What is the value for my input data Using IF statement and FindTestData from Excel?

Hi Katalon Community,

I want to automate the checkbox in my system.
I am using IF function and i want that IF function to read from my excel data that i had prepared.
This is the sample of my excel data. i name the data file as testing_checkbox:
C1 to C6b are the name of each of the checkbox.
In my test data i want to test various scenario for clicking each of the checkbox.

This is my Manual Recording step, i add in IF function before click all the Checkbox.

My question is how do i make input for IF statement to read from my data file?
What is Data Value Type that should i select? I try to choose value as Test Data Value.

But i am not sure what value should i put for test data, column and row.

Pls help me. Thank you in advance :slight_smile:

2 Likes

Hi there @insyirahmajid,

I have set your topic to auto-bump itself in a few hours so that others will be able to see your topic on the homepage and support you better. :wink:

Cheers,
Albert

1 Like

if you want to use the excel data for if Condition please follow the following method.

  1. findTestData(‘new_user’).getValue(1, 2)
    here
  2. ‘new_user’ → is your data file Name (you can specify your data file name under which you kept your data

1 inside the Get Value is pointing to the Row
2 inside the Get Value is pointing to the Column

Open script mode
Example
1.

if(findTestData('new_user').getValue(**1**, **2**)=="Your value Here")
2.
 String excel_Data=findTestData(**'new_user'**).getValue(**1**, **2**)
if(excel_Data=="Your value Here")

if you need to select it in ui it should be TestData Value for excel Data

Hi @bharathi.a , thanks for your help.

If my data file have 10 row of data, how can i make the Get Value to be flexible?
I want the Get Value to read all row in the data file.

Previously i did that control at Data Binding, where i set the automation to run from which row i required.
However i am bit confused when it come to read the data file from the IF statement function.

1 Like

I made a Test Data named testing_checkbox similar to yours as this:

I made this Test Data based on a CSV file, not Excel, but this difference should not be significantt at all.

I wrote a Test Case:

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import com.kms.katalon.core.testdata.TestData as TestData

// see the doc of TestData class at
// https://api-docs.katalon.com/com/kms/katalon/core/testdata/TestData.html

TestData testData = findTestData("testing_checkbox")
int numberOfRows = testData.getRowNumbers();

for (int rowx = 1; rowx <= numberOfRows; rowx++) {
	String c1 = (String)testData.getObjectValue("C1", rowx)
	String c2 = (String)testData.getObjectValue("C2", rowx)
	String c3 = (String)testData.getObjectValue("C3", rowx)
	String c4 = (String)testData.getObjectValue("C4", rowx)
	String c5 = (String)testData.getObjectValue("C5", rowx)
	String c6a = (String)testData.getObjectValue("C6a", rowx)
	String c6b = (String)testData.getObjectValue("C6b", rowx)
	println "C1=${c1}, C2=${c2}, C3=${c3}, C4=${c4}, C5=${c5}, C6a=${c6a}, C6b=${c6b}"
	
	// here you can insert any statements that uses the variable c1, c2, ...
	
}

When I ran the Test Case, I got the following output in the console:

2024-01-19 12:13:10.022 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-01-19 12:13:10.027 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC1
C1=1, C2=1, C3=1, C4=1, C5=0, C6a=0, C6b=0
C1=1, C2=1, C3=1, C4=1, C5=1, C6a=0, C6b=0
C1=1, C2=1, C3=1, C4=1, C5=0, C6a=1, C6b=0
C1=0, C2=0, C3=0, C4=0, C5=0, C6a=0, C6b=1
2024-01-19 12:13:10.779 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC1

Please find that this Test Case can get access to data of cells. The code identifies each cells by the combinations of rowx (row index) and column name such as “C1”, “C2” etc.

This sample code shows how to read the Test Data. You can start with this sample code, change it, add any statements as you need.


@insyirahmajid

My sample code does “Data Binding” on it’s own. It read an external data source, digest it into rows, pick up data items in a row into a set of variables so that you can refer to the data via variables. I guess, that is what you wanted to do.

Stop using “Manual mode” which would not let you iterate over the data rows. You need to do real programming in the “Script mode”.

You can find the API documentation of Test Data class at

1 Like

@insyirahmajid please follow the script shared by @kazurayam.

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import com.kms.katalon.core.testdata.TestData as TestData

TestData testData = findTestData("testing_checkbox")
int numberOfRows = testData.getRowNumbers();

for (int rowx = 1; rowx <= numberOfRows; rowx++) {
	String c1 = (String)testData.getObjectValue("C1", rowx)
	String c2 = (String)testData.getObjectValue("C2", rowx)
	String c3 = (String)testData.getObjectValue("C3", rowx)
	String c4 = (String)testData.getObjectValue("C4", rowx)
	String c5 = (String)testData.getObjectValue("C5", rowx)
	String c6a = (String)testData.getObjectValue("C6a", rowx)
	String c6b = (String)testData.getObjectValue("C6b", rowx)

if(**your required condition here** example(if(c2<=25))
{
and println(c2)
}
}
  1. loop will fetch all the data from the data file(CSV File) as a string
  2. use your condition wherever you need inside the loop

@insyirahmajid

If I were to propose a solution for this, I would not use Excel at all.

Let me show you my code. I wrote a Test Case in the Script mode:

doSomething(["C1":true, "C2":true, "C3":true, "C4":true, "C5":false, "C6a":false, "C6b":false])
doSomething(["C1":true, "C2":true, "C3":true, "C4":true, "C5":true, "C6a":false, "C6b":false])
doSomething(["C1":true, "C2":true, "C3":true, "C4":true, "C5":false, "C6a":true, "C6b":false])
doSomething(["C1":false, "C2":false, "C3":false, "C4":false, "C5":false, "C6a":false, "C6b":true])

def doSomething(Map<String, Boolean> cond) {
	println("-------------------------------")
	println(cond)
	if (cond["C1"]) {
		println("do something great for C1")
	}
	if (cond["C2"]) {
		println("do something funny for C2")
	}
	if (cond["C3"]) {
		println("do something interesting for C3")
	}
	if (cond["C4"]) {
		println("do something brilliant for C4")
	}
	if (cond["C5"]) {
		println("do something monstrous for C5")
	}
	if (cond["C6a"]) {
		println("do something tricky for C6a")
	}
	if (cond["C6b"]) {
		println("do something lucky for C6b")
	}
}

When I ran this, I got the following output:

2024-01-19 21:58:37.185 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-01-19 21:58:37.190 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC2
-------------------------------
[C1:true, C2:true, C3:true, C4:true, C5:false, C6a:false, C6b:false]
do something great for C1
do something funny for C2
do something interesting for C3
do something brilliant for C4
-------------------------------
[C1:true, C2:true, C3:true, C4:true, C5:true, C6a:false, C6b:false]
do something great for C1
do something funny for C2
do something interesting for C3
do something brilliant for C4
do something monstrous for C5
-------------------------------
[C1:true, C2:true, C3:true, C4:true, C5:false, C6a:true, C6b:false]
do something great for C1
do something funny for C2
do something interesting for C3
do something brilliant for C4
do something tricky for C6a
-------------------------------
[C1:false, C2:false, C3:false, C4:false, C5:false, C6a:false, C6b:true]
do something lucky for C6b
2024-01-19 21:58:38.241 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC2

Far simpler, isn’t it?

Although you need to be a programmer to write this.

If you’re willing to do some coding, this blog post may serve you well. Check out the section on Builders.

Happy coding!