JSON Format

Zarkonnen edited this page Apr 13, 2012 · 9 revisions

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

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

Negation

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"
    }
  ]
}

Variables

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}"
    }
  ]
}

Versioning Policy

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.