Using variables in Test Objects' Xpath

Hi, I have tried solutions provided in similar posts, but i can’t seem to get this working. Please help with the following:

  • Inside a test script, I have created a variable called ‘Employee’, which is of the type ‘String’ and holds a ‘Default value’
  • I use this variable to Send Keys, which works great
  • I now want to use the same variable within a XPath, to be able to click on the item.

The last part is tricky it seems:

In a Test Object I use ‘Selection Method’ ‘XPath’ with the following value:

//*[contains(text(),‘John’)]

This works, however, when trying to insert the variable here, I can’t get it working. Have tried the following:

//*[contains(text(), ‘${Employee}’)]
//*[contains(text(), ${Employee})]
//*[contains(text())=’${Employee}’]

What am I doing wrong? I know how to tackle this through scripting using Java, but I want to be able to do this through the basic interface of Katalon, so users with less experience can handle this as well.

Try this:

Also, see this under scripting View

@eyildiz

possibly you need lines as follows:

def Employee = 'Goo'
TestObject to = findTestObject('your test object name', ['Employee', Employee])
WebUI.sendKeys(to, "Hello")

Please find a fragment ['Employee', Employee].

For detail, hava a look at the doc on parameterizing Test Object:

Hi guys thanks for the response. I still need to check your suggestions, but just to make things clear (as i have the impression scripting is involved): have you read the last part of my question?

I know how to tackle this through scripting using Java, but I want to be able to do this through the basic interface of Katalon, so users with less experience can handle this as well.

By basic i mean the GUI, manual steps view / test objects, without touching scripting.

Of course. The idea would be to get it working in script, then design a custom keyword which would enable your users to use Manual View.

@kazurayam’s answer is the most “native” way to do this in Katalon. Maybe it just looks like it more when it’s all wrapped in a WebUI call?:

WebUI.sendKeys(findTestObject('your test object name', ['Employee': Employee]), 'Hello')

The first xpath in that list is the correct way to parameterize it. I would test this xpath in your browser inspector first, before placing it in the Test Object.

“parameterized Test Object” in Katalon Studio is designed not very friendly to less experienced people. It requires some programming skill to understand and use. Please embrace this fact.

1 Like

@kazurayam, @Brandon_Hein, @Russ_Thomas thanks for the informaiton. At least now it’s clear that you won’t get away with just using the basic GUI. I will take this into considiration.

That’s a blinkered view, if you don’t mind me saying. Think of it this way:

  1. Manual View. Use Lego Bricks to build a test.

  2. Script View. Design your own, unique bricks that work alongside the pre-designed Lego Bricks. Build tests using both.

We have an alternative approach.

If you create a GlobalVariable.Employee then you can use it as followis in a TestObject’s XPath (and CSS selector):

//*[contains(text(), '${GlobalVariable.Employee}')]

See also:

@Russ_Thomas Perhaps, but considering the context we are going to use it, I want to utilize the existing Lego blocks as much as possible. If too much scripting is involved for simple tasks, such as parametrization, it might become a challenge for the end-users.

Having said that, don’t get me wrong. I see the power this tool offers and that’s the whole purpose for us to give it a go. Personally, I wouldn’t want to leave the scripting view 

@kazurayam thanks for that alternative approach. I have been able to get it work as well, using the TO level variables.

2 Likes

Hi @eyildiz

Have you checked this documentation ?

Unless the doc is not up-to-date, I think there’s a way to get it done through the manual view.

Yeah thanks, have seen this document as well, and problem was already solved. Forgot to flag this post as such. Thanks for your help