For Loop: Support for pulling out specific db data within a specified column

Hi,

I’m having trouble writing a for loop that would search for a specified value within a specified column of a database (shown below). The database is named ‘DM_Demo’ with ‘Column_Name’ as the specified column, and ‘ABC’ as the value to find. Essentially to run through the ‘Column_Name’ list and only run the command if a username is “ABC”.

TestData Demo_User = findTestData(“DM_Demo”)

for (def index : (0…Demo_User.verifyColumnName(“Column_Name”))) {

WebUI.openBrowser(‘’)

WebUI.navigateToUrl(‘http://Demo.com/#/’)

WebUI.waitForElementVisible(findTestObject(‘Page_Demo/Login/Login_Username’), 0)

WebUI.setText(findTestObject(‘Page_Demo/Login/Login_Username’), Demo_User.internallyGetValue(“ABC”,index))

WebUI.setText(findTestObject(‘Page_Demo/Login/Login_Password’), GlobalVariable.Login_Password)

WebUI.click(findTestObject(‘Page_Demo/Login/button_Sign in’))

}

Thanks in advance!

Still in need of help, if anyone can respond? Would be greatly appreciated.

Dom,

I am not sure if I understood the question correctly. Did you want to get the value of a column or the index (row_number)?

Following script could be used to loop through a ColumnName and print out each value in row. Does it help?

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

int rows = accounts.getRowNumbers()

for (i in 1…rows) {

println accounts.getObjectValue(‘Username’, i)

}

Thank you for the response Trong! Apologies for the confusion, certainly new to all this!

I have a data file (a linked DB) with the following data:

LocationName (Column 1)
- Location1
- Location2
- Location3
- Location1
- Location2
- Location3

LoginUsers (Column 2)
- DEFUser
- ABCUser
- DEFUser
- ABCUser
- ABCUser
- DEFUser

What i’d like to do is write a test case that would login only users with a username of ‘ABCUser’. The data is expandable so more of this user type can be added/removed.

How would i go about writing a script that would run logins for 'ABCUser’s only? Essentially looking through ‘Column 2’ for the ‘ABCUser’ and then running a login script for these users ignoring ‘DEFUser’?

Thanks again!

Dom,
I got the scenario now. It will be easy if this test case is just a login test since we could use above script with an if checking for username. However, in more complicated situation where you need to call other test cases in the flow, for example:
- call testcase Login
- call testcase do something else (searching, verifying, etc).
then we do not have proper solution for it since we havent added filter ability to the DataFile yet.

I think some work-aroud solutions now are:
- combine all steps into single test case and then use above scripts to filter for logged in account.
- create temporary DataFile which contains only the account you wanna test.

I will put the filter ability to DataFile into our backlog for future release.

Dom,

The snippet for your case could be:
- Create a test case
- Add a Variable name username
- Add test script as below:

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

int rows = accounts.getRowNumbers()

for (def i : (1…rows)) {

def user = accounts.getObjectValue('Username', i)

if (user == username) {

   // do login

   // do more test steps

}

}

Notes:
- username is a variable helping you extend more test data later.

Sorry for the delayed response. Thanks Trong! Works like a treat!