Selenium IDE


 Selenium IDE
Selenium is a test tool for web applications. Selenium tests run directly in a browser, just as real users do. Selenium is a JavaScript framework that runs in your web browser. Selenium IDE is a FireFox extension made by the OpenQA.org team, that records mouse and keyboard actions as Selenium commands. It is very easy to use and powerful tool for controlling, automating or testing web sites. You can record how an application is being used and then play back those recordings followed by asserts. After recording, you can export test case in many languages like java, Ruby, Perl, python etc.

So, let’s get started with it.

Installing Selenium:  IDE is only available for Firefox as a add-on. In Firefox browser, go to Tools, add-ons, click on get Add-ons, search for Selenium IDE, Click on Install IDE .After installing, restart FireFox.


Selenium IDE explained

After installing Selenium IDE, go to Tools->Selenium IDE, you’ll get a screen which contains

Base URL:The root of web application you want to test. It can be any website URL under test. For ex, If you are test Google’s homepage, then Base URL will be automatically filled by www.google.co.in.

Fast and Slow: We can specify the speed of the test case using Fast and Slow. Default is fast. Sometimes test fails due to the fast execution. Selenium IDE gives the facility to adjust the speed.

Run Test Suite: If there are many test cases, we can put all together in a suite. This button helps us to run the entire suite.

Run a single Test: After recording a test case, we can run the test case by clicking on this button.

Pause: We can pause a test case using this button.

Step: We can step through the test case.

Apply RoleUp Roles:

Record By default when the IDE comes up it has recording turned on.  You might want to turn it off by clicking on the red button, until you are ready to begin recording.

Command ,Target, Value: Specify commands, including asserts.

Log, Reference, UI-Element, RollUp: Reference of the currently selected command.

Recording a Simple Test:
  1.  Start Selenium IDE  in Firefox: Tools->Selenium IDE.
  2. Browse to Google.com and enter ’selenium’ in the search box and click enter.
  3. Click on the first result, which is that of selenium.openqa.org.
  4. Stop the recording by clicking on the record button.
  5. If you click on the ‘Source’ tab you can see the test html generated by selenium.
  6. The ‘table’ tab shows the commands recorded by Selenium.  Open a new tab in Firefox and click on the Selenium IDE’s play button to run the recorded test
                         
There are several commands that can be used  .To use the available commands ,follow the step below.
a. Click on the blank line below after the last ‘clickAndWait’ command and insert ‘assertTextPresent’ command from the drop down box as shown below. You should see something like this.

This test checks to see if the text ‘Selenium News’ is present in the last rendered page. Run the test again and you should see that the test has run successfully. No try replacing the text with something that is not present on the page, take for example ‘mpower’ and run the test again. Now the test fails and you should get the screen below.

We can record and play on any website.
    
Second  example: Now we are  going to use few more commands in our test case. Follow the Step by Step procedure.
  1. Open Firefox browser
  2. In the navigation bar, type in http://www.mpowerglobal.com/
  3. Go to Tools->Selenium IDE. By default it starts recording.
  4. Now go back to firefox, on the http://www.mpowerglobal.com/ home page, On right clicking anywhere on the page ,you can find show all commands with an arrow.On following the arrow,you can find assertTitle  IT Business Consulting | Liferay Portal | … command. select that command.
  5. Now highlight “Who we Are” and right click , select  verifyTextPresent.   
  6. Now go to Selenium IDE , you can find all the actions you performed in command table tab.      
  7. Now go to File->Save TestCase.Browse to the folder you want to save and then save test case  in .html format.

We have successfully created another test case.Now if we want to run these two test cases one after the other, then we can put them in a suite.


Writing a Test Suite: A Test Suite in Selenium is just an HTML file that contains a table of links to tests.

<html>
<table border="1" style="font-size:25">
    <tr><td><a href="./F:/Tests in html/testcase1">Google test</a></td></tr>
                        <tr><td><a href="./F:/Tests in html/testcase2">mPower test</a></td></tr>
</table>
</html>

In order to create a test suite, all you have to do is create an HTML document that is composed of a table of links to your individual unit tests. Obviously you’ll need to adjust the href’s to wherever you have your test cases stored, but essentially that is all there is to creating a test suite.

Running the Test Suite:   After creating the suite, go to Selenium IDE ->File-> Open test suite->navigate to your main suite position.

After opening suite , click on run test suite and see your tests working. To view the test case running, minimize the FireFox window and keep selenium IDE next to it.
  
After recording, we can export test case in many languages .Java developers can export test case in Java. Just have to go File->Export test case as->Java (JUnit)
                           
After exporting, we need Selenium RC to run our exported test case.

Extensions to Selenium IDE: You can extend functionalities of Selenium IDE with JavaScript. There are 2 types of scripts in Selenium IDE - formats and extensions.
User-extensions are very easy to use with the selenium IDE.
  1. Create your user extension and save it as user-extensions.js.
  2. Open Firefox and open Selenium-IDE.Click on Tools, Options
  3. Write the user extensions.js file.
  4. Your user-extension will not yet be loaded, you must close and restart Selenium-IDE.
  5. Now you can use the values present in user-extensions.js file.
XPath: One of the main reasons for using XPath is when you don’t have a suitable id or name attribute for the element you wish to locate. You can use XPath to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute. XPath locators can also be used to specify elements via attributes other than id and name.
There are also a couple of very useful Firefox Add-ons that can assist in discovering the XPath of an element:
  • XPath Checker - suggests XPath and can be used to test XPath results.
  • Firebug - XPath suggestions are just one of the many powerful features of this very useful add-on.

9 comments:

  1. Hi,
    I am new to Selenium tool, Actually we have developed the application on Java and Flex. We want to use selenium tool.
    Please let me know how to install selenium with flex.

    Thanks,
    Raman

    ReplyDelete
  2. Hi,

    You can use selenium rc and java to test your application.There is nothing like selenium +flex installation. Just download Selenium RC and write the test script.
    You can also test using IDE.What problem you are facing while recording script in IDE,let me know.

    ReplyDelete
  3. How to find the name and handle the pop up windows that come automatically(dynamic popups)
    for example : if a pop up window comes immediately after login.

    ReplyDelete
  4. Use waitforpopup command to handle that pop up

    ReplyDelete
  5. Hi... I am automating a test framework. I have a challenge to save the exported documents from the UI. I have a link 'Export as xls' in the UI. So, if i click 'Export as xls' in the UI, immediately, a windows xp pop up will arise which asks us to save or open the document. How to automate this exporting and saving or opening the documents.. Thanks in advance if any one can help me

    ReplyDelete
  6. Hi... I am automating a test framework. I have a challenge to save the exported documents from the UI. I have a link 'Export as xls' in the UI. So, if i click 'Export as xls' in the UI, immediately, a windows xp pop up will arise which asks us to save or open the document. How to automate this exporting and saving or opening the documents.. Thanks in advance if any one can help me

    ReplyDelete
    Replies
    1. You can solve this problem by using firefox profile. when the downloads popup appears for the first time, click on checkbox ,"do this for all " which appears below open file, save file radio button.Then, next time, downloads window won't open, and hence file gets stored on local.

      Delete
  7. I am working on selenium RC, but getting error while executing script
    In IE and firefox - i am getting message that


    - 14:26:08.830 INFO - Killing Firefox...
    14:26:08.832 WARN - Firefox seems to have ended on its own (did we kill the real
    browser???)


    And for iexploreproxy
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Timestamp: Tue, 7 Feb 2012 08:55:05 UTC
    Message: Access is denied.
    Line: 184
    Char: 9
    Code: 0
    URI: http://www.google.com/selenium-server/core/scripts/selenium-testrunner.js

    ReplyDelete
    Replies
    1. have u started your session on port 4444?

      Delete