Parameterization
Parameterization is a key feature in automation testing. It is possible to give test data (parameter) as input in Selenium IDE as it is with any other automation tool. Selenium IDE requires configuration before proceeding for parameterization, which is explained in the following section.
After configuring Selenium IDE for parameterization, in the following example, we will search a text on Google and verify the text appears on the page. The storeEval
command will read the search data from the google_search.js
file and save it in the searchDataValue
variable. With this variable, data types on the Google search page, verify Download Selenium IDE text using the assertTextPresent
command. In this way, you can achieve data parameterization or data-driven testing by passing external data to a variable in Selenium IDE.
Selenium IDE Configuration
You need to create JavaScript file as the data source file. These are the steps to create JavaScript file and configure Selenium IDE:
- In a Notepad, create input data as follows:
searchData = 'Selenium IDE'
- Save it as a file, say for example,
google_search.js
. - Open Selenium IDE and choose the Option | Options… menu.
- Under Selenium IDE Extensions, browse the saved
google_search.js
file. After attaching the data file, your Selenium IDE option window will look like the following screenshot. Then, click OK and restart the Selenium IDE: - Now, record the script to perform Google search and verify the page element and update the commands as shown in the following screenshot. Then, execute the test. You can also use the
WaitForElementPresent
command till the page element is loaded and verify instead of thepause
command.
In this example, we are searching a text on the Google page and verifying the text appearing on the page. The storeEval
command will read the search data from the google_search.js
file and store it in a searchDataValue
variable and verify the Download Selenium IDE text using an assertTextPresent
command. In this way, you can achieve data parameterization or data-driven testing in Selenium IDE.
Generating source code from Selenium IDE
The Selenium IDE formatters plugin enables you to export the recorded steps. Selenium IDE can export the recorded steps or user actions to different formats. The Selenium team provides bindings for several programming languages. You can write a script in one of these programming languages and use the provided libraries to remotely control a browser. Selenium IDE formatters convert the recorded actions into source code for a specific programming language.
You need to set enable experimental features on Selenium IDE options to view the formatters. Check out the following screenshot for formatters:
Record user actions on Selenium IDE, and to view specific programming language formatters, select the Selenium IDE | Options | Format as shown in the following screenshot. A confirmation dialog appears, click on OK:
Ensure that the code is displayed under the Selenium IDE Source tab as seen in the screenshot that follows. You can also see the Java/Junit4/WebDriver programming language formatter. Selenium IDE used the type command to identify text typing into the textbox. In the source code, the sendkeys
command is used in order to type text into the textbox using the Selenium Java/Junit4/WebDriver programming language. You can generate a formatter of any of the specific programming languages. After viewing the source code, you can switch back from a specific formatter to HTML. If a formatter is not HTML, then recording options will not work and the
Table tab will not be active:
In the preceding recorded action, we searched a text on Google and verified the text appears on the page. Selenium IDE exports these actions to view a specific programming language. This is one of the useful features of Selenium IDE; it provides an option to set the clipboard format. You can copy commands from the Table tab and paste in the format of that specific programming language.