Using the rollup feature of Selenium

Recently someone had put forward a doubt on the usage of rollup feature in Selenium.

Rollup, in Selenium,  is a series of commands with a unique name, and optionally arguments that control the generation of the set of commands. If any one of the rolled-up commands fails, the rollup is considered to have failed. Rollups may also contain nested rollups.

Consider, I want to do below operations in a web browser –

     (a) Login to “http://www.mail.com” URL.
     (b) Type Email
     (c) Type Password
     (d) Click on “Log in”

Logically if you see, all the above 4 different activities are serving  to a single use-case – “do_login”.

Any activity (reading mail, deleting mail, sending mail etc) will need you to first login to your mailbox. So, instead of duplicating the code for “login”  across all your testcases (e.g. reading mail testcase, sending mail testcase, delete mail testcase), you can write only once the testcase code for login and then wrap-up this testcase with a name and call this code with it’s wrapped-up name across all your testcases which needs login to the mailbox as a pre-requisite. This is where the “rollup” feature of Selenium comes into picture.

Have a look at the user-extensions.js (below). You can think of this file as a re-usable library wherein I’ve defined the actual action steps i.e. logging in, typing username, typing password and signing in. I’ve then wrapped up all these actions under “do_login” rollup rule.
I haven’t hardcoded the username and password here as I wanted to read these from the testcase.
var manager = new RollupManager();

manager.addRollupRule({
 name: 'do_login'
 , description: 'log in to mail.com'
 , args: [
 {
 name: 'username'
 , description: 'username'
 }
 , {
 name: 'password'
 , description: 'password'
 }
 ], commandMatchers: [
 ]
 , getExpandedCommands: function(args) {
 var commands = [];

commands.push({
 command: 'open'
 , target: ''
 });
 commands.push({
 command: 'type'
 , target: 'login'
 , value: args.username
 });
 commands.push({
 command: 'type'
 , target: 'password'
 , value: args.password
 });
 commands.push({
 command: 'click'
 , target: 'btnLogin'
 });
 return commands;
 }
});
Now have a look at my actual testcase “rollupExample.html” (below). If you notice, here I’m just calling the rollup rule i.e. “do_login”. Along with it I’m passing the required username and password (sanjit/sanjit). Just a single line of code in my testcase and it takes care of all the login functionality!!!
Now, all you need to do is to make the Selenium core aware of your new user-extensions javascript file and then import the testcase to your selenium IDE and run. Thats all!

Published by

Sanjit ...

Engineering Manager, Broadcom | Views expressed on my blogs are solely mine; not that of present/past employers | Support my work @https://ko-fi.com/sanjitmohanty

3 thoughts on “Using the rollup feature of Selenium”

  1. What if i wan’t to run my test case on selenium server? i can’t seem to get roll ups to work on the server, probably because the server can’t find, don’t know how to located the .js files i specify in the options of the ide.. any ideas?

    Like

  2. Can i use multiple rollup.js in selenium IDE like one for login, one for delete. I tried uploading two rollup.js in user-extensions. but only rollup is identified basically the last one. How can i use multiple rollup.js in selenium IDE?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.