How to create a variable with the value from another variable?

I want to create some related variables like below:
base_url = “https://google.com
image_url = base_url+"/images
video_url = base_url+“videos”

Because the URLs can be changed in our projects.
How I can create those variables?

I tried Global variables in Profile but it only allows the fixed values.

Thanks in advance!

1 Like

Given a GlobalVariable defined in a profile thus:

base_url = "https://example.com"

You can do all or any of these:

// log the current value of base_url
println GlobalVariable.base_url

String images = GlobalVariable.base_url + "/images"
println images

// modify this instance of base_url
GlobalVariable.base_url = GlobalVariable.base_url + "/new_path"
println GlobalVariable.base_url

// use the new base_url
String videos = GlobalVariable.base_url + "/videos"
println videos

@Russ_Thomas
So, is there any way to create variables like that in the Profile?
I just want to create all variables in one place.

Many thanks for your answer.

For anyone visits this topic.

You need to add the above script to the “Script” section. If you want to use it, choose the Value Type is “Variable” then just enter the variable name (if you click on the drop down, it doesn’t show :frowning: )

Yes, like I showed you - just create whatever variables you want. Katalon will use the values in the variables from the profile. You can change them in any test, but they revert to the original value at the start of each test.

You can. And you can modify them in a test, like I showed you.

Yes, like I showed you - just create whatever variables you want. Katalon will use the values in the variables from the profile. You can change them in any test, but they revert to the original value at the start of each test.

I just see manual and XML Script mode in Profile.
Can I create variables in java like in your example?

Yes.

Those become GlobalVariables in your test case – a special construct predefined by Katalon. If you want to use regular variables, that’s easy too, but they won’t have values until you set them in code.

I think you’re “over-thinking” this… it’s really quite simple stuff.