Loop over url/user/passw combinations

Hi, I just found Katalon and it’s really great!

I created a test-case using global variables as url/username/password and execute it from cmd line using the -g_ approach to run the test for different environments.
Each time it runs it has to instantiate the whole runtime environment adding time to the overall duration.

Is there a way to have the url/user/passw combinations stored inside the project (or maybe read from .csv?) and execute the test case while looping over those combinations so it only has to instantiate once?

Thanks!
L

Hi Lars,

it is definitely possible. If you prefer using external sources (e.g. file), this should work:

import com.kms.katalon.core.util.KeywordUtil

File loginInfoFile = new File("C:\\test\\userPasswdCombofile.txt")
BufferedReader fr = new BufferedReader(new FileReader(loginInfoFile))
List<String[]> parsedLoginInfo = new ArrayList()

while((line = fr.readLine()) != null) {
	String[] parsedLine = line.split(",")
	parsedLoginInfo.add(parsedLine)
}

for(String[] singleRecord in parsedLoginInfo) {
	KeywordUtil.logInfo("For the address " + singleRecord[0] + ": My name is " + singleRecord[1] + " and my password is " + singleRecord[2])
	
	// put your test scenario into this loop
}

Output:

The file content looks like this:

url1,admin,password1
url2,user,password2
url3,anotheruser,password3
2 Likes

hi,

check this site

or using yaml

1 Like

hello,

like this way

users.yaml

url1: https://www.katalon.com
url2: https://www.google.com
url3: https://www.google.fi
user1: admin
user2: user
user3: anotheruser
pass1: password
pass2: secret
pass3: unknown

Testcase
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import com.esotericsoftware.yamlbeans.YamlReader; //this will need to download yamlbeans-1.06.jar to Drivers folder

reader = new YamlReader(new FileReader("C:\\KatalonStudio\\KatalonProject\\Include\\USERS\\users.yaml"));
Object object = reader.read();
System.out.println(object);
Map map = (Map)object;
System.out.println(map.get("url1"));
System.out.println(map.get("url2"));
System.out.println(map.get("url3"));

results:
https://www.katalon.com

https://www.google.com

https://www.google.fi

or you can simply use the builtin feature for data driven testing approach.
check the doc’s, there are also plenty topics on this matter here on the forum
add your testcases to a testuite and bind the data file to it

It’s running the test-case & looping over a bunch of URL’s from a file and grabbing the necessary variables with just a single invocation of Katalon cmdline. Also squeezed in some steps to send metrics to a Prometheus push gateway for Grafana visualising! Looking great!

Thanks for the replies!
L