How to Create a Data-Driven Test from XML files
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, for example, databases, spreadsheets, XML files, and so on.
In fact, Maveryx supports XML files, Excel spreadsheets, and almost any database (JDBC sources) including Microsoft SQL Server, Oracle, MySQL, Microsoft Access, and others.
For this reason, in the MAVERYX_HOME/demo directory, you can find some easy examples.
Example
Of course, Maveryx supports also XML data sources, with the following structure:
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<testdata name="username" type="java.lang.String">
<data id="user1" value="john.smith@maveryx.com"/>
<data id="user2" value="support@maveryx.com"/>
</testdata>
<testdata name="password" type="java.lang.String">
<data id="1" value="Jsmith01"/>
<data id="2" value="johnsmith"/>
<data id="3" value="mysupport"/>
</testdata>
</dataset>
dataset: the root element. Obviously, this element shall contain at least one testdata element.
testdata: contains a collection of related test data. Such element too shall contain at least one data element. As you can see, testdata shall consist of the following properties:
- name: a string label for the test data
- type: the test data type (OPTIONAL)
data: the test data. This element shall consist of the following properties:
- id: a string label specifying the data Identifier (you can use alphanumeric values such as “1”, “one”, “data–1”…)
- value: the test data value
How to Integrate Data-Driven testing into your script
To integrate data-driven testing into your Maveryx test script firstly you have to 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 XML data file:
TestDataManager t = new TestDataManager( “C:\\Maveryx\\demo\\data\\Test_Data.xml”)
At this point, to get a specific value you have to specify the testdata element and the specific data:
//get the ‘username’ with id = ‘user1’ – ‘john.smith@maveryx.com’
String username = t.getData( “username” ).getDataById( “user1”).getValue();
//get the ‘password’ with id = ‘1’ – ‘Jsmith01’
String password = t.getData( “password”).getDataById(“1”).getValue();
In conclusion, 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’ with id = ‘2’
String password = t.getData( “password” ).getDataById(“2”).getValue() ;
//enter the password
pText.setText(password) ;
That’s all!
We hope this article was useful. For any further questions on this and more, do not hesitate to get back to us.