Excel data file - Value reading to List

Hi
I am trying the to pick all the data from excel data file and stored into list and later use those list values to do my test
My code
Role = findTestData(‘Data Files/Role_List’).getAllData()
println('Role values in excel ’ + Role)
Role is set as list in variable section
i got something like below
i am expecting only my text value without []. How do we achieve that ?

Role values in excel [[East Substance Misuse - x], [DOS Substance Misuse - y]]

Looking at the source code for this, it looks like the getAllData() method returns a List<List<Object>>, which makes sense, as it’s trying to give you what is essentially a 2-dimensional array to represent the entire spreadsheet. So when you are printing the “Role”, you are not printing a series of strings, but rather you are printing a list of lists of strings:

[      [East Substance Misuse - x]    ,    [DOS Substance Misuse - y]    ]
|                    |                                 |
List of Rows   First Row of Data as List          Second Row of Data as List

If you instead want just a long list of values by iterating through each row/column, you could try:

List<List<String>> data = findTestData("Data Files/Role_List").getAllData();
List<String> values = new ArrayList<String>();
for(List<String> row : data) {
   values.addAll(row);
}

You would then have a 1-dimensional list of values in row/column order grabbed from the data file to do whatever you want with.

1 Like

Thank you for the solution.Its working fine now.

Hi Saranya
For my application after entering login credentials(Username and Password),
authentication pass-code will be send to my personal mobile,then I have use that number to access the application .
Can you advise me how to handle this scenario.

Hello Vinay,
I am also a new user to katalon. :slight_smile:
In my case its Data Driven Test so i am passing all my data instructions to my script via data files.
In your case its quite different by sending value to different device; is its a mobile testing/web ?

its Web,is it possible to send via run time arguments in Katalon studio
does katalon studio support run time variable?

Hi Vinaynk,
I think this is different with my topic which i have created. It would be better to create the new topic with your query. So that you will get the solution for your problem.

1 Like

@Brandon_Hein

Regarding this piece of code, it copies all the rows data in a string list. Would you know how to use this in a scenario where I am using data binding in my test that takes one row at a time.

I have internal data file like this:

image

What I want is to call add items to cart method depending on the number of items present in a row. So in my case, the test would trigger and add two items to cart, it then execute other steps like checking out and then terminates. Due to data binding, a second test triggers and this time it should add item to cart once, since the second row has only single item.

For me, what the above code does is it adds three items to cart. It stores the values 69924, 69926 and 69926 in a list, whereas I want it to save the first two items in the first iteration, and then when the test is triggered second time, it saves just one itemID in the list.