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.
Store a value from an element
Section titled “Store a value from an element”- Add a Store Variable step and choose the element option.
- Enter the element’s CSS selector.
- Give the variable a unique name.
Store a value from JavaScript
Section titled “Store a value from JavaScript”- Add a Store Variable step and choose the JavaScript option.
- Write a script that ends with a
returnstatement. 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()}`;Use a stored variable
Section titled “Use a stored variable”- 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 returntruewhen the check passes.
- Variable names must be unique and can’t contain spaces.
- Declare a variable before you use it.
Related pages
Section titled “Related pages”- Application variables, for values shared across tests
- Assertions