1

I'm new in katalon studio. I’m tying to make while statement in PUT Request. I made everything well, but I want to know if it is possible to somehow get only statementIds, count them if every statementId is different. This is my script.

I made for only 5 requests and manually i can check that statementId are different, but when I will make for 100 or more it will be hard to manually check it. I think, that I need to catch statementId.

WS.sendRequest(findTestObject('Object Repository/PUT_Count'))
RequestObject request_object = findTestObject('PUT_Count')
String startDate = "2018-02-02"
String endDate = "2019-01-01"
boolean inEquivalent = false

while(GlobalVariable.accountId < 5) {
    request_object.setRestUrl(String.format(request_object.getRestUrl(), GlobalVariable.accountId, startDate, inEquivalent))

    ResponseObject response = WS.sendRequestAndVerify(request_object)

    WS.verifyResponseStatusCode(response, 200)

    int statusCode = response.getStatusCode()

    String bodyContent = response.getResponseBodyContent()

    System.out.println((('Status Code: ' + statusCode) + ':') + bodyContent)

    GlobalVariable.accountId++
}

Output is : Status Code: 200:{“statementId”:“11dbfd2f-3d30-493c-b41a-c40a83e41269”,“accountId”:123,“accountIban”:“12345”,“ccy”:“One”,“startDate”:“2018-12-10”,“endDate”:“2019-01-09”,“startBalance”:100.0,“endBalance”:1000.0,“startPointer”:“0094230492304923090Anffjle39440583490434rieklfrlfkjedtu8er9t7548684568t9fkgmndflkgr5908yt546”}

P.S I've tried to catch statementId so : String statement_id = request_object.statementId, also made that: String statement_id = request_object.getName("statementId") , realized that in request_object is stored only request and nothing else, but response does not have such thing to get only one object.

1 Answer 1

1

You need to use JsonSlurper with the bodyContent:

import groovy.json.JsonSlurper
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(bodyContent)

and then try getting the statement_id:

String statement_id = parsedJson.statement_id
7
  • everything works now, but for comparison I need to store the old statementId and compare to the new one, if they are different. I've tried some things with jsonslurper but now what I did, every statementId is now the same :D
    – brithwulf
    Jan 9, 2019 at 7:37
  • Add this line: def statement_ids = [] before the while loop and statement_ids << statement_id after the line where you get the statement_id. And now you have a list of statement ids that you can compare.
    – Mate Mrše
    Jan 9, 2019 at 7:41
  • You can then compare for example statement_ids[0] and statement_ids[1]
    – Mate Mrše
    Jan 9, 2019 at 7:43
  • I should compare it in loop, yes ?
    – brithwulf
    Jan 9, 2019 at 7:47
  • Well, it depends on what do you want to do. If you want to verify every id is different, you can add this line to the end of the loop (before incrementing accountId): WebUI.verifyNotEqual(statement_ids[GlobalVariable.accountId], statement_id)
    – Mate Mrše
    Jan 9, 2019 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.