Insert POST twice and verify second response error status and body

the second part of test case failed at verification to verify if status code 400 and body returned correctly, how do I correct them?

test case
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

//send POST message to insert Product

result = CustomKeywords.‘testlog.AddPro’()


//insert same Product ID should not be allowed
def response = WS.sendRequest(findTestObject(‘AddPro’))

WS.verifyResponseStatusCode(response, 400)

WS.verifyElementText(response, “duplicate ID”)

print response
return response

console log
2019-07-29 17:16:48.754 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/AddPro FAILED.
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementText() is applicable for argument types: (com.kms.katalon.core.testobject.ResponseObject, java.lang.String) values: [400 273 bytes, duplicate ID]
Possible solutions: verifyElementText(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.String), verifyElementText(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.String, com.kms.katalon.core.model.FailureHandling)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)

You miss a parameter

See also

what should be the locator? i did not put it as i only get response body “duplicate ID” when i inspect the API log.

See examples from the doc

did not get any good ideas from the brief intro/people’s comments.

Katalon Studio give you the locator when you mouse over the response. Here “5”.

in my case the body isn’t in json/xml format.
it is returned from codes.
Content-Type: text/plain; charset=utf-8

Share an example

which example?
it is just plain text response
duplicate ID

So try with Response body: Contains string
assertThat(response.getResponseText()).contains('duplicate ID')

you mean in test case? i tried earlier, got error. don’t think assert is good to use inside test case. if this to be added in object repo when sending the POST message, then i need advise how ot make it passed only on second POST, not first POST, as first POST is not response the duplicate ID, only second POST.

groovy.lang.MissingMethodException: No signature of method: Script1564388610308.assertThat() is applicable for argument types: (java.lang.String) values: [duplicate ID]

“assertThat” works inside a TestCase, example :

import static org.assertj.core.api.Assertions.*

String a = "123"

You can try println response.getResponseText().contains('duplicate ID') to see if you have the good value (true/false) then you can create a function to use this result

1 Like

ok the root cause was import not there , it is running without error now. is that katalon defect? i was trying to do shift ctrl + o but import not auto added.
import static org.assertj.core.api.Assertions.*

Because it’s static. We should write Assertions.assertThat('something') then press Ctrl + Shift + O to add imports