Run your own JavaScript in a web test

Run your own JavaScript in a web test when no built-in step fits: an uncovered flow, a computed value, a custom metric sent to Analytics.

Run your own JavaScript inside the test: handle a flow no built-in step covers, compute a value, or push a custom metric to Analytics. The script runs in the test's browser session with the full WebdriverIO API available.

Parameters

ParameterRequiredDescription
Step titleNoThe name shown for this step in the builder and in results.
ScriptYesJavaScript code, edited in a dedicated modal.
Ignore error on this stepNoThe run continues with the next step if the script throws. Default: off.

Inside the script you can use the WebdriverIO browser object to drive the session, and the test helpers, for example:

// Push a custom metric to Analytics
test.metrics.create("checkout", { basket_total: 39.98 }, { currency: "EUR" });

Results and metrics

  • Timing: start, end, and duration (in seconds) recorded in the step result.
  • Status: failed if the script throws, success otherwise.
  • Output: anything the script logs is available in the step's output for debugging.
  • Custom metrics: metrics created with test.metrics.create(measurement, fields, tags) flow to Analytics like any built-in metric.

What's next?

Set variable

Store a value without writing code

Analytics

Where custom metrics show up

Last updated on