-
Notifications
You must be signed in to change notification settings - Fork 104
JSON Format
The Selenium 2 script format is intended to bridge between the strict list of steps in Selenium 1 and the Selenium 2 API. Selenium 2 script files are JSON files composed of a list of steps, such as "get" or "clickElement" which have named parameters. Here is a simple example:
{
"seleniumVersion": "2",
"formatVersion": 1,
"steps": [
{
"type": "get",
"url": "http://www.sebuilder.com/"
},
{
"type": "verifyTextPresent",
"text": "Open Source Software"
}
]
}
The list of available commands and their parameters is still amenable to change. The most up to date list is currently available from here in the code or from the Selenium 2 Step Support Table within Se Builder.
Locators are used in Selenium 1 and 2 to describe how to find a particular DOM element - a link to click, for example. Locators are represented as JSON objects that contain a type and a value. Example:
{
"seleniumVersion": "2",
"formatVersion": 1,
"steps": [
{
"type": "get",
"url": "http://www.sebuilder.com/"
},
{
"type": "clickElement",
"locator": {
"type": "link text",
"value": "Apache 2 License"
}
}
]
}
The available locator types are:
- id
- name
- link text
- css selector
- xpath
Assertion, verification and wait steps can also be negated, inverting their condition. For example, this script checks that the words "Closed Source Software" do not appear on sebuilder.com:
{
"seleniumVersion": "2",
"formatVersion": 1,
"steps": [
{
"type": "get",
"url": "http://www.sebuilder.com/"
},
{
"type": "verifyTextPresent",
"negated": true,
"text": "Closed Source Software"
}
]
}
Values stored in variable using the store_X_ commands can be referenced in parameters using the syntax ${varname}
. For example, the following script checks that the page's title appears in the page itself:
{
"seleniumVersion": "2",
"formatVersion": 1,
"steps": [
{
"type": "get",
"url": "http://www.sebuilder.com/"
},
{
"type": "storeTitle",
"variable": "title"
},
{
"type": "assertTextPresent",
"text": "${title}"
}
]
}
For future compatibility, the seleniumVersion field is intended to signal which major incompatible version of Selenium the file describes. The formatVersion field likewise signals major incompatible versions. Software that can read version X should be backwards-compatible with earlier versions as much as possible.