Just to give a context on what I want to achieve: I want to check if an existing “Test Cycle” exists in JIRA (Zephyr). If yes, then the test case should be executed under that Cycle ID. Else, a new Cycle will be created. I want to capture the Cycle ID if the Cycle name matches the one in Katalon
Example: response is “3”:{“name”=“ST Cycle 1”…) - from here, if “ST Cycle 1” exists in JIRA (Zephyr) then I want to capture the value “3”.
I parsed a json response using JsonSlurper (This code is under Keyword passed to Test Listener in Katalon so I can capture the testSuiteContext.getTestSuiteId():
//Capture the response from JIRA (Zephyr)
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') : '']))
//Parse the response into text
def json_search_test_cycle = jsonSlurper.parseText(search_test_cycle.getResponseText())
KeywordUtil.logInfo(json_search_test_cycle.toString())
The response (sorry it is long) is:
{-1=[{-1={build=, createdDate=, description=, endDate=, ended=, environment=, executionSummaries={executionSummary=}, expand=executionSummaries, isExecutionWorkflowEnabledForProject=true, isTimeTrackingEnabled=true, modifiedBy=, name=Ad hoc, projectId=14900, projectKey=TUT, startDate=, started=, totalCycleExecutions=0, totalExecuted=0, totalExecutions=0, versionId=-1, versionName=Unscheduled}, 13={build=, createdBy=sysadmin, createdByDisplay=System Administrator, createdDate=2019-01-30 17:41:12.403, description=Create cycle from Katalon, endDate=, ended=, environment=, executionSummaries={executionSummary=}, expand=executionSummaries, isExecutionWorkflowEnabledForProject=true, isTimeTrackingEnabled=true, modifiedBy=sysadmin, name=ST Cycle 1, projectId=14900, projectKey=TUT, sprintId=1, startDate=, started=, totalCycleExecutions=1, totalDefects=0, totalExecuted=0, totalExecutions=0, totalFolders=0, versionId=-1, versionName=Unscheduled}, recordsCount=2}]}
From the above response:
1st level: “-1” - although a negative number, this is always fixed
2nd level (dynamic): “-1” and “13” (id’s) with values of “name” as “Ad hoc” and “ST Cycle 1”, respectively
I want to capture “13” in this case.
Next set of codes as per @kazurayam 's response in another thread:
def expectedLabel = “ST Cycle 1”
def wantedValue = 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)
if (v.get(‘name’) == expectedLabel) {
wantedValue = v.get(key)
WebUI.comment(“wantedValue=${wantedValue} when key=${key}”)
}
}
}
The problem I have is that the 2nd level is the key itself. I am unsure how to capture this.