mainj
July 17, 2020, 11:45am
1
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
Choose (or create a new) profile: Tests Explorer > Profiles
Create a variable: myVariable
Give the variable a value: myvalue
Use the variable in a Test Case:
WebUI.navigateToUrl('http://demoaut.katalon.com/' + GlobalVariable.myVariable)
2 Likes
mainj
July 17, 2020, 2:53pm
3
Thank you, you are a legend…
It works great perfect
1 Like
mainj
July 20, 2020, 6:21pm
4
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"
mainj
July 20, 2020, 8:06pm
6
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
J
WebUI.navigateToUrl("http://work.coms/login/user/" + GlobalVariable.myVariable + "/lead.id")
1 Like
mainj
July 22, 2020, 10:10am
8
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