Web服务请求中的While语句

时间:2019-01-09 07:13:51

标签: web-services automated-tests katalon-studio web-api-testing

我是katalon工作室的新手。我想在PUT请求中发表while声明。我一切都做得很好,但是我想知道是否有可能只获得statementIds,如果每个statementId不同,则将它们计算在内。这是我的脚本。

我只提出了5个请求,并且可以手动检查statementId是否不同,但是当我提出100个或更多请求时,将很难手动检查它。我认为,我需要捕获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++
}

输出为:状态代码: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”

PS我试图捕获statementId,所以:String statement_id = request_object.statementId,也使得:String statement_id = request_object.getName("statementId")意识到,在request_object中仅存储了请求,而没有其他存储,但是响应没有这样的东西只有一个物体。

1 个答案:

答案 0 :(得分:1)

您需要将JsonSlurperbodyContent一起使用:

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

,然后尝试获取statement_id

String statement_id = parsedJson.statement_id