ZS
Katalon Apprentice
09/14/2018

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.
Upvote
Quote

Comments

  • Mate Mrse
    Katalon Expert
    09/14/2018
    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: https://forum.katalon.com/discussion/6178/console-mode-execution-with-different-profiles-always-uses-default#latest.
    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/14/2018
    edited September 14
    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!

    Upvote
    Quote
  • Mate Mrse
    Katalon Expert
    09/17/2018
    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.
    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/17/2018
    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!
    Upvote
    Quote
  • Mate Mrse
    Katalon Expert
    09/18/2018
    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).
    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/18/2018
    edited September 18
    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 } }
    Upvote
    Quote
  • Mate Mrse
    Katalon Expert
    09/18/2018
    What does your Tests Explorer show under "Data Files"? It should look something like this:

    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/18/2018
  • ZS
    Katalon Apprentice
    09/18/2018
    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.
    Upvote
    Quote
  • Mate Mrse
    Katalon Expert
    09/18/2018
    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)
    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/18/2018
    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 :(
    Upvote
    Quote
  • ZS
    Katalon Apprentice
    09/18/2018
    So, Katalon team, this is my feature improvement suggestion. Please allow assigning data files to execution profiles in the UI.
    Upvote
    Quote
Sign In or Register to comment.