Store Variable
Use cases where store variable can be used
When we need to generate a random email address/name/variable for a signup form, then wish to assert that email address later on.
Extract the contents value of an element(static or Dynamically generated) and store it in a variable for use in later steps
If you want to store the value generated in javascript
In CloudQA, using Store Variable you can store a value and use it anywhere in the text case.
1. Store variable from an element
2. Store variable from Javascript
1. Store variable from an element
Add a step name called Store Variable, choose option from an element, provide a value using CSS selector you want to store and give a unique name(eg: ordernumber)
The store variable can be used directly in a step or script or asserted script
Usage in a step:
Declared store variable can be used in the same test case. Name of a store variable has to be replaced by values for type fields like textboxes, password, assertions.(Eg:
__ordernumber__
){% video width="650" %}https://cquserfiles.s3.amazonaws.com/3161/3a135d22086c413aa0309942f360740b/StoreVariable.mp4{% endvideo %}
Usage of store variable in script and assertion
To use the variable stored, in script use syntax
window.cloudqa.variablename
in above case it will be window.cloudqa.ordernumberAssertion: Change the assertion type to the script and write a script that returns a value true below code shows an example of how to write the script.
return (function validate() {
try {
//your code and return true if your validation check
return true;
} catch {
return false;
}
})();
2. Store variable from Javascript
Add a step Store Variable, choose option from Javascript, add the javascript along with the return statement.
This returns a value from custom JavaScript and stores it in a variable for use in later steps
Use the variable (Eg:
__date__
) in later part of test caseBelow is the sample JavaScript Date functions to generate current date in DD-MM-YYYY format and store the custom date string to use it in later part of test case
NOTE:
- Store variable names cannot be duplicate.
- Store variables have to be declared before using them.
- No spaces are allowed in the name