Data-driven tests using datatables
The concept of datatables is used to test more than one set of data for the same test scripts. For example if you have a script that tests registration, then you can test the script for different categories of data without having to rewrite the scripts for each test. The most common way to use datatables is to retreive data from a table or spreadsheet.
WET supports datatable through Microsoft Excel or by using a XML based datatable. The limitation is that every test can only retrieve data from one single excel file. The required data must be stored in the first worksheet. The format for entering data in a datatable is as follows:
- Data must be stored in the first worksheet of the specified excel spreadsheet.
- The first row of the spreadsheet represents the data 'fields'. For example, in an employee datatable, the fields may be a) Employee ID, b) First name, c) Last Name, d) Date of Birth and e) Date of joining.
- The first column of the spreadsheet represents the category of data. During any testing assignment, one of the tester's goal is to test the application for various categories of data. For example, you may want to test the employee database for a) first employee,
b) last employee, c) Employee who barely qualifies as eligible to work, d) Employee who is a senior citizen, etc.,
For the above case, the spreadsheet looks as follows:

While running the tests, to retrieve data, you can use the utility method,
datatable().item(field, category)
Your script to create an employee could then look like:
all_data=["first_emp", "new_emp", "young_dude", "elderly_sir"]
all_data.each do |dt|
Browser(...).TextField("name:=empId").set datatable().item("id", dt)
Browser(...).TextField("name:=fname").set datatable().item("fname", dt)
..
..
end
Clearly the above utility provides a very simple yet organized way of testing the same scenario using multiple data.
Instead of using an Excel sheet, you could also use an xml syntax. The XML schema for the datatable is:
If the Datatable is in an XML Format, then an example is :
<data>
<category name='general'>
<Item name="firstname" value="Me" />
<Item name="lastname" value="Exists" />
<Item name="employeeid" value="001" />
<Item name="age" value="34" />
</category>
<category name='boundary'>
<Item name="firstname" value="New" />
<Item name="lastname" value="Girl" />
<Item name="employeeid" value="100" />
<Item name="age" value="26" />
</category>
<!-- You can have many more categories here -->
</data>
The API Guide for using the Datatable is at:
http://wet.qantom.org/api_reference/classes/DataTable.html