This post helps us understand how to declare, initialize and re-use variables in Selenium IDE.
store command
Helps in declaring and assigning a value to a variable.
ex:
Command: store
Target: 1000
Value: a
This will create a variable ‘a’ and assign 1000 as its value.
echo command
Helps in printing a value to the log. It can be a character, string, number or value of a variable.
To print value of a variable ,
Command: echo
Target: ${Variable Name}
ex:
command: echo
Target: ${a}
This will print value of variable ‘a’ that is 1000 to the log.
Note:
* If you simply give 'a' in the target instead of '${a}' then this is treated as a string/Character and 'a' is printed to log but not its value.
*All the variables declared in a test are stored into an array called "storedVars". In order to refer value of variable inside storedVars array, you can call Target: javascript{storedVars['a']}
*command: echo
Target: ${a}
is same as,
command: echo
Target: javascript{storedVars['a']}
*Command: echo
Target: storedVars['a']
this will print string "storedVars['a']" to the log but not value of ‘a’.
Assigning value of a Variable to another variable
Command: store
Target: ${a}
value: b
or,
Command: store
Target: javascript{storedVars['a']}
value: b
In both the examples mentioned above, value of 'a' is assigned to variable 'b'.
storeEval command
Using storeEval command you can directly assign or print value of a variables without help of 'javascript{}' in the target.
Ex:
Command: storeEval
Target: storedVars['a']
value: c
Observe that in the above example we are directly calling storedVars['a'] to assign value of variable ‘a’ to ‘c’.
How to add value 10 to variable ‘a’ and assigning it to variable ‘d’ ?
Command: storeEval
Target: storedVars['a']+10
value: d
Now if you try to print value of ‘d’ using echo command, then it will print string "1000+10" but not "1010". This is because the return value of storedVars['a'] in the target is being treated as a string. In order to avoid this, we need to type caste it to a number as follows,
Command: storeEval
Target: new Number(storedVars['a'])+10
Value: d
Now that we discussed all that mentioned above, create a test case to practice them (refer snapshot below)
store command
Helps in declaring and assigning a value to a variable.
ex:
Command: store
Target: 1000
Value: a
This will create a variable ‘a’ and assign 1000 as its value.
echo command
Helps in printing a value to the log. It can be a character, string, number or value of a variable.
To print value of a variable ,
Command: echo
Target: ${Variable Name}
ex:
command: echo
Target: ${a}
This will print value of variable ‘a’ that is 1000 to the log.
Note:
* If you simply give 'a' in the target instead of '${a}' then this is treated as a string/Character and 'a' is printed to log but not its value.
*All the variables declared in a test are stored into an array called "storedVars". In order to refer value of variable inside storedVars array, you can call Target: javascript{storedVars['a']}
*command: echo
Target: ${a}
is same as,
command: echo
Target: javascript{storedVars['a']}
*Command: echo
Target: storedVars['a']
this will print string "storedVars['a']" to the log but not value of ‘a’.
Assigning value of a Variable to another variable
Command: store
Target: ${a}
value: b
or,
Command: store
Target: javascript{storedVars['a']}
value: b
In both the examples mentioned above, value of 'a' is assigned to variable 'b'.
storeEval command
Using storeEval command you can directly assign or print value of a variables without help of 'javascript{}' in the target.
Ex:
Command: storeEval
Target: storedVars['a']
value: c
Observe that in the above example we are directly calling storedVars['a'] to assign value of variable ‘a’ to ‘c’.
How to add value 10 to variable ‘a’ and assigning it to variable ‘d’ ?
Command: storeEval
Target: storedVars['a']+10
value: d
Now if you try to print value of ‘d’ using echo command, then it will print string "1000+10" but not "1010". This is because the return value of storedVars['a'] in the target is being treated as a string. In order to avoid this, we need to type caste it to a number as follows,
Command: storeEval
Target: new Number(storedVars['a'])+10
Value: d
Now that we discussed all that mentioned above, create a test case to practice them (refer snapshot below)
Great article... thanks
ReplyDelete