# Changing a variable during a test suite run

**URL:** <https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951>\
**Category:** Miscellaneous\
**Created:** [August 30, 2018, 4:35pm UTC](https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951 "2018-08-30T16:35:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Deverson](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Josh\_Deverson](https://forum.katalon.com/u/Josh_Deverson)\
**Post date:** [August 30, 2018, 4:35pm UTC](https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951/1 "2018-08-30T16:35:11Z")

</div>

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](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](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](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.

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [August 30, 2018, 6:06pm UTC](https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951/2 "2018-08-30T18:06:55Z")

</div>

Hey Josh,

this is what I would do:

```auto
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](https://s3.amazonaws.com/katalon-forum/editor/8p/7xoyt9f01dzt.txt)

---

<div class="post-metadata">

**Author:** ![Josh\_Deverson](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Josh\_Deverson](https://forum.katalon.com/u/Josh_Deverson)\
**Post date:** [August 31, 2018, 12:43pm UTC](https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951/3 "2018-08-31T12:43:21Z")

</div>

Marek,

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

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 31, 2018, 1:09pm UTC](https://forum.katalon.com/t/changing-a-variable-during-a-test-suite-run/12951/4 "2018-08-31T13:09:45Z")

</div>

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.
