Skip to content

Store variable

Store Variable saves a value so you can use it again later in the same test case.

Common uses:

  • Generate a random email address or name for a signup form, then assert it later.
  • Capture the text of an element, whether static or dynamically generated, for use in later steps.
  • Save a value produced by JavaScript.
  1. Add a Store Variable step and choose the element option.
  2. Enter the element’s CSS selector.
  3. Give the variable a unique name.
  1. Add a Store Variable step and choose the JavaScript option.
  2. Write a script that ends with a return statement. The returned value is stored for later steps.

For example, this script stores today’s date in DD-MM-YYYY format:

const d = new Date();
const pad = (n) => String(n).padStart(2, '0');
return `${pad(d.getDate())}-${pad(d.getMonth() + 1)}-${d.getFullYear()}`;
  • In a step or assertion field, such as a text box or password field, wrap the name in double underscores: __variablename__.
  • In a script or script assertion, read it as window.cloudqa.variablename. In a script assertion, change the assertion type to Script and return true when the check passes.
  • Variable names must be unique and can’t contain spaces.
  • Declare a variable before you use it.