Start your demo and save on the first 12 months!

Blog

Data-driven from excel files

Posted by on 15 June 2021 in Blog, Tips

Data-driven tests are functional tests that perform the same series of test actions, but with different data sets supplied by an external data source (database, spreadsheet, XML files …).

Maveryx supports XML files, Excel spreadsheets and almost any database (JDBC sources) including Microsoft SQL Server, Oracle, MySQL, Microsoft Access, and others for data-driven testing.

In the MAVERYX_HOME/demo directory, you can find some examples using the data-driven approach.

Maveryx supports also Excel data sources with the structure in the following image:

Test data are organized by columns.
The first row contains the table header.
The first cell of each column shall contain the string label for the test data (e.g. “username”, “password”).
Each cell from the second one defines test data (input or expected output).

To integrate data-driven testing into your Maveryx test script you have to first import the relevant libraries:

import com.maveryx.util.datadriven.*; //import the data-driven libraries

Then you have to create a new TestDataManager object to manage the test data, by passing the full path to the xls data file:

TestDataManager t = new TestDataManager( C:\\Maveryx\\demo\\data\\Test_Data.xls”)

TestDataManager constructor creates automatically an equivalent XML file from the XLS one. To get a test data you have to specify the column header and the row number:

//get the ‘username’ at row = 2 – ‘john.smith@maveryx.com’
String username = t.getData( “username” ).getDataById( “2”).getValue();

//get the ‘password’ at row = 3 – ‘johnsmith’
String password = t.getData( “password”).getDataById(“3”).getValue();

This piece of code shows how to integrate the data-driven approach into a Maveryx test script:

//create a new password text field
GuiPasswordText pText = new GuiPasswordText();

//get the ‘password’ at row = 2 – ‘Jsmith01’
String password = t.getData( “password” ).getDataById(“2”).getValue() ;

//enter the password
pText.setText(password) ;

At the same time, it’s possible to integrate data-driven and keyword-driven testing.
In your keywords-driven tests use the parameters fields to set the data source:

${file path} {testdata name} {data id}: to use the data-driven mechanism
(e.g. ${ C:/Maveryx/demo/data/Test_Data.xls} {username} {user1})
#{i}: for loop (for/foreach) counter variables
\\${value}: to use a custom data-driven mechanism

We hope this article was useful. For any further questions on this and more, do not hesitate to get back to us.