Possible to use getresponsetext and assertion without jsonslurper jsonoutput ?
i noticed jsonslurper and jsonparse tend to give me response in different structure.
i would like to use getresponsetext to get raw response.
the raw response is in array format. assertThat(test1List.data[0].testId).isEqualTo(“FF1”)
which i use the format assertThat(test1List.data[0].testId).isEqualTo(“FF1”)
however the assertion keep complaining the data[0] cannot be used.
No such property: data for class: java.lang.String
test scripts:
import static org.assertj.core.api.Assertions.*
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import internal.GlobalVariable
def SiteHostName = GlobalVariable.SiteHostName
def Port = GlobalVariable.Port
No is not. Is an object. Inside that object you have the key data, which is indeed an array.
you cannot use such assert on a string (getResponseText() is returning a string representation of your JSON response).
To reach a given element of the response, you have to parse it into a collection, therefore you need jsonslurper (or any other string to map/array library). If jsonslurper is not at your taste you can try google’s gson library.
Other option is to use the verifyElementPropertyValue keyword straight on the response object (without using getResponseText)
i removed json slurper and json output. cleanup the code.
just purely uses below and no error now.
but i am not sure if the json response structure is always consistent or not.
the jsonslurper always give me different structure and assertion failed earlier.
thanks @bionel I will monitor and report if again the structure changed.