Data Driven tests
Parameterization is a part of the Data Driven technique for retrieving values from an external data source as input. In general, the Data Driven tests are used to verify the actual and expected values from an external data source. The Selenium IDE plays a major role in parameterization, as it operates with different sets of permutations and combinations. Let's see how we can use a JavaScript file as a data source for Data Driven tests. The following is the JavaScript syntax for parameterization:
varname = "value"
For example, create a JavaScript (.js
) file (Datasource.js
) that includes the following keywords:
Search1 = "PrashanthSams" Search2 = "Selenium Essentials"
Launch the Selenium IDE and choose Options… from the Option menu, Option | Options.... Now, browse through Selenium IDE extensions and select the .js
file created earlier (Datasource.js
), as shown in the following screenshot:
Finally, restart the Selenium IDE to effect the changes. Initialize, store, and fetch values from the .js
file one by one using the storeEval
command, as follows:
Here, Search1
and Search2
are the two variables that retrieve the respective keywords from the JavaScript file. These values are again stored in the new variables, GoogleSearch1
and GoogleSearch2
, as shown in the preceding screenshot.
User-defined JavaScript methods
The IDE actions, accessors, and assertions can be user-defined and customized. To achieve this, the user is supposed to add JavaScript methods to the Selenium object prototype and the PageBot object prototype. In general, the Selenium IDE verifies the user-defined JavaScript methods on launching the IDE. Selenium Core extensions (user-extensions.js
) in Options... give support to upload the user-defined JavaScript files.
Let's discuss this with an example that involves step-by-step instructions, as follows:
- Refer to the Google site https://sites.google.com/site/seleniumworks/selenium-ide-data-driven to download the following JavaScript files:
datadriven.js
goto_sel_ide.js
user-extensions.js
- Launch the Selenium IDE and choose Options… from the Option menu, Option | Options.... Now, navigate to Selenium Core extensions and upload the JavaScript files (
user-extensions.js
,goto_sel_ide.js
anddatadriven.js
), as shown in the following screenshot. Finally, restart the Selenium IDE for the changes to take effect. - In the Selenium IDE, the XML file is used as a data source to store values, whereas
Datadriven.js
is designed to support the XML file format.Here is the syntax for XML file formatted data source:
<testdata> <test varname="value" /> <test varname="value" /> <test varname="value" /> </testdata>
Create an XML file with the extension
.xml
(data.xml
). Here,varname
is the variable name, andvalue
refers to the keyword under the<test>
tag. Let's create an XML file with the.xml
extension (data.xml
). For example, refer to the following code snippet:<testdata> <test phrase="selenium essentials" /> <test phrase="seleniumworks.com" /> <test phrase="prashanthsams" /> </testdata>
- Take a look at these details:
loadTestData
is a user-defined command that fetches the XML data source,while
andendWhile
do looping, whereasnextTestData
checks for the data from the next row in the data source. The user can add any number of JavaScript methods. The following screenshot shows this step in detail: