I am trying to verify response status codes if every response status is 200. I have to verify it with big data and for that I’ve made a loop. Here is the code.
SQLHandler_TEST sql = new SQLHandler_TEST()
List<GroovyRowResult> res = sql.getSelectResults('SELECT TOP 2 TEST FROM card.PCARDS WHERE STATUS=30')
String cc = "SS"
for(Map oneRow in res) {
String test_id = oneRow.get("TEST_ID")
KeywordUtil.logInfo("TEST ID : " + TEST_id)
KeywordUtil.logInfo("CC : " + cc)
// use variables in the GET request here
RequestObject get_object = findTestObject('=GET_AvailableBalance')
String url = "http://testapi.comv1/cards/%s/AvailableBalance?cc=%s"
get_object.setRestUrl(String.format(url, test_id, ccy))
ResponseObject get_response = WS.sendRequestAndVerify(get_object)
int statusCode = get_response.getStatusCode()
KeywordUtil.logInfo("Status: " + statusCode + " URL: " + get_object.getRestUrl())
String getContent = get_response.getResponseBodyContent()
KeywordUtil.logInfo("Response Body Content: " + getContent)
WS.verifyResponseStatusCode(get_response, 200)
}
return res
Here with WS.verifyResponseStatusCode(get_response, 200), I am trying to verify if the first response was successfull, but if it is not, it throws an exception and stops the test. I want to make so that it would not stop the test and continue with the failure, but in the end test case should not passed, it should be failed. Because of that I don’t want to use FailureHandling, is there any another way ?
Possible solution:
Set a ‘flag’ boolean variable with an initial value of ‘true’
Encapsulate the verification in a try {} catch {}, if any error is thrown the catch should set the flag to false (and log some info’s).
Once the loop is ended make a final assert on the flag variable
Other possible solution:
Use the SQL statement as a data provider for a test suite.
Bind it to the test case.
With this approach, you no longer need to make the loop, the test case will execute for each row returned by the query.
Yes, but will it be possible with API request ? how can i perform such an acction.
Also try catch didn’t work for some reason.
EDIT: Well, that data binding was very cool, also it resolved my problem now it makes 1 test case for 1 row and now if one fails it will make another row too. THANKS !
LE: i think the try {} catch {} didn’t worked because the WS.verifyResponseStatusCode keyword is not throwing an exception, but just return a boolean value … not sure here, but if this is the case, an if / else can be used … i am getting old, have to find time to play more with katalon