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.

image

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")

When the script is run, the baseurl is set to https://website-qa.com and the /tasks is added to the end to make https://website-qa.com/tasks

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:

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments