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.
Write a few lines of code when the built-in steps can't do what you need. You edit the script in a dedicated modal, and it runs in the test's own browser session, on the page where the previous steps left off.
Parameters
| Parameter | Required | Description |
|---|---|---|
| Step title | No | The name shown for this step in the builder and in results. |
| Script | Yes | JavaScript code, edited in a dedicated modal. |
| Ignore error on this step | No | The run continues with the next step if the script throws. Default: off. |
Inside the script, drive the browser with the browser object. The script has the full WebdriverIO API (the browser automation library behind it), so look up the syntax in the WebdriverIO documentation. The test helpers cover the rest, for example sending a metric to Analytics:
// 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?
Last updated on