Global Variables – How to define your test environment
Before we get too deep into creating scripts I wanted to point out the use of Global Variables since several of the screenshots already reference something called GlobalVariable.baseurl + "/tasks" or something similar.
I saw this referenced in several Katalon examples, but the reason for doing it wasn’t clear. If you recall from the Selenium IDE, there was a field where you could enter the base URL of the site. This meant you could run the same tests in QA and Production with just a change to the URL. This accomplishes the same functionality in Katalon Studio. The base URL is set for QA 99% of the time and when you want to run tests in Production, simply change the value of the Global Variable and all tests that reference that variable will use the new site address.
In this example, I’m creating a variable called "baseurl". This contains the URL of my site in the QA environment.
Click the blue X on the right sidebar of Katalon to bring up the window to define a Global Variable.
Within my tests, I refer to the baseurl, then add additional text to make a complete URL. These are examples of the navigateToUrl command using the variable.
WebUI.navigateToUrl(GlobalVariable.baseurl + "/v3/sales_dashboard")
WebUI.navigateToUrl(GlobalVariable.baseurl + "/tasks)
WebUI.navigateToUrl(GlobalVariable.baseurl + "/prospects")
The use of Global Variables must be defined within your project, so make sure your test script has the following line within the import statements at the top:
import internal.GlobalVariable as GlobalVariable
This is a pretty important piece of functionality that wasn’t obvious to me. It’s great to make tests, but how do you use them in different environments? Now the idea makes sense to me.
Other articles of interest:
- Setting up Environment Profiles in Katalon Studio
- Securely storing passwords and login details with Set Encrypted Text in Katalon Studio
- Creating a Data Driven Test Suite in Katalon Studio
- Entering and reading text GetText, SetText and SendKeys in Katalon Studio
- New Libraries to Import into Katalon Studio
- Output status messages and test information by writing to the Log File Viewer in Katalon Studio
- More Katalon Studio and Automation to come
- Katalon Studio – Manual View – The start of a test script
- Getting started with Katalon Studio
- Changing the scope of a variable to be available within a Method