Using the Selenium IDE for Data-Driven Testing: XML

I just started looking into Selenium as a way to automate some of my testing two days ago. Thanks to others posting about similar things, I’ve managed to create a data-driven web test using an XML file as the data source.  Here’s how I did it:

1. Download flowcontrol, includeCommand4IDE, and datadriven extensions

2. Install the extensions in the Selenium IDE in the same order as listed above. Re-start the IDE after you specify all of the extensions.

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

3. Create an XML file. Here’s a small portion of mine:

<testdata>
<test nameText=”HELLO!!!!!&amp;&lt;&gt;&quot;&#39;” addressText=”This is my address”/>
<test nameText=”Name” addressText=”Address Test Test”/>
</testdata>

XML does have limitations with special characters, so I had to change “&” to “&amp;”, “<” to “&lt;” etc. – see “Special Characters and XML Strings”

4. Create a test case in the IDE. The first command must load the test data. I had to play around with the “while” portion of my test case to ensure that the loop was functioning properly. Here’s some useful documentation from the OpenQA Wiki on the structure of the test case. This is my test case, which edits Account Name and Address in my web application. It then saves the changes, logs out, logs back in, and ensures that the name displayed on the home screen is the name that was just saved. It’s just a simple test, I plan to add a lot more to it.

Edit_AccountInfo
loadTestData file:///C:\ASM\Automated Testing\TestData.xml
open http://localhost:90
type id=username test@test.com
type id=password password
clickAndWait id=loginButton
clickAndWait link=Account Info
click link=Edit
while !testdata.EOF()
nextTestData
type name=name ${nameText}
type name=address-line-1 ${addressText}
click //button[@type=’submit’]
clickAndWait link=Logout
type id=username test@test.com
type id=password password
clickAndWait id=loginButton
verifyTextPresent ${nameText}
clickAndWait link=Account Info
click link=Edit
endWhile

And that’s it! At first, I kept getting errors in the IDE about the datadriven extension, but when I traced the code, I discovered that the real problem was with my XML file. Your XML file cannot have ANY errors in it (no matter how small) or else the test won’t work. If you get an error, check your XML file first!

Although I am happy to be able to easily create data driven tests, I’m already seeing the limitations of using XML as input. I’ve made it my goal for today to figure out how to use a SQL data source. Look for that as my next blog post!


7 Comments

  • Reply Shy |

    Hi there, can you help me? I’ve tried to run tests on selenium as you did with load test data, but something went wrong… It’s not reading from the file and not recognizing the next test data command.. Thanks in advance, shy.

    • Reply Hannah |

      Hi Shy,

      Thanks for the comment. Unfortunately I haven’t worked with this in well over a year now, so I can’t be much help.

      Hannah

      • Reply Pranjal R Nigam |

        Hi Shy,

        Please let me know what is the issue you are facing. Let me try and see if I can help you with that.

        Thanks
        Pranjal R Nigam

  • Reply Pranjal R Nigam |

    Hi Hannah,

    Very well written. Very well explained.

    Thanks.
    Pranjal R Nigam

  • Reply Pranjal R Nigam |

    Hi Hannah,

    You mentioned about ‘Look for that as my next blog post!’. So when is it coming?

    Thanks
    Pranjal R Nigam

  • Reply Pranjal R Nigam |

    Hi Hannah,

    You used ‘testdata.EOF()’ is it because ‘testdata’ is the root element of the XML file? If it had been ‘” then should we have been using ‘object.EOF()?

    Thanks
    Pranjal R Nigam

So, what do you think ?