How to use DataFile to pass data from file into test

I’m trying to hold passwords (for testing of course) in the datafile within Katalon. How to I access the password in order to pass it into my test?

For example:
I want to change my password but I have to input my current password, my new password and my new password again. I have the pws in the file. How do I access those to input them into the tests? (kind of like calling a method or testObject…)

Thanks!

Amanda,
Could you try following snippet? The data is first loaded from the DataFile and then used in the script.

TestData accounts = findTestData(‘Data Files/Accounts (1)’);

int rows = accounts.getRowNumbers()

for (i in 1…rows) {

println accounts.getObjectValue('Username', i)

}

Trong Bui said:

Amanda,
Could you try following snippet? The data is first loaded from the DataFile and then used in the script.

TestData accounts = findTestData(‘Data Files/Accounts (1)’);

int rows = accounts.getRowNumbers()

for (i in 1…rows) {

println accounts.getObjectValue('Username', i)

}

Hey, one question… using this snippet with my DataFile, should i be able to store test outputs?

@10127-Martin

Currently we could not save the outputs into the DataFile, maybe the GlobalVariable is a place for storing runtime output.

@Amanda Perkins

You can also declare a variable in the testcase and set it’s type to Test Data Value, if the GUI approach is more comfortable:

Test Data Value Input.png

Trong Bui said:

@10127-Martin

Currently we could not save the outputs into the DataFile, maybe the GlobalVariable is a place for storing runtime output.

Thanks… do you know what should be the best approach or best practice to pass values between test cases?
For example, I have a test case linked to a data file that creates a kind of item, so if I load 3 records in that datafile it will run 3 times… where should store that? I have another test case that should take that created data and perform another action.

Thanks for your help!

@10127-Martin

We have different ways to return a value from a test case and pass it to another test case. There is a problem in your setup (when using Katalon) is that we do not know where to save the data in the next row of data-driven.

if you create items in databases, when we can query it and use in the next test case. In this situation, you can create all resources in a single test cases before executing the rest.

if the data created are at runtime, I will save them into a GlobalVariable, and use it in other test cases. Another option is saving data into external files.

@10127-Martin

In my understanding, you need to re-use the data grabbed by one test case and iterate another test-case over it.

In this case, you can create a ‘mockup’ test data (with some default values).

CSV or internal (XML) are easy to parse file formats.

Since the test data are in fact physical files on hdd (and since the test data is already defined you should know the exact path and name), you can use some system commands to parse it’s content when the first test case is executed and update the data into the given file.

Not sure how safe is this procedure or if it will actually work, but you can try.