The status is 200. It just doesn’t seem to capture the details of the Response text using the PUT method. It works for POST method which I used for another functionality of creating a JIRA test case:
// Create a new test case with provided information - this needs to be done once
def create_issue = WS.sendRequest(findTestObject('JIRA/Create Issue Type', [('projectKey') : GlobalVariable.JIRA_Project_Key
, ('summary') : currentTestCaseName, ('description') : 'Creating of an issue using project keys and issue type names using the REST API'
, ('issueType') : 'Test', ('priority') : 'Major', ('authorization') : GlobalVariable.JIRA_Authorisation, ('url') : GlobalVariable.JIRA_URL]))
**def json_create_issue = jsonSlurper.parseText(create_issue.getResponseText())**
@Brian_Ducson Ok I got another problem (which still applies to the original topic I asked earlier) as it is always showing null when I am trying to capture a value from the response body.
So, the response body generated is as follows:
{
“39”: {
“id”: 39,
“name”: Test
}
}
However, when I am trying to display the “id” value using the jsonSlurper, it returns null.
Note that “39” is dynamic and not fixed so it keeps changing everytime. As I need to pass this value to test case, then I can’t just hardcode it to “39” so I need to capture the value of “id” or I workaround by using substring to grabe the values before “: {”
I am fairly new to automation of API so bare with me if the terms I use are not correct.
Hi Vinh, I use this most of the time but since the parent node is dynamic, I cannot pass this as a variable.
the jSonPath will keep changing (e.g. 30.id then when I run the script again, the response will change to 31.id, 32.id, and so on and so forth).
Hi @Brian_Ducson , would you know how to skip two levels of dynamic values?
I need to retrieve the 3rd level value by ignoring the parent level (which is always dynamic) and the 2nd level which is unfortunately, also dynamic. Response body below:
{
“1”:[
{
“8”:{
“totalExecutions”:0,
}
From above, I need to skip “1” and “8” (both will dynamically change) before retrieving the value “0” of totalExecutions. I tried following the nested loop statement from here (putting another loop statement within the loop: http://forum.katalon.com/t/how-to-get-json-value-skip-first-level/10857/6
but I get the error below: com.kms.katalon.core.exception.StepErrorException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘1=[{8={totalExecutions=0}]’ with class ‘java.util.TreeMap$Entry’ to class ‘java.util.Map’
I was just checking the 2nd level at this stage, but getting the error already as it seems not able to identify the Map variable:
def search_test_cycle = WS.sendRequest(findTestObject(‘JIRA/ZAPI-Get List of Cycle’, [(‘authorization’) : GlobalVariable.JIRA_Authorisation, (‘projectId’) : GlobalVariable.JIRA_Project_ID
, (‘url’) : GlobalVariable.JIRA_URL, (‘versionId’) : ‘’, (‘cycleId’) : ‘’, (‘issueId’) : ‘’])) → the response body for this is the above {“1”:[{“8”:{“totalExecutions”:0}
def json_search_test_cycle = jsonSlurper.parseText(search_test_cycle.getResponseText())
KeywordUtil.logInfo(json_search_test_cycle.toString())
def d = json_search_test_cycle.keySet()[0]
for (Map map : json_search_test_cycle){
Set keySet = map.keySet()
Iterator iter = keySet.iterator()
while (iter.hasNext()) {
def key = iter.next()
def v = map.get(key)
KeywordUtil.logInfo(v.toString())
}
}