Can I use a variable in web URL string

Hi
Can anyone assist in how I go about creating a variable for a web URL:

I would like my Url to identify a variable in the URL I will use the following URL as an example:

Current - Categories - Katalon Community
Variable option - http://forum.katalon.com/${id} so the variable should be id so that I can use data to drive which page should open

Is this possible and how?

Thanks

  1. Choose (or create a new) profile: Tests Explorer > Profiles

  2. Create a variable: myVariable

  3. Give the variable a value: myvalue

  4. Use the variable in a Test Case:

WebUI.navigateToUrl('http://demoaut.katalon.com/' + GlobalVariable.myVariable)
2 Likes

Thank you, you are a legend…
It works great perfect :+1:t2:

1 Like

Hi

I’m getting the basics working but not the complex query

So in the example below I need the GlobalVariable to be in the middle of the URL
can this be done?

WebUI.navigateToUrl('http://demoaut.katalon.com/#/ + GlobalVariable.myVariable/register/new)

Thanks
J

In essence, you’re asking how to concatenate strings in Groovy script.

String myString = "mainj" + myVariable + "russ" + otherVariable + "Katalon"

Yes and No:
So the Idea as per my original post was to use a GlobalVariable in my Web URL
Which when I use. Example
WebUI.navigateToUrl(‘http://demoaut.katalon.com/+ GlobalVariable.myVariable)
it works happy

However I want to push this further so that when I navigate to the URL the variable is in the middle of the URL
Example:
WebUI.navigateToUrl('http://work.coms/login/user/ 988asd09-09asda2i9as/lead.id)

The key 988asd09-09asda2i9as must come from a variable as this can change with new sessions

I have tried using concatenate but have failed :disappointed:

J

WebUI.navigateToUrl("http://work.coms/login/user/" + GlobalVariable.myVariable + "/lead.id")
1 Like

Thank You
I Realized my mistake.

You can use also string interpolation if concatenation is confusing:

WebUI.navigateToUrl("http://work.coms/login/user/${GlobalVariable.myVariable}/lead.id")

see: https://groovy-lang.org/syntax.html#_string_interpolation