Global test action arguments


Global arguments can be used to control how an action is executed and trigger additional behaviors, as described in the sections below. Global test action arguments can be passed to any test action, whether it is part of the OpenTest core distribution or is implemented in a plugin. They are easy to spot, since their names start with the $ sign, same as other symbols defined by OpenTest itself (as opposed to user-defined ones).

$checkpoint

When a test step fails, the normal behavior is that the test is marked as failed and execution is immediately stopped. When assigned a value of true, the $checkpoint argument marks a test step as checkpoint, meaning that, in case the step fails, the test will still be marked as failed, but will continue executing to the end as if no failure occurred. This means the test can do more verifications in one go, minimizing execution time and conserving computing resources. For more information see the Checkpoints page.

Example:

# This verifies the element's visibility,
# but doesn't fail the test right away
# when this step fails

- description: Verify query box visibility
  action: org.getopentest.selenium.AssertElementVisible
  args:
    locator: { name: q }
    $checkpoint: true

$if

Determines whether a test action will execute or be skipped. The value of this argument must be a JavaScript expression that evaluates to a boolean. The action will be executed if the expression evaluates to true, and will be skipped if the expression evaluates to false.

Example:

# Will only execute before 10 am. Will be
# skipped if the test runs later in the day

- description: Click the "Good morning" button
  action: org.getopentest.selenium.Click
  args:
    locator: { id: good-morning }
    $if: $script (new Date()).getHours() < 10

$optional

When assigned a value of true, it marks a test step as non-critical for the success of the test and avoids failing the test if this step fails. Both optional actions and checkpoints allow the test execution to continue after the action fails. The difference is that optional actions will not mark the test as failed, meaning that the test can potentially pass (provided that nothing else fails).

Example:

# When this action fails, the test will continue and
# will not be considered failed

- description: Sample action
  action: org.getopentest.actions.SampleAction
  args:
    $optional: true

$screenshot

When assigned a value of true, it instructs a test action to take a screenshot after it executes.

Example:

- description: Click product 1 and capture a screenshot
  action: org.getopentest.selenium.Click
  args:
    locator: { id: product1 }
    $screenshot: true

$localData

Populating the $localData argument writes data in the local data store. The local data store is an object (a Java Map) that can be used to easily store and retrieve pieces of data that need to be shared between multiple test steps. For more information see this page.

Example:

- description: |
    Read the username and write it to the "username" local
    data property
  action: org.getopentest.selenium.ReadElementText
  args:
      locator: {css: p.username}
      $localData:
        username: $output.text

$sharedData

Populating the $sharedData argument writes data in the shared data store. The shared data store is persisted at the OpenTest server and can be used to easily store and retrieve pieces of data that need to be shared between multiple test actors that are part of a distributed test. For more information see this page.

Example:

- description: |
    Read the username and write it to the "username" shared
    data property
  action: org.getopentest.selenium.ReadElementText
  args:
    locator: {css: p.username}
    $sharedData:
        username: $output.text

$sessionData

Populating the $sessionData argument writes data in the session data store, as described here.

- description: |
    Read the username and write it to the "username" session
    data property
  action: org.getopentest.selenium.ReadElementText
  args:
    locator: {css: p.username}
    $sessionData:
        username: $output.text