Execute Javascript

Command value: eval

Runs JavaScript in the page without asserting on the result.

Fields

FieldJSON propertyDescription
JavaScript CodevalueCode that runs in the page. Use return to send a value back.

Usage

  • Use it to scroll, clear storage or set up state that has no UI control.
  • The step fails only if the code throws an error. To fail the test on a condition, use JavaScript returns true instead.

Example step (JSON)

{
  "command": "eval",
  "value": "window.localStorage.clear();"
}

Playwright equivalent

await page.evaluate(() => { window.localStorage.clear(); });

Common options

  • Make this step optional (Continue on failure): when checked, a failure in this step is recorded and the test continues with the next step.
  • Execute step when JavaScript returns true: runs the step only when the JavaScript condition returns true. Otherwise the step is skipped.

See conditional steps and variables for details.