The Selenium IDE Firefox plugin can handle javascript in targets. For larger projects the options also allow inclusion of javascript files. Simply set a .js file (by it’s full path) in the “Selenium Core Extensions”. Multiple .js files can be added, separated by a comma.

A common task in selenium tests is the inclusion of dummy form data. Create a javascript file called data.js and enter:


function getRandomAge() {
   return Math.floor(Math.random()*111);
}

Add as user extension. Remember to reload Selenium each time the .js file changes. Use the available javascript functions in the test:

command: store
target: javascript{getRandomAge()}
value: random
command: type
target: //input[@name='age']
value: ${random}

Chance.js is a javascript library especially designed to generate random data. In order to use it in a Selenium test make sure it is loaded before the data.js file. The data.js file is also the place to instantiate the chance class:


var chance = new Chance();

then deploy in test:

command: store
target: javascript{change.age({min: 18, max: 65})}
value: random
command: type
target: //input[@name='age']
value: ${random}

Sideflow.js is a flow control extension for Selenium IDE. It allows the creation of loops in a test. Add sideflow.js as an "Selenium Core Extensions" and deploy in a test:

command: store
target: 1
value: i
command: while
target: ${i} < 11
value:
command: storeEval
target: eval(${i} + 1)
value: i
command: echo
target: ${i}
value:
command: endWhile
target:
value:

Advertisements