Galactic Civilizations 3
Read xml in Selenium and create parameterized test scripts

Read xml in Selenium and create parameterized test scripts

Category: Javascript.
Posted by on the 07/05/2014.
Last update on the 07/05/2014.

<<Previous tutorial    Next tutorial>>

Description

This tutorial explains how to read xml in Selenium and create parameterized test scripts.

Introduction

This tutorial requires that Selenium IDE is installed. It also requires that the plugin SelBlocks is installed. This tutorial has been done with Firefox. This tutorial can be realized with a simple text editor like « Notepad ».

Write the XML

In order to parameterize the Selenium script with a XML file, you need to use the following structure:

<testdata>
    <vars NAMEVAR1="VAL1" NAMEVAR2="VAL1" />
    <vars NAMEVAR1="VAL2" NAMEVAR2="VAL2" />
</testdata>

For this tutorial, we will use the following XML:

<testdata>
    <vars pageName="Page accueil" url="http://www.tutorielsenfolie.com/" />
    <vars pageName="Plan du site" url="http://www.tutorielsenfolie.com/siteMap.html" />
</testdata>

We will name our xml file: myXML.xml

Read the XML

For using the data of our XML file, we need to use the « forXml » and « endForXml » commands.

The « forXml » command allows us to iterate on each « vars » element of the XML file. The attributes of the « vars » elements will be manipulated as Selenium variables.

For examples:
${pageName} to retrieve the page name of our XML file or ${url} for the page url.

Here is an example with our XML file:

forXml | myXML.xml
echo |${pageName}
echo |${url}
endForXml

Selenium script to read xml

This script will display the value of the variables pageName and url in the logs thanks to the echo command.

Result of a Selenium script that read an XML

You like this tutorial ?
Like this website in order to promote it on facebook !

<<Previous tutorial    Next tutorial>>

You like this tutorial ? Share it with your friends !
Partager sur Facebook Partager sur Twitter Partager sur Myspace Partager sur Stumbleupon Soumettre sur Reddit Partager sur Digg Ajouter à vos favoris Technorati Ajouter à vos favoris Live Ajouter à vos favoris Google Ajouter sur vos favoris Yahoo