Skip to content

Data driven Testing

David Stark edited this page Mar 3, 2014 · 2 revisions

In Builder, you can play back tests on the basis of rows of data. Each row of data is a test run. The data values are put into playback variables, so for example, the script

print ${varname}

with data rows of

varname
-------
foo
bar
baz

will run the script three times, printing foo, bar and baz.

You can set up a script for data-driven playback through the Data menu in Builder. With Selenium 2, the data-driving settings are saved in the script JSON file.

Tool Support

Support for this new feature in the Java and node interpreters is currently in the works.

Data Sources

The following data sources are currently supported:

None

The default. Equivalent to a single row with zero columns.

Manual

A single data row stored directly in the script. Useful for testing.

JSON

The data is stored in a JSON file, the path to which is stored in the script. The JSON structure is an array of objects, one per row. For example:

[
  { "varname": "foo" },
  { "varname": "bar" },
  { "varname": "baz" }
]

XML

The data is stored in an XML file using the same format as data-driven playback in Selenium IDE. For example:

<testdata>
  <test varname="foo" />
  <test varname="bar" />
  <test varname="baz" />
</testdata>

JSON Format Details

The addition of this feature raises the version number of saved Selenium 2 JSON files to 2. Here is an example exported script:

{
  "type": "script",
  "seleniumVersion": "2",
  "formatVersion": 2,
  "steps": [
    {
      "type": "print",
      "text": "${varname}"
    }
  ],
  "data": {
    "configs": {
      "json": {
        "path": "/Users/zar/Desktop/mydata.json"
      }
    },
    "source": "json"
  },
  "inputs": []
}