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

**URL:** <https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [January 17, 2024, 7:46am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447 "2024-01-17T07:46:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![insyirahmajid](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/insyirahmajid/32/16103_2.png) [@insyirahmajid](https://forum.katalon.com/u/insyirahmajid)\
**Post date:** [January 17, 2024, 7:46am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/1 "2024-01-17T07:46:19Z")

</div>

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.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/5/e/5e52ec4aa926522f861e2be44f61e3ec8991a3bf.png)

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

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/8/f/8fa8299536b1131932a48fccb6937aef5db6d8c3.png)

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.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/1/c/1c436cf1c2b725c93f43b1295abfd1080e48f3ce.png)

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

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/4/5/4524c9d0861d5a8cd3172e556c6f22a3cb09507e.png)

Pls help me. Thank you in advance 🙂

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [January 17, 2024, 8:15am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/2 "2024-01-17T08:15:28Z")

</div>

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. 😉

Cheers,  
Albert

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [January 17, 2024, 1:00pm UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/3 "2024-01-17T13:00:37Z")

</div>

Automatically bumped on January 17, 2024, 1:00pm UTC



---

<div class="post-metadata">

**Author:** ![bharathi.a](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bharathi.a/32/24695_2.png) [@bharathi.a](https://forum.katalon.com/u/bharathi.a)\
**Post date:** [January 18, 2024, 2:45pm UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/4 "2024-01-18T14:45:51Z")

</div>

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.

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

```

```auto
 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

---

<div class="post-metadata">

**Author:** ![insyirahmajid](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/insyirahmajid/32/16103_2.png) [@insyirahmajid](https://forum.katalon.com/u/insyirahmajid)\
**Post date:** [January 19, 2024, 2:11am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/5 "2024-01-19T02:11:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 19, 2024, 3:21am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/6 "2024-01-19T03:21:24Z")

</div>

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

 ![スクリーンショット 2024-01-19 12.09.52](https://europe1.discourse-cdn.com/katalon/original/3X/5/9/597b245f706ef38ad965070169fa967a379c7243.jpeg)

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:

```auto
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:

```auto
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

> [@insyirahmajid](#):
>
> 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

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

- [TestData (Katalon Studio API Specification)](https://api-docs.katalon.com/com/kms/katalon/core/testdata/TestData.html)

---

<div class="post-metadata">

**Author:** ![bharathi.a](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bharathi.a/32/24695_2.png) [@bharathi.a](https://forum.katalon.com/u/bharathi.a)\
**Post date:** [January 19, 2024, 4:47am UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/7 "2024-01-19T04:47:23Z")

</div>

@insyirahmajid please follow the script shared by @kazurayam.

```auto
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

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 19, 2024, 1:03pm UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/8 "2024-01-19T13:03:49Z")

</div>

@insyirahmajid

> [@insyirahmajid](#):
>
> I want to automate the checkbox in my system.

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [January 20, 2024, 12:39pm UTC](https://forum.katalon.com/t/what-is-the-value-for-my-input-data-using-if-statement-and-findtestdata-from-excel/114447/9 "2024-01-20T12:39:07Z")

</div>

If you’re willing to do some coding, [this blog post may serve you well](http://forum.katalon.com/t/a-modular-way-to-do-data-driven-testing/83831). Check out the section on Builders.

Happy coding!
