Using global variable for value in test object

I want to use global variable for value in test object. I tried using like ${global_var} but didn’t help.

try ${GlobalVariables.yourVariable}

Hi, I would like to ask you a question related to this topic. I must say that I´m a beginner in programming and it´s not easy for me to learn it all by myself. Sorry for that in advance.
I am creating a Test Case in Katalon Studio which is simple: the automate loggs in the web with the credentials, enters the search and types the order number (IDEnvio) which is a variable and there are many orders to loop through. I need to click on the order that is a result of the serach and make some modifications in it and the problem that I have is that the Katalon doesn´t find the Test Object on the web page.
The Test Object´s name is “td_12534” where 12534 is the order number. Each order can be identified in the same way so I used the an Excel file in Test Data of the Test Suite to identify each order but I cannot find a way to connect the Test Object´s name or identificator with the Variables that I have defined within the Test Case and Test Data. I defined the Test Objet´s Input parameter as variable and assigned the variable but it doesn´t seem to work.
Script view:'Page_Envios/td_12534', [('') : IDEnvio]))

Test Object´s locator: //tr[@id='rowId_12534']/td
Is there any way to use the data from the Excel file to identify the Test Objects?
I will be grateful for any feedback!


(1) You should rename your Test Object:
Page_Envios/td_12534 --> Page_Envios/order
or something like this. Renaming is necessary because you want to use it for processing multiple order numbers, not only the order number ‘12534’.

(2) You want to parameterize the Test Object. Edit the locator slightly. You want to introduce a place holder:
//tr[@id='rowId_12534'] --> //tr[@id='rowId_${ORDER_NUMBER}']

(3) You want to change the test case script slightly so that it gives the placeholder ORDER_NUMBER with actual values you want.

def orderNumber = '12534'
// or
// def orderNumber = you can set value retrieved from Excel

TestObject tObj = findTestObject('Page_Envios/order', ['ORDER_NUMBER': orderNumber])
println tObj.getActiveProperties()[0].getValue()   // you can see how the actual locator looks like

// make sure the element is clickable
WebUI.verifyElementPresent(tObj, 10, FailureHandling.STOP_ON_FAILURE)
WebUI.waitForElementVisible(tObj, 10)

// finally you can click it

See for more info.

1 Like

@kazurayam Thank you so much! This is exactly what I was looking for and is working! Thank you again for explaining it perfectly so that even a noob like me can understand it :slight_smile: