Skip to main content
Javascript steps run custom JavaScript during your test. Use them for custom DOM manipulation, data setup, and checks the built-in steps don’t cover.
To pass a value to later steps, return it and start the step’s Add a Description field with save:<name>, for example save:orderId. In a later step, type { and select the variable. A step without return still runs, but it saves no value.
1

Add a JavaScript action

Begin by typing // to open the Javascript interface.
2

Write your JavaScript code

Write custom Javascript code, with support for synchronous and asynchronous functions, as well as multi-line Javascript code. Then describe the code in the required Add a Description field.
3

Execute code and view results

After executing your JavaScript code, you can view the output of your JavaScript execution, any returned values from your code, and execution status and completion information.

JavaScript code examples

Here are some common examples of JavaScript actions:

Best practices

  1. Keep your JavaScript code focused and specific to the task
  2. Use async/await for asynchronous operations
  3. Handle potential errors with try/catch blocks
  4. Add comments to explain complex logic
  5. Test your JavaScript code thoroughly before adding it to your test suite

Important notes

  • JavaScript actions run in the context of the current page
  • You have access to the full browser JavaScript API
  • Returned values show in the step’s result. Spur saves a value for later steps only when the description starts with save:<name>
  • Multi-line code is supported
  • Both synchronous and asynchronous functions can be used