URL Variables & Testing Production vs. Staging

I’m developing a project centered around testing our production environment “software as a service” web application. I’d like to take as much of my existing scripting and be able to test our staging environment as well, which exists in a different URL of course. What I want to know is if there is a way to define variables or something along those lines that will have test cases choose to be executed in our production URL or staging URL. Would it be easier to create a new project, copy and paste my existing scripts, and simply change the initial navigateToUrl commands? Obviously not every single script element may execute exactly the same way between the two environments but I would test my tests and make any necessary changes to objects, etc.

Use different profiles, one for each environment.

In the production profile, set TARGET_URL to the url for production.

In the staging profile, set TARGET_URL to the url for staging.



If you use Profiles like @Russ_Thomas suggests, you have to remember to choose the correct environment after you launch KS and before starting your testing. Remember the computer does not change the environment profile setting by itself; the profile stays throughout your testing but you have to reset it when you start or restart KS.


@grylion54 @Russ_Thomas
This is a solid solution, thank you both. Forgive me for my ignorance as I want to learn everything I can, but if I edit navigateToUrl commands in one profile, will that inadvertently affect the other profile’s scripts?

In other words, will I need to go through and edit scripts each time?

No, that was the point. You set the actual URL value in a profile. You don’t touch the script. When you execute the suite (or test case) you decide which profile is selected first.

@Russ_Thomas Thank you very kindly. I see the wisdom here. On a more personal note, do you find pretty smooth translation in your staging tests vs. production tests? I suppose I foresee some minor issues where something is a bit different in a staging environment.

I (we) don’t test like that.

I run suites continuously against two development systems (one for SQL Server back end and the other for Oracle). When a dev branch is about to be finalized, it is given a “tag” and tested for approximately one week before the branch is closed (and the software released). Then I revert back to testing the dev branch again.

@Russ_Thomas Thanks for your help again.
Things were going smoothly but I’ve noticed now that I’m receiving
Caused by: java.lang.IllegalArgumentException: Url cannot be null or empty
when calling navigateToUrl and passing the global variable to the command. This is in both profiles.

Show me the code, the Profile definition and the error.

`=============== ROOT CAUSE =====================
Caused by: java.lang.IllegalArgumentException: Url cannot be null or empty


09-17-2021 01:37:19 PM Test Cases/Alerts Tests/9000 - Alerts - Alerts Log

Elapsed time: 2.729s

Test Cases/Alerts Tests/9000 - Alerts - Alerts Log FAILED.
com.kms.katalon.core.exception.StepFailedException: Unable to navigate to ‘null’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.NavigateToUrlKeyword.navigateToUrl(NavigateToUrlKeyword.groovy:83)
at com.kms.katalon.core.webui.keyword.builtin.NavigateToUrlKeyword.execute(NavigateToUrlKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.navigateToUrl(WebUiBuiltInKeywords.groovy:187)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$navigateToUrl$0.call(Unknown Source)
at 9000 - Alerts - Alerts Log.run(9000 - Alerts - Alerts Log:38)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:430)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:421)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:400)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:392)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:273)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1631900237221.run(TempTestCase1631900237221.groovy:25)
Caused by: java.lang.IllegalArgumentException: Url cannot be null or empty
at com.kms.katalon.core.webui.keyword.builtin.NavigateToUrlKeyword$_navigateToUrl_closure1.doCall(NavigateToUrlKeyword.groovy:75)
at com.kms.katalon.core.webui.keyword.builtin.NavigateToUrlKeyword$_navigateToUrl_closure1.call(NavigateToUrlKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more


In which Execution Profile did you define GlobalVariable.TARGET_URL ?
In the “default” profile? or else?

Whichever the Execution Profile is, are you sure you applied that profile when you ran your test case?

I guess, you created an Execution Profile (e.g, “foo” profile) where you defined the GlobalVariable.TARGET_URL, but you forgot to apply the “foo” profile for the test case run.

In that case, your test case will fail to find the GlobalVariable.TARGET_URL, as it is not there in the applied Profile.

@kazurayam I’ve defined an additional profile called “Staging” to go along with production which is, of course, “default”. Both profiles have global variables established with TARGET_URL being the string value of each respective URL to navigate to the desired environment. Neither selecting “Staging” nor “default” changes the error output.

Put this at the top of a test and run it against each profile:

println GlobalVariable.TARGET_URL + "*************************"

Then check the console.