How to pass global variable in rest request

Sample rest request-
{
“objectType”:“business”,
“code”:${#GlobalVariable.code},
“name”:“Allocation Group2 Business Group”,
“shortName”:“BG3”,
“businessTypeId”:“1”,
“parentBusinessId”:1,
“startDate”:“2017-06-15”,
“endDate”:“2018-06-22”,
“changeEffectiveDate”:“2017-07-29”
}

I have tried all options-
set code in Parameters- like Name is code and value is AG2.
I want to pass runtime value in the code.

How will i do it?

Sample rest request-
{
“objectType”:“business”,
“code”:${#GlobalVariable.code},
“name”:“Allocation Group2 Business Group”,
“shortName”:“BG3”,
“businessTypeId”:“1”,
“parentBusinessId”:1,
“startDate”:“2017-06-15”,
“endDate”:“2018-06-22”,
“changeEffectiveDate”:“2017-07-29”
}

I have tried all options-
set code in Parameters- like Name is code and value is AG2.
I want to pass runtime value in the code.

How will i do it?

Hi there,

In order to pass Global Variable in rest request, you need to use ‘setRestParameters’ method and pass in TestObjectProperty list which can be retrieved using the sample code below:

RequestObject request = findTestObject(‘your/sample/request’)
List parameters = new ArrayList<>()
parameters.add(new TestObjectProperty(‘code’, ConditionType.EQUALS, GlobalVariable.code))
list.add(parameters)
request.setRestParameters(list)

Please refer to our API docs for more details: http://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/RequestObject.html

Thanks

Hi there,

In order to pass Global Variable in rest request, you need to use ‘setRestParameters’ method and pass in TestObjectProperty list which can be retrieved using the sample code below:

RequestObject request = findTestObject(‘your/sample/request’)
List parameters = new ArrayList<>()
parameters.add(new TestObjectProperty(‘code’, ConditionType.EQUALS, GlobalVariable.code))
list.add(parameters)
request.setRestParameters(list)

Please refer to our API docs for more details: http://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/RequestObject.html

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Thanks for the support.

Hi,

Below is the code,

import com.kms.katalon.core.testcase.TestCaseas TestCase

import com.kms.katalon.core.testcase.TestCaseFactoryas TestCaseFactory

import com.kms.katalon.core.testdata.TestDataas TestData

import com.kms.katalon.core.testdata.TestDataFactoryas TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepositoryas ObjectRepository

import com.kms.katalon.core.testobject.TestObject
as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
as WS

import
com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
as WebUiBuiltInKeywords

import
com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
as WebUI

import
internal.GlobalVariable as
GlobalVariable

impor**t
**com.kms.katalon.core.testobject.TestObjectProperty

import
org.openqa.selenium.Keys
as Keys

import
com.kms.katalon.core.testobject.ConditionType

import
com.kms.katalon.core.testobject.list

import
com.kms.katalon.core.testobject.RequestObject
as
RequestObject

//def response1 = WS.sendRequest(findTestObject(‘Get Business type based on ID’))

//def response2 = WS.sendRequest(findTestObject(‘Create Business Entity’))

//responseText = response1.getResponseText()

//System.out.println(‘O_Body:’+responseText)

//assert response1.getResponseText().contains(“TOC”)

//WSBuiltInKeywords.verifyElementPropertyValue(response1, ‘code’, ‘TOC’)

RequestObject
request =
findTestObject(‘Create Business Entity’)

List
parameters =new ArrayList<>()

parameters.add(new
TestObjectProperty(‘code’, ConditionType.EQUALS,
GlobalVariable.code))

list.add(parameters)

request.setRestParameters(list)

I am getting error as-

07-10-2017 10:54:01 AM - [START] - Start Test Case : Test Cases/Rest Test Case

07-10-2017 10:54:01 AM - [INFO] - Evaluating variables for test case

07-10-2017 10:54:01 AM - [ERROR] - Test Cases/Rest Test Case FAILED because (of)
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

file:/C:/Users/kaverik/Katalon%20Studio/DCAS%20Rest/DCAS%20Rest/Scripts/Rest%20Test%20Case/Script1498801544692.groovy: 24: unable to resolve
class com.kms.katalon.core.testobject.list

@ line 24, column 1.

import com.kms.katalon.core.testobject.list

^

1 error

07-10-2017 10:54:01 AM - [END] - End Test Case : Test Cases/Rest Test Case

Can you please help me in this.

Thanks,

Kaveri

Please remove this import: import com.kms.katalon.core.testobject.list as this is a invalid package.

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Hi,

If i removed below line, the getting-

Test Cases/Rest Test Case FAILED because (of) Variable ‘list’ is not defined for test case.

Test Cases/Rest Test Case.run:38

Thanks,

Kaveri

Hi there,

I will follow up with you on this ticket instead: https://katalonhelp.zendesk.com/agent/tickets/1210.

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO