Jenkins - parameterization for test build

I have a test suite in KS which validates a website with parameterized data(FirstName, LastName, Phone#, City etc…)which means, every time I run my test suite it looks for the csv file which has multiple rows and columns in order to read the contents and submit the form vis website.

My question is, am planning to do CICD where whenever my developers push and commit any changes to branch my test build in Jenkins will invoke automatically and run the test. But my concern is, I don’t want my test build to consume same test data from csv rather it should be a loop. To cut it short, every time it should take different set of test data from my csv file. Any thoughts will be helpful.

Thanks,
Vimal

every time it should take different set of test data from my csv file

Could you give us an conceptual example of your csv file?

Would you be satisfied if I show you how your test case chooses just randomly one line among the following CSV and print it to console?:

sample,data,1,
sample,data,2,
sample,data,3,
sample,data,4,
sample,data,5,

Or do you have any more requirements?

1 Like

So the CSV file would have headers as FirstName, LastName, City, Phone#, PostalCode and there will be around 20 rows(ie, 20 test data) in a csv/xls file. I guess you got my question. Still, trying to clarify more - I would like to see whenever Jenkins test build gets invoked how it will not end up choosing the same row#(same test data). Because, when my Jenkins test build got invoked for the first time it would have chosen row#1…now when the job got invoked again for the 2nd time, how will I make sure it won’t chose again the row#1 but row#2 ?

when my Jenkins test build got invoked for the first time it would have chosen row#1…now when the job got invoked again for the 2nd time, how will I make sure it won’t chose again the row#1 but row#2 ?

I do not understand why want to do this, but …

Using OS-level environment variable would be an option for you.

In the command line or windows bat script you would do:

>set dataIndex=1>...>.\katalon -runMode=console ...

and in your Test Case you do

def dataIndex = 0
if (System.getenv("dataIndex") != null) {
    dataIndex = Integer.parseInt(System.getenv("dataIndex"))
}
// you use dataIndex to retrieve the row
2 Likes

kazurayam said:

I do not understand why want to do this, but …

I need this because, the outcome of my script is to read the data(for example, ID) from csv/xls and create an ID with the same name as mentioned in row#1. So, when my script runs for the second time, I want my script to look at row#2 for retrieving the ID2 and create the ID with the same name. I cannot afford having duplicate IDs as it will impact the system. Hope this helps

>set dataIndex=1Is this 1 is the number of rows in total?

set dataIndex=N

dataIndex here represents which specific row you want.

---------------------------------------------
Let me show you an example.
I have a Data File like this:

I wrote a test script TC2:

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
TestData data = findTestData('Book1 (1)')
int row = 2
if (System.getenv("dataIndex") != null) {
    row = Integer.parseInt(System.getenv("dataIndex"))
}
StringBuilder sb = new StringBuilder()
for (int col = 1; col <= 3; col++) {
    if (col > 1) sb.append(',')
        sb.append(data.getValue(col, row))
    }
WebUI.comment("${row}: ${sb.toString()}")

When I ran TC2 without Environment variable, I got the following message in the log:

10-09-2018 02:49:28 PM - [INFO]   - 2: 333,333,333

And when I ran TC2 in the console mode specifying the Environment variable dataIndex=5,

>set dataIndex=5>...>.\katalon -runMode=console ...

I got the following message in the log:

10-09-2018 02:xx:xx PM - [INFO]   - 5: 666,666,666

Book1.PNG

1 Like

I like this idea and Thanks for sending this out. But, as I already mentioned I do not want to hard code the dataIndex value to the row number from which I need data. Because, if that is the case I can just put one row of test data and ask my script to always look for it whenever Jenkins test build is triggered.

I’m looking for something like…if my test data file has 5 rows, whenever Jenkins test build is triggered my test script should use ‘next’ test data. And this should happen automatically. In the example you mentioned, I have to go to Jenkins every time and set the value to the row number for the one which I want to use. What am planning is a CICD workflow which should not have any manual intervention.

you can use the $BUILD_NO env variable to set the dataIndex value :wink:

Ibus,

I made a Test Case as this

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.comment(">>> BUILD_NO=${System.getenv('BUILD_NO')}")

When I executed this, I got the following output:

10-10-2018 03:14:46 PM - [START]  - Start action : comment10-10-2018 03:14:46 PM - [INFO]   - >>> BUILD_NO=null
10-10-2018 03:14:46 PM - [END]    - End action : comment

This output tells that there is no environment variable BUILD_NO available.

Could you elaborate a bit more how to get access to the BUILD_NO?

@4280-kazurayam

Sorry, is BUILD_NUMBER. Pay attention that this is Jenkins specific, for other CI’s may be different or not available at all.

The current build number, such as “153”

A bit of math will be needed also, if let’s say the data has only 5 rows, since the build it will continuously increase with each execution … but that should be trivial to do it, e.g:

BUILD_NUMBER % 5 + 1

You may just randomized the the row var in your case, eg.
row = Math.floor(Math.random() * DataRowCount) + 1

with this, every time you execute, the row number is random within your data file