Selenium IDE Rollups With StoredVars Logic
Creating rollups in Selenium IDE with execution logic based on storedVars can be tricky. Storing the value of an element or its presence within the rollup command list and using if or other logic blocks via the various “flow” add ins will not work as you expect. Nor will storing the values and then using JavaScript logic within your rollup. Getting storedVars working in a rollup is a special kind of black magic.
Here are my methods that are working for me with my home-grown “Go With The Flow” add-in I brewed based on similar control flow plugins.
Set Vars In A Separate Rollup
I find that setting my variables in a separate rollup is a simple solution. This ensures your variable stack exists and is set using standard Selenium IDE commands. My example for testing if I am already logged in before prompting for user and password data and running the login:
/** * Set My Vars */ manager.addRollupRule({ name: 'set_my_vars', description: 'Set variables we might care about.', commandMatchers: [], getExpandedCommands: function(args) { var commands = []; commands.push({ command: 'setTimeout' , target: '10506' , value: '' }); commands.push({ command: 'setSpeed' , target: '0' , value: '' }); commands.push({ command: 'storeElementPresent' , target: 'id=colophon' , value: 'not_logged_in' }); return commands; } });
Use JavaScript Logic
Once your variables are set they are standard JavaScript variables that will be available throughout your rollups. You can use this fact to build standard JavaScript logic in your rollup and decide what commands the rollup will push on the stack during each execution. In your Selenium IDE command list you can then change storedVars using various store commands and then call the rollup afterwards; in essence changing what commands are executed “on the fly”.
You’ll notice that I also do a quick check at the top to ensure the set_my_vars rollup was already run by checking that the storedVars key I need is set. If not it echos a message to the Selenium IDE log console and skips doing anything else.
/** * Super Admin Login */ manager.addRollupRule({ name: 'sa_login', description: 'Super Admin Login must run rollup set_my_vars first.', commandMatchers: [], getExpandedCommands: function(args) { var commands = []; if (typeof storedVars[ 'not_logged_in' ] === 'undefined') { commands.push({ command: 'echo', target: "run rollup set_my_vars before running this rollup" , value: '' }); return commands; } if ( storedVars[ 'not_logged_in' ] ) { commands.push({ command: 'open' , target: '/' , value: '' }); commands.push({ command: 'storeEval' , target: "prompt('Dashboard Admin Login' , 'me@storelocatorplus.com')" , value: 'sa_user' }); commands.push({ command: 'storeEval' , target: "prompt('Password' , 'Jeny8675309' )" , value: 'sa_pwd' }); commands.push({ command: 'type' , target: 'id=email' , value: '${sa_user}' }); commands.push({ command: 'type' , target: 'id=login-password' , value: '${sa_pwd}' }); commands.push({ command: 'clickAndWait' , target: 'css=input[type="submit"]' , value: '' }); commands.push({ command: 'waitForElementPresent', target: 'id=footer-thankyou' , value: '' }); } else { commands.push({ command: 'echo', target: "already logged in ( not_logged_in : " + storedVars[ 'not_logged_in' ] + " )" , value: '' }); } return commands; } });
Hopefully these tricks will help you with your Selenium IDE rollup builds. Some things to keep in mind is that things like Selenium labels or endif markers do not exist within the rollup itself if you are creating them in the rollup. Same concept with storedVars, the storedVars[<key>] will not exists and be available to your rollup JavaScript logic if you create the var inside the rollup itself. When a rollup that creates a storedVars entry is complete it is then available for any future commands, including rollups.
Hi Lance, for the testing of our SAAS product I have managed to circumvent the “the storedVars[] will not exists and be available to your rollup JavaScript logic if you create the var inside the rollup itself” issue by using another rollup (within the rollup) to use the vars created in the first rollup. That is to say, my rollup calls a rollup, which uses the storedVars created in the first rollup. Confused? In fact with a bit of tweaking one rollup can call itself – effectively meaning this issue disappears 😉