Switching between Data Files based on execution profile

Not sure if I’ve completely missed this feature, or if it really doesn’t exist.

First question is about testSuites. I should be able to tell it to use datafile_dev when -executionProfile=dev and to use datafile_qa when -executionProfile=qa. How do I do this?

Second one is about the testSuiteCollections. Why do I have to manually choose profiles? I’d expect the testSuiteCollection to run with the execution profile that I pass in the arguments.

Thanks in advance.

1. This should do it for the first question:

import com.kms.katalon.core.configuration.RunConfiguration as RC
RC.getExecutionProfile()

2. You are right about the second. Unfortunately, for now you can only manually choose profiles for the test suite collections. See: http://forum.katalon.com/discussion/6178/console-mode-execution-with-different-profiles-always-uses-default#latest.

Thanks!

1. So I’ve got the below based on your answer. But now trying to find out how to set the appropriate data file to the test suite in the script. i.e. what goes inside the cases?

def profile = RC.getExecutionProfile()	switch (profile) {		case "local":		break		case "qa":		break	}

2. The question in that thread “Does anyone know if this is by design and if there is a workaround or coming fix?” hasn’t been answered yet though. I’ll keep my hopes high!

There’s com.kms.katalon.core.testdata.TestDataFactory.findTestData…
So
case “local”: myData = TestDataFactory.findTestData(“Data Files/data_file_1”) …

You will need to link your data files to Katalon by going to File > New > New Test Data.

Mate Mrse said:

There’s com.kms.katalon.core.testdata.TestDataFactory.findTestData…
So
case “local”: myData = TestDataFactory.findTestData(“Data Files/data_file_1”) …

You will need to link your data files to Katalon by going to File > New > New Test Data.

I guess my question was what would that “myData” that you’ve mentioned in your code snippet be? What type is that?

I have already linked the 2 different data files to the test suite through the UI. But I don’t know how to tell the script which to use.“MyData” should be the object being used by the test suite as the current data file being used. But how and where is that defined?

Thanks again!

If you go to File > New > New test data, you will link some file (let us say an excel table named “data_file_1” as in my example) with Katalon.
Then, myData = TestDataFactory.findTestData(“Data Files/data_file_1”) says to Katalon to use that file as the source for myData.

Now let’s say that you are running another profile “qa” and you wish to use an another file. Just add myData = TestDataFactory.findTestData(“Data Files/data_file_2”), where “data_file_2” is another excel sheet that you previously added (File > New > New test data).

Oh Interesting! so myData is a meaningful thing in itself not a variable of some sort. How did you find that out?!

I tried that, it doesn’t seem to be working because in the variable binding section, the test data column seems to be only taking whatever data file I’ve inputted there through the UI, and not being automatically updated with the correct data file when myData is set in my script.

@SetUp(skipped = false) // Please change skipped to be false to activate this method.
def setUp() {	// Put your code here.	def profile = RC.getExecutionProfile()		switch (profile) {				case "local":				myData = findTestData("Data Files/AUM_local")		break				case "qa":			myData = findTestData("Data Files/AUM_qa")		break		default:			myData = findTestData("Data Files/AUM_qa")		break	}}

Screen Shot 2018-09-18 at 09.16.18.png

What does your Tests Explorer show under “Data Files”? It should look something like this:

2018-09-18_11-06-18.png

Screen Shot 2018-09-18 at 10.21.06.png

I’m using internal data so I don’t have the File’s information section like you do. I just have 2 columns accountName and date, with my data in it.

myData = TestDataFactory.findTestData(“Data Files/data_file_1”) only links “myData” to a file in filesystem.
But then, if you want to read from that file, you would use something like:
def accountName = myData.getValue(1,1)
def date = myData.getValue(1,2)

I thought there might be a way to do this without having to write the whole test case in the script. It’s a shame the UI doesn’t allow a seamless integration of profiles and data files for test suites. I don’t want to have to loop through all the rows and columns in the file and assign values to variables that will then be used by the test cases… too long winded :frowning:

1 Like

So, Katalon team, this is my feature improvement suggestion. Please allow assigning data files to execution profiles in the UI.

1 Like

Hi,

Did you find another way to switch between data files based on execution profile?

Implementing this feature will be very useful to many of the folks, as it will add scalability to the framework especially while testing multi environment applications. Please try to implement this feature asap

1 Like

Is there a way today to bind a data file with an execution profile ?
Or to reference the data file with a variable and set this variable in the execution profile ?

Any improvement on this feature?

2 Likes

Did someone found any solution for above issue @Katalon_team

This is a workaround, and kind of hack-ish, but is working fine.

First, organize the Test Data folder like this:

Test Data/Profiles/default/users
Test Data/Profiles/staging/users

Then, in each profile, create a variable users whose value is like findTestData('Profiles/default/users'), replacing ‘default’ with the correct profile name of course.

Finaly, in the script, get the data like so:
GlobalVariable.users.getValue('password', 1)

There doesn’t seem to be a way of adding a method call directly in manual mode, I have to drop down to script mode.

"Welcome To The Desert Of The Real. "

so said Morpheus :sunglasses: in The Matrix