Arrays is a data structure that is using in many programming languages to implementing and manipulating sets of similar type data. In Selenium IDE, Array can be used to enter a sets of data one by one in an input field or clicking on different link or button to repeat the same task.
Here we will explain how it can be performed.
Step 1 : We have a sample task on Selenium page. We want to visit different tabs on selenium page, Tabs are : Project, Download, documentation, Support, About.
I want to make a data structure where I store the tab name in the array and IDE script will read the tab name from Array and execute the click command according to it. Note that we will also implement while loop here.
Array will be,
Step 2 : In order to traversing the Array we need a loop command. In that case we will use while loop but “while” command is not a built in command in selenium IDE. We have to download the user extensions from the following location.
After downloading the user-extension.js file we need to attach it to Selenium IDE.
- Go to Options>Options…
- Options window will be displayed and go to General tab.
- Locate the user-extension.js file and click on OK button.
Step 3 : Write the following Selenium command and that will be,
Here we use the storeEval and getEval command.
storeEval : Execute the Java script command and return the value and assign the value Value column.
getEval : Execute the Java script command but does not do any return.
Line 1: Open the application with the base URL : http://www.seleniumhq.org/
Line 2 : Define the array
|storeEval||new Array("Projects", "Download", "Documentation","Support","About")||tabNameArray|
Line 3 : Define a variable.
Line 4 : Write while command and condition.
Note that we use storedVars['tabNameArray'] here to return the array reference.
Line 5 : Store tabItems to TabN
Line 6 : Return the tab name from tabNameArray and store it to tabName.
So, tabNameArray =”Projects”
and so on….
Line 7 : Print the tab name.
Line 8 : Click on the tab by Link name.
Line 9 : Increase the value for tabItems to 1.
Line 10 : End of the while loop.
Step 4 : Run the script.
In this way we can also store user data to an array and use those array data as input of the application. So driven testing can also be performed in this way. Thanks…
Happy Selenium IDE scripting with Array…