How to get value from query parameter?

Hi Everyone,

I have question about query parameter, capture below

I’ve set query parameter and resource data in tab variables, I want to create test case from this service. my question is, How to I get value from parameter and how to call in test case level?

Thanks

1 Like

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

HI, I’m not sure about what exactly your response looks like, if it is a Json object, below you have 2 examples in which are described how to send an API request in a test case and get a field value from Json.If your response is not a Json I hope these examples will provide you some guidance.

Example 1
// Send request and verify API code response
	'Send a request and returns its response'
	def response = WS.sendRequest(findTestObject('IBM Cloud API/3.POST - Get Access Token (Client_credentials)'))
	
	'Verify if the response from "REST_Status Codes/POST_200" object returns the 200 status code'
	def status = WS.verifyResponseStatusCode(response, 200) // returns a boolean
	println("----------- Code status is 200:" + status)

// Extract field value from response (response is Json object)
	'Create a new instance of JsonSlurper and call the JsonSlurper.parseText method'
	JsonSlurper slurper = new JsonSlurper()
	Map parsedJson = slurper.parseText(response.getResponseText())
	
	'Getting Json values'
	String access_token = parsedJson.access_token
-------------------------------------------------------------------------
Example 2
	'Send a request and returns its response'
	def response2 = WS.sendRequest(findTestObject('IBM Cloud API/4. POST - GyS API - Validate classification'))
	JsonSlurper slurper2 = new JsonSlurper()
	Map parsedJson2 = slurper2.parseText(response2.getResponseText())
	String conceptId = parsedJson2.goodsAndServices[0].terms[0].conceptId
	println(" ----------- JSON value conceptId:"+ conceptId)

1 Like

Hi @isaac.palmasolis.ex1 ,

Sorry for late response.
thanks for your answer, but in your case I can get in test case from getResponBodyContent.

in my case, I want to export value from request object or query parameter and then throw in test case. Is it possible?

For now, Im extract value like this and don’t know how extract value in test case


Regards

If I get you correctly you just need to retrieve baseURL,email and password in your test case, if so you’ve already stored those values:

  • baseURL (Global variable) get value:
    println(GlobalVariable.baseURL)
  • email:
    getEmail = findTestData(“Auth/Login”).getValue(2, 1)
    println(getEmail)
  • password:
    getPassword = findTestData(“Auth/Login”).getValue(3, 1)
    println(getEmail)

Hi!
Your email and password variables come from a data file, right? On the variables tab it is shown that the type is Test Data Value.

When you write the Verification for the query, you write

def variables = request.getVariables()

This will get you the variables, that are specified on the Variables tab. So this only gets you the email and password, that you told the test to use, from the DataTest named file. And does not get the email and password from the response!

If you wanted to get this in the Test Case also from the DataTest, than it is already done when you send the request here:

But if you want it from the response that is being sent to you, than we have to know if email and password values are included in the response, and if yes, how exactly are they called and how the response looks like. Because the structure of the JSON is important.

For example:

{
    "user": [
    {
        "email": "something@something.com",
        "password": "password123"
    }
  ]
}

If you want to get the email, you have to write:
WS.getElementPropertyValue(response, "user[0].email") → this will give you a String

WS.getElementPropertyValue(response, "user.email") → this gives you a List

When you send the request in Katalon, and get the response back, you can check the structure under Body, if you hover over the value, Katalon will write the path in the lower left corner: