#  Get the next record from a data file

**URL:** <https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [December 14, 2022, 3:05am UTC](https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528 "2022-12-14T03:05:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelbenzam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/miguelbenzam/32/20464_2.png) [@miguelbenzam](https://forum.katalon.com/u/miguelbenzam)\
**Post date:** [December 14, 2022, 3:05am UTC](https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528/1 "2022-12-14T03:05:55Z")

</div>

Hello, I have a question, how can I make a method that takes the first record and then runs and takes the second? I have a test where I have to register several computers and I want it to take all the records that it has in that list

---

<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:** [December 14, 2022, 3:51am UTC](https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528/2 "2022-12-14T03:51:55Z")

</div>

> **[Data-driven testing approach with Katalon Studio](https://toolsqa.com/katalon-studio/data-driven-testing-approach-katalon-studio/)**
>
> Katalon Studio supports data-driven testing which allows users to define data sets and execute test scripts that use these data sets.

This article tells you that there is 2 approaches of “Data-driven testing”

- _ **A. Execution from test suites** _
- _ **B. Execute from a test case** _

I guess, you @miguelbenzam are using the “A. Execution form test suites” approach. By the “A” approach, Katalon Studio does opening a file and reading records out of it. KS will pass records one by one to your test case. Your test case code has no control over accessing the data.

“B. Execute from a test case” — I am afraind, it is proorly titled. The title “use  
com.kms.katalon.core.testdata.InternalData object explicitly” would be better.

In the “B” approach, your test case is totally responsible opening a file and reading records out of it.

So you should try the “B”.

---

<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:** [December 14, 2022, 4:29am UTC](https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528/3 "2022-12-14T04:29:53Z")

</div>

> [@miguelbenzam](#):
>
> I have to register several computers and I want it to take all the records that it has in that list

I guess, you should write a preprocessor script. The preprocessor transform the data file(s) to create a simpler list of data which your test can consume just one by one record.

---

<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:** [December 25, 2022, 5:53am UTC](https://forum.katalon.com/t/get-the-next-record-from-a-data-file/81528/4 "2022-12-25T05:53:02Z")

</div>

> [@miguelbenzam](#):
>
> I have a test where I have to register several computers and I want it to take all the records that it has in that list

It sounds like you wish to loop through the models of that `TestData` file…

If so, and you are willing to parse each of the rows into models, I start you off with this `BaseModelBuilder`, straight from my actual project:

```auto
public abstract class BaseModelBuilder<T> {

	protected TestData testData;

	public BaseModelBuilder() {
		this.init();
	}

	public BaseModelBuilder(TestData testData) {
		this.testData = testData;
		this.init();
	}

	protected void init() {
		// implementation go here
	}

	public TestData getTestData() {
		return this.testData;
	}

	public List<T> createModels() {
		return this.testData.getAllData()
				.stream()
				.filter { row ->
					row.stream().anyMatch { String cell ->
						cell != null && !cell.isEmpty()
					}
				}
				.map { row -> this.createModelFromRow(row) }
				.collect(Collectors.toList())
	}

	public T createModelFromRowNum(int rowNum) {
		return this.createModelFromRow(this.testData.getAllData().get(rowNum))
	}

	public abstract T createModelFromRow(List<Object> row)
}

```

to use it, simply:

- create and implement your model class
- extend `BaseModelBuilder` with a builder for `YourModel` (let’s call it `YourModelBuilder`) like so:

```auto
public class YourModelBuilder extends BaseModelBuilder<YourModel> { 
	public YourModelBuilder() { 
		super(findTestData(yourDataFile)); // TODO: replace yourDataFile with whatever you named it in Katalon Studio
	}

	@Override
	public YourModel createModelFromRow(List<Object> row) { 
		// TODO: implement mapping of the 0-based row entries to the properties of YourModel
	}
}

```

- and then, in your data-driven loop-driven test, you can just be like :

```auto
for (YourModel model : new YourModelBuilder().createModels()) { 
	// your model-driven test code goes here
}

```

**NOTE** : you should save these models and builders as [Keywords](https://docs.katalon.com/docs/legacy/katalon-studio-enterprise/extend-katalon-studio/custom-keywords/introduction-to-custom-keywords)
