3.11.1.Convert to DDT Refactoring
Open the test case and open the Create Data Driven Test dialog by using «Refactor» ? «Create DDT...» command or
toolbar button .
We will start with an example (recorded using SwingSet3 application):
#### Original Code
assert_p("tfHistory", "Text", "John")
From the script we will extract string "John" using Create Data Driven Test dialog, as show below.
Select a line in
Script Selection section from which you have to extract. All the Constants, which can be extracted
will be shown in table-view
Constants. You have to select corresponding checkbox(es) of the value column(s)
to extract as
parameter(s). You can also edit the name of the parameter in
Extract with name column by double clicking on it.
All the extracted parameters are listed on
Module Parameters section. Once extraction is done, press
Convert button, it prompts for a file name to save it with. It create a CSV file with data(s) and save it in TestData
#### Converted Code
assert_p("tfHistory", "Text", $name)
The extract refactoring adds the call to
use_data_file in the header. The file is expected to be in TestData
folder. Note the
$ prefix to variable names. These are global in nature.
Executing Data Driven Tests
There are mutiple ways of executing Data Driven Test. You can run the tests in regular way from Marathon as well as command line. Click on the play button to run
the test. Observe that the test runs once for the data row.
We can add more data to the CSV file. Edit the CSV file using
CSV Editorand add few more rows. To open
CSV Editor, doulbe click on a CSV file which is under TestData folder.
Select a row from the table-view and copy the row using button . Then edit columns to add data. The first column i.e marathontestname is appended
to the test script name to create individual test names. Select a row and click button to remove data from file.