How to get an element property value from an API response?

Hi,

How to get an element property value from an API response?
There is keyword ‘verifyElementPropertyValue’ which verifies an element property value with an expected value. But I want to get an element property value from an API response, save it in a variable and later compare this with a UI value.

Please let me know is there any keyword available to get an element property value.

Thanks,
Ravi B

1 Like

Hi ravi.b23,

Please review this post for your needs. You can get the response data and assign to the global variable.

Example script:

response = WS.sendRequest(findTestObject(‘Employees/Login backoffice and get access token’))
WS.verifyResponseStatusCode(response, 200)
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(response.getResponseText())
String access_token = parsedJson.access_token
GlobalVariable.Token = access_token

1 Like

Hi sang,

Thanks for your solution.
I want to get ‘amount’ value from balance node.
I tried below 2 methods but it is showing error.

String amtValue = parsedJson.get(“balance”.“amount”)
String amtValue = parsedJson.balance.amount
In balance node, there are many sub nodes like amount, type etc…

Please help me on how to get these kind of values.

Thanks,
Ravi B

Hi sang,

Though it is showing as error, I got the value by using below statement.

String amtValue = parsedJson.get(“balance”).get(“amount”)

Thanks,
Ravi B

1 Like

Hi @ravi.b23,
We will support more keywords for getting info from API response in version 7.2.0.
Regards.

1 Like

Are there any more functions to make it easier to extract fields from json responses yet?

1 Like