Changing a variable during a test suite run

Hi all,

I will try to keep this as brief as possible. With as much detail as I can.

Scenario

I
am running a very simple test suite that will check multiple URL’s.
Some of these URL’s have a prefix of https, others have a prefix of www.
They all lead to the same site but I need to test that the sites are
all up and running.

Currently, I have it set like this;

WebUI.openBrowser(’’)

WebUI.maximizeWindow()

WebUI.navigateToUrl(‘https://website.com’)

CheckDefaultLanguage = WebUI.waitForElementAttributeValue(findTestObject(‘Check For English/Language_Select’), ‘Value’,
‘English’, 3)

if (CheckDefaultLanguage == false) {
WebUI.click(findTestObject(‘Check For English/input_ddlLanguage’))

WebUI.click(findTestObject('Check For English/td_English'))  

}

WebUI.verifyTextPresent(‘Business Management Centre’, true)

WebUI.navigateToUrl(‘http://website.com’)

CheckDefaultLanguage = WebUI.waitForElementAttributeValue(findTestObject(‘Check For English/Language_Select’), ‘Value’,
‘English’, 3)

if (CheckDefaultLanguage == false) {
WebUI.click(findTestObject(‘Check For English/input_ddlLanguage’))

WebUI.click(findTestObject('Check For English/td_English'))  

}

WebUI.verifyTextPresent(‘Business Management Centre’, true)

WebUI.navigateToUrl(‘http://www.website.com’)

CheckDefaultLanguage = WebUI.waitForElementAttributeValue(findTestObject(‘Check For English/Language_Select’), ‘Value’,
‘English’, 3)

if (CheckDefaultLanguage == false) {
WebUI.click(findTestObject(‘Check For English/input_ddlLanguage’))

WebUI.click(findTestObject('Check For English/td_English'))  

}

WebUI.verifyTextPresent(‘Business Management Centre’, true)

WebUI.closeBrowser()

However,
it has come to my attention that the above is a very set way of dealing
with this and we are looking to move our servers to the cloud,
therefore, this test needs to be used more.

Requirement

I
need to make it so that, either in the test case or test suite, the
prefix to the URL (www. or https etc.), is changed 4 times before moving
on to the next case, or closing the browser.

Is there
any way of getting Katalon to run through multiple variables, through
something like a data file? I just want to try and make this test as
flexible as possible.

Any questions please ask.

TL;DR: I want a variable that changes 4 times before the test case finishes, changing the start of a URL each time.

Hey Josh,

this is what I would do:

import com.kms.katalon.core.configuration.RunConfigurationimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIimport static com.kms.katalon.core.testobject.ObjectRepository.findTestObjectBufferedReader fr = new BufferedReader(new FileReader(RunConfiguration.getProjectDir() + "\\Data Files\\prefixes.txt"))List<String> prefixes = new ArrayList<>()while((line = fr.readLine()) != null) {	prefixes.add(line)}for(String prefix in prefixes) {	WebUI.navigateToUrl(prefix + 'website.com')		CheckDefaultLanguage = WebUI.waitForElementAttributeValue(findTestObject('Check For English/Language_Select'), 'Value',		'English', 3)		if (CheckDefaultLanguage == false) {		WebUI.click(findTestObject('Check For English/input_ddlLanguage'))			WebUI.click(findTestObject('Check For English/td_English'))	}		WebUI.verifyTextPresent('Business Management Centre', true)}

First, put your prefixes into some file (I put it into /Data Files/prefixes.txt) - attached.
Then, read all lines and put it into a list to work with them easily.
Finally, use for-each loop to loop through all your prefixes and do the rest of stuff.

The advantage of this solution is that your prefixes are centralized in a file - and you can use them in multiple test cases.
Yes, you can simply create a list and put all prefixes there, but when you add/remove some of them, you’d have to rewrite all tests where the ya re included. This is more robust solution.

prefixes.txt

2 Likes

Marek,

Thank you so much, that one was getting to me.

Upvoted.

The advantage of this solution is that your prefixes are centralized in a file - and you can use them in multiple test cases.

Yes,
you can simply create a list and put all prefixes there, but when you
add/remove some of them, you’d have to rewrite all tests where the ya re
included. This is more robust solution.

Mantra!

Marek, please, write this up as a “Tip” so we can have it republished properly.