Tuesday, 7 January 2014

Selenium IDE | Data-driven

This is the continuation of previous post involving advanced concepts of Data-driven tests using Selenium IDE. It helps you while giving a Demo or to do a primary check over the tests again & again. Selenium IDE have an additional feature called user-extensions that gives support to data-driven tests.

Selenium IDE [Data Driven]

1| Download the javaScript files, datadriven.js | goto_sel_ide.js | user-extensions.js from link
2| Open Notepad
3| Copy & Paste following tags and replace the keywords highlighted in Orange with your text.

<testdata>
<test phrase="seleniumworks.com"/>
<test phrase="fire &amp; safety"/>
<test phrase="selenium"/>
<test phrase="Prashanth Sams"/>
</testdata>

4| Save it as a .xml file. e.g., googlesearches.xml
5| Open Selenium IDE.
6| Click Option > Options...
7| Click on Browse under 'Selenium Core extensions (user-extensions.js)'
8| Select all the 3 .js files downloaded earlier [datadriven.js | goto_sel_ide.js | user-extensions.js]
9| Click Ok
10| Restart Selenium IDE








































11| Now, Record the script and edit them in Selenium IDE for proper looping.

loadTestDatafile://c:/googlesearches.xml
while!testdata.EOF()
nextTestData
openhttp://www.google.co.uk
typeq${phrase}
clickbtnG
endWhile
12| Run the Test case

21 comments:

  1. Prashanth,

    How to associate the xml file path to user extensions..? i think that information missing over here.
    Thanks
    Balaji

    ReplyDelete
  2. Aniket,

    After adding extensions and restartnig the IDE it is showing the following Error

    Failed to load user-extensions.js!
    files=D:\Automation Data\Import Export\User Extensions\goto_sel_ide.js, D:\Automation Data\Import Export\User Extensions\datadriven.js, D:\Automation Data\Import Export\User Extensions\user-extensions.js
    lineNumber=37
    error=ReferenceError: XML is not defined

    please give solution
    thanks in advance

    ReplyDelete
    Replies
    1. Add:
      var XML = {};
      before the script starts. It works just fine after that..

      Delete
    2. What do you mean by saying "Add: var XML = {}; before the script starts."
      I have the same problem. If you can tell me more detailly,
      it will help me a lot.

      Delete
  3. Type "var XML = {} ; " in the line before the error line in your user-extensions.js file

    ReplyDelete
  4. I have loaded all the above js files into selenium IDE. and also created a xml with the data given. After that I created the below test in IDE
    loadTestData file://C:/test.xml
    while !testdata.EOF()
    echo ${phrase}
    endWhile

    While I run it, it goes for infinite loop i.e. it doesn't stop. And also instead of printing the real data it is printing "echo: ${phrase}".
    Please help on this.

    ReplyDelete
    Replies
    1. I'm having this issue too, except for the looping. It randomly decides to use the value listed in the file, and othertimes not. Very frustrating. It may be related to what text editor you use.

      Delete
  5. what does the command click btnG do.

    ReplyDelete
    Replies
    1. It clicks the search button on google.

      Delete
  6. Very usefull, it works perfectly ! instead of installing goto_sel_ide.js as an extension you can use the FlowControl plugin

    ReplyDelete
  7. Following error coming after all the step you have suggested.

    [error] Unexpected Exception: Error: Error while fetching url 'file://E:/Selenium/Salesforce/Studentinfo' details: [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://selenium-ide/content/tools.js -> file:///E:/Selenium/Salesforce/Modified_JS/user-extensions.js?1439609307028 :: IDEIncludeCommand.prototype.getIncludeDocumentBySynchronRequest :: line 83" data: no].

    ReplyDelete
  8. while i run .it's issue:
    [error] Unexpected Exception: Error: A element could not be loaded, or was empty..
    Please help me

    ReplyDelete
  9. Hi,

    When starting the IDE again, I get the following error:

    "Failed to load user-extensions.js: SyntaxError: expected expression, got '<'"

    I googled around but didn't find the answer.

    Thanks for any help on this.




    ReplyDelete
  10. error: Unknown command: 'loadTestData

    I'm getting this error why?? running through command line linux

    ReplyDelete
    Replies
    1. Use user-extension.js file
      https://drive.google.com/file/d/0B-1W-UOHy7uyYjFxN3JITF9Wd2c/view

      Delete
  11. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  12. I obtain such error :

    [error] Unexpected Exception: TypeError: activeBlockStack(...).top(...) is undefined.

    Do you know what is the problem?

    ReplyDelete
  13. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  14. Hi Prashanth,

    Request you to update the scripts,

    I am getting the below error message after restarting the IDE:

    Failed to load user-extensions.js: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsILocalFile.initWithPath]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://selenium-ide/content/file-utils.js :: FileUtils.getFile :: line 32" data: no]

    ReplyDelete
  15. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. Selenium Training in Chennai

    ReplyDelete
  16. I am using .csv file and it works fine on my PC. For other PC's it is not working because of .csv file path. So, How can I write relative path in selenium IDE so that my test suite will run in all PC'S?

    ReplyDelete