Data Driven Testing with Selenium IDE

Selenium IDE does not have in-built features to create data-driven tests. However there are multiple options available in the form of Selenium IDE User Extension or Add-On for creating Data Driven tests.

This post will explore using a Selenium IDE Add-on called Sel Blocks to create Data Driven tests on a sample BMI Calculator application. This is a simplest option available for Selenium IDE for data-driven tests.

The Sel Blocks Add-on provides various flow control elements such as conditional handling, looping, variables and data-driven testing in Selenium IDE tests.

Setup
Install the Sel Blocks for Selenium IDE Add-On using the Add-On Manager in Firefox from https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-sel-blocks/?src=search

Creating Data Driven Tests
First we need to identify test data for the script. The Sel Blocks Add-on needs the test data in XML format. Create a XML file with following format:

<testdata>
	<vars height="160" weight="45" bmi="17.6" bmi_category="Underweight" />
	<vars height="168" weight="70" bmi="24.8" bmi_category="Normal" />
	<vars height="181" weight="89" bmi="27.2" bmi_category="Overweight" />
	<vars height="178" weight="100" bmi="31.6" bmi_category="Obesity" />
</testdata>

You can have data rows defined as <vars> element under the root element <testdata>. In <vars> element you can define all the parameters needed for the test. Create the following script in Selenium IDE:

SelIDE

How it works
In this test the type and verifyValue commands are parameterized by substituting values from the test data specified in above XML file.

The forXml command of Sel Blocks is supplied with the name of XML file where test data is stored. In this example path of data.xml file is passed to the forXml command.

When this test is executed, Sel Blocks loads the content of XML file in memory and executes the script for number of times <vars> element present in the XML file. In this example it will execute the test for four times.

For all the attributes mentioned in <vars> element, Sel Blocks create internal variables that we can substitute as Selenium command parameters.

You can analyse the Selenium IDE Log tab for  results. If the expected data and actual data do not match, an error is reported in the Selenium IDE Log tab.

There’s more
You can also use datadriven user extension to create Data Driven tests. You need to install flowControl andinclude user extensions to use the dataddriven extension. Sel Blocks is easier option as it does not have dependency on any other extension. For more info visit http://wiki.openqa.org/display/SEL/datadriven

This post covers Data Driven testing with Selenium IDE. If you are looking for Data Driven testing with Selenium WebDriver, grab my book Selenium Testing Tools Cookbook published by PacktPub

About these ads

21 Comments on “Data Driven Testing with Selenium IDE”

  1. Ning says:

    I have encountered problem when I was doing the data-driven testing. I made one simple testing working. It was opening a Yahoo website, and clicking four links on Yahoo website. It worked very fine. Then with the same user extension files, I apply the same data-driven testing way to my specific application. Just test data in .xml file is different, test case is much more like your example here because all our variables are input by ‘type’ command. But it doesnot work. It gets stuck even before loading test data without error message in Selenium IDE testing tool interface. The debug log is as following:

    [debug] createForWindow
    [debug] browserName: Netscape
    [debug] userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
    [debug] modifyWindow seleniumMarker1354899420229:undefined
    [debug] _getFrameElement: frameElement=null
    [debug] isPollingForLoad false, this.pollingForLoad[1]: undefined
    [debug] Starting pollForLoad (selenium1354899420233): about:home
    [debug] _getFrameElement: frameElement=null
    [debug] pollForLoad original (selenium1354899420233): about:home
    [debug] _isSamePage: currentHref: about:home
    [debug] _isSamePage: originalHref: about:home
    [debug] _isSamePage: sameDoc: true
    [debug] _isSamePage: sameLoc: true
    [debug] _isSamePage: sameHref: true
    [debug] _isSamePage: markedLoc: true
    [debug] pollForLoad continue (selenium1354899420233): undefined
    [debug] getCurrentWindow newPageLoaded = false

    It even has not run “loadTestData” command. My question is what it runs before loading test data. My successful run has following debug log. I just cut the debug log after loading test data:

    [debug] createForWindow
    [debug] browserName: Netscape
    [debug] userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
    [debug] modifyWindow seleniumMarker1354899311375:undefined
    [debug] _getFrameElement: frameElement=null
    [debug] isPollingForLoad false, this.pollingForLoad[1]: undefined
    [debug] Starting pollForLoad (selenium1354899311379): about:home
    [debug] _getFrameElement: frameElement=null
    [debug] pollForLoad original (selenium1354899311379): about:home
    [debug] _isSamePage: currentHref: about:home
    [debug] _isSamePage: originalHref: about:home
    [debug] _isSamePage: sameDoc: true
    [debug] _isSamePage: sameLoc: true
    [debug] _isSamePage: sameHref: true
    [debug] _isSamePage: markedLoc: true
    [debug] pollForLoad continue (selenium1354899311379): undefined
    [debug] getCurrentWindow newPageLoaded = false
    [debug] currentTest.start()
    [debug] currentTest.continueTest() – acquire the next command
    [debug] currentTest.continueTestAtCurrentCommand()
    [debug] currentTest.resume() – actually execute
    [debug] runScheduledPollers
    [debug] pollForLoad original (selenium1354899311379): about:home
    [debug] _isSamePage: currentHref: about:home
    [debug] _isSamePage: originalHref: about:home
    [debug] _isSamePage: sameDoc: true
    [debug] _isSamePage: sameLoc: true
    [debug] _isSamePage: sameHref: true
    [debug] _isSamePage: markedLoc: true
    [debug] pollForLoad continue (selenium1354899311379): undefined
    [debug] runScheduledPollers DONE
    [info] Executing: |loadTestData | file:///C:/Users/x156179/Desktop/data-driven/test1.xml | |

    Could anyone tell one why it behaves like this?

    Thanks very much,

    Ning

  2. I like your article about data driven testing with selenium ide. I was looking for information about this item and I’m very pleased to read more work of you. keep on writing. thnx

  3. Hendela says:

    Hi, I am using the example above but while running the testcase, Selenium log shows the following error:
    [error] Unexpected Exception: fileName -> chrome://selblocks/content/extensions/sel-blocks.js?1369745820318, lineNumber -> 785, columnNumber -> 6

    • unmesh says:

      Hi Hendela,

      Hope you have given the path of xml input file correctly at forXml command?

      Best,
      Unmesh

      • Hendela says:

        Hi Unmesh,

        After some research I find out that some testdata I put in the .xml file wasn’t correct, after correcting the data, the error doen’t show anymore. Thanks for your reply.

        Regards,
        Hendela

      • John says:

        Hi Hendela,

        Could you possibly explain in what way your test data wasn’t correct? I’m having this same issue but I’m pretty sure my data is fine. Any information would be a big help to me.

        Regards

        John

      • deepak says:

        Hi Unmesh,

        I have the correct path:
        file://c:/data.xml

        and the data seems to be ok:

        still getting the error:

        [error] Unexpected Exception: fileName -> chrome://selblocks/content/extensions/sel-blocks.js?1374402318852, lineNumber -> 778, columnNumber -> 0

        Using FF 20.0

        Thanks,
        Deep

  4. Neil says:

    Hi

    After updating my firefox broxer to version 21.0 , on opening the selenium ide a alert is showing always, and also the data driven testing is not working , is there any way out ?

  5. These are really great ideas in concerning blogging.
    You have touched some fastidious factors here. Any way keep up wrinting.

  6. Satkar says:

    when i run same script i got error (Unexpected Exception: TypeError: testCase.file is undefined. fileName -> chrome://selblocks/content/extensions/sel-blocks.js?1374680614144, lineNumber -> 852). give me example for username and password.

  7. Mike says:

    If I am not mistaken, the SelBlocks is not compatible with FlowControl, another selenium extension.

  8. karan says:

    PLEASE HELP !!!

    I am trying to execute data driven testing using selenium IDE.

    I downloaded all the three extensions that are told step by step and uploaded to selenium IDE core extensions in the same order as guided (C:\Selenium\extensions\goto_sel_ide.js, C:\Selenium\extensions\user-extensions.js.includeCommand4IDE, C:\Selenium\extentions\datadriven.js)

    I restarted the IDE to make sure that it accepts the extention files. It was done successfully.

    My first command in the IDE is “loadTestData | file:///C:/Selenium Test Cases/members.xml | |

    when i am executing the test case i am getting error which is as follows:

    [info] Executing: |loadTestData | file:///C:/Selenium Test Cases/members.xml | |
    [error] Method is not present on Selenium interface: loadTestData

  9. Nilesh says:

    Hi, im getting error as [error] Unknown command: ‘forXml’

    can you please help me on this. I have installed Sel Blocks 1.3

  10. Nilesh says:

    Hi Unmesh,

    Sel Blocks add-on is failing with following error :
    ReferenceError: XML is not defined.

    I am using Selenium Version : 2.4.0 and In Firefox version 25.0.1

    Please help, if there is work around

    Thanks in advance.
    Nilesh

  11. shy says:

    Please help me…

    I’m getting an error message which looks like this: unexpected exception: typeerror: callstack is null….

    What should i do???

  12. Peter Kehl says:

    You may be interested in SeLite. It’s a framework that helps functional testing in Selenium IDE. It allows your tests to access (read and write to) a test DB (isolated from the DB of the tested application). See https://code.google.com/p/selite/wiki/ProjectHome.

    The test data is in SQLite. If the web application can have its data in (separate) SQLite DB, then data lifecycle is very easy. However, you can benefit from SeLite even if your web app uses other type of DB.

  13. Ivan says:

    Hey Unmesh
    Thanks for the great extention
    The problem that I’m facing is that whenever I use this one in parallel with Flow Control extention – ‘labels’ of Flow Control do not work (everything works fine whenever I disable Selblocks)
    Looks like there is a conflict of these two extention
    Could you advice as both are really good and needed for different interactions?

    thx


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers