Selenium IDE


Important Links:

For downloading selenium IDE:
http://www.seleniumhq.org/download/

Selenium IDE Documentation:
http://www.seleniumhq.org/docs/02_selenium_ide.jsp

Firefox add-ons/extensions for Selenium IDE
https://addons.mozilla.org/en-us/firefox/search/?q=selenium&cat=1%2C0&appver=20.0&platform=windows

Installing the Selenium IDE
http://www.seleniumhq.org/docs/02_selenium_ide.jsp#installing-the-ide

Selenium Commands
http://www.seleniumhq.org/docs/02_selenium_ide.jsp#selenium-commands-selenese

Using JavaScript in IDE
http://www.seleniumhq.org/docs/02_selenium_ide.jsp#javascript-and-selenese-parameters

Dealing with Alerts, Popups and Windows
http://www.seleniumhq.org/docs/02_selenium_ide.jsp#alerts-popups-and-multiple-windows



 Selenium IDE Tutorial

Introduction:

Selenium IDE is a plugin to firefox to record and playback tests. You can then export the recorded test in most language such as html, Java , .net , perl , ruby etc. The exported test can be run in any browser and any platform using "selenium remote control" (Selenium RC).
How to Build Test Cases:
Building Test cases by Recording

When Selenium-IDE opened for the first time the record button is ON by default. If you do not want Selenium-IDE to begin recording automatically you can turn this off by going under Options > Options... and deselecting “Start recording immediately on open.”

During recording, Selenium-IDE will automatically insert commands into your test case based on your actions. Typically, this will include:

    clicking a link - click or clickAndWait commands
    entering values - type command
    selecting options from a drop-down listbox - select command
    clicking checkboxes or radio buttons - click command

Points to remember:

    The type command may require clicking on some other area of the web page for it to record.
    Following a link usually records a click command. You will often need to change this toclickAndWait to ensure your test case pauses until the new page is completely loaded. Otherwise, your test case will continue running commands before the page has loaded all its UI elements. This will cause unexpected test case failures.

Verification and Assertions

 
         Your test cases will also need to check the properties of a web-page. This requires assertand verify commands. We won’t describe the specifics of these commands here; that is in the chapter on Selenium Commands – “Selenese”. Here we’ll simply describe how to add them to your test case.

With Selenium-IDE recording, go to the browser displaying your test application and right click anywhere on the page. You will see a context menu showing verify and/or assertcommands.

The first time you use Selenium, there may only be one Selenium command listed. As you use the IDE however, you will find additional commands will quickly be added to this menu. Selenium-IDE will attempt to predict what command, along with the parameters, you will need for a selected UI element on the current web-page.

Let’s see how this works. Open a web-page of your choosing and select a block of text on the page. A paragraph or a heading will work fine. Now, right-click the selected text. The context menu should give you a verifyTextPresent command and the suggested parameter should be the text itself.

Also, notice the Show All Available Commands menu option. This shows many, many more commands, again, along with suggested parameters, for testing your currently selected UI element.

Try a few more UI elements. Try right-clicking an image, or a user control like a button or a checkbox. You may need to use Show All Available Commands to see options other thanverifyTextPresent. Once you select these other options, the more commonly used ones will show up on the primary context menu. For example, selecting verifyElementPresent for an image should later cause that command to be available on the primary context menu the next time you select an image and right-click.

Again, these commands will be explained in detail in the chapter on Selenium commands. For now though, feel free to use the IDE to record and select commands into a test case and then run it. You can learn a lot about the Selenium commands simply by experimenting with the IDE.

Editing the Commands

Insert Command

Table View

Select the point in your test case where you want to insert the command. To do this, in the Test Case Pane, left-click on the line where you want to insert a new command. Right-click and select Insert Command; the IDE will add a blank line just ahead of the line you selected. Now use the command editing text fields to enter your new command and its parameters.


Source View

Select the point in your test case where you want to insert the command. To do this, in the Test Case Pane, left-click between the commands where you want to insert a new command, and enter the HTML tags needed to create a 3-column row containing the Command, first parameter (if one is required by the Command), and second parameter (again, if one is required to locate an element) and third parameter(again, if one is required to have a value). Example: 


<tr>
    <td>Command</td>
    <td>target (locator)</td>
    <td>Value</td>
</tr>

Insert Comment


Comments may be added to make your test case more readable. These comments are ignored when the test case is run.

Comments may also be used to add vertical white space (one or more blank lines) in your tests; just create empty comments. An empty command will cause an error during execution; an empty comment won’t.
 

Table View

Select the line in your test case where you want to insert the comment. Right-click and select Insert Comment. Now use the Command field to enter the comment. Your comment will appear in purple text.


Source View

Select the point in your test case where you want to insert the comment. Add an HTML-style comment, i.e., .
 

Edit a Command or Comment

Table View

Simply select the line to be changed and edit it using the Command, Target, and Value fields.


Source View

Since Source view provides the equivalent of a WYSIWYG (What You See is What You Get) editor, simply modify which line you wish–command, parameter, or comment.

Opening and Saving a Test Case

Like most programs, there are Save and Open commands under the File menu. However, Selenium distinguishes between test cases and test suites. To save your Selenium-IDE tests for later use you can either save the individual test cases, or save the test suite. If the test cases of your test suite have not been saved, you’ll be prompted to save them before saving the test suite.

When you open an existing test case or suite, Selenium-IDE displays its Selenium commands in the Test Case Pane.


Running Test Cases


The IDE allows many options for running your test case. You can run a test case all at once, stop and start it, run it one line at a time, run a single command you are currently developing, and you can do a batch run of an entire test suite. Execution of test cases is very flexible in the IDE.

Run a Test Case

    Click the Run button to run the currently displayed test case.


Run a Test Suite

    Click the Run All button to run all the test cases in the currently loaded test suite.
 

Stop and Start

    The Pause button can be used to stop the test case while it is running. The icon of this button then changes to indicate the Resume button. To continue click Resume.
 

Stop in the Middle

    You can set a breakpoint in the test case to cause it to stop on a particular command. This is useful for debugging your test case. To set a breakpoint, select a command, right-click, and from the context menu select Toggle Breakpoint.
 

Start from the Middle

    You can tell the IDE to begin running from a specific command in the middle of the test case. This also is used for debugging. To set a startpoint, select a command, right-click, and from the context menu select Set/Clear Start Point.
 

Run Any Single Command

    Double-click any single command to run it by itself. This is useful when writing a single command. It lets you immediately test a command you are constructing, when you are not sure if it is correct. You can double-click it to see if it runs correctly. This is also available from the context menu.

    

Using Base URL to Run Test Cases in Different Domains


The Base URL field at the top of the Selenium-IDE window is very useful for allowing test cases to be run across different domains. Suppose that a site named http://news.portal.com had an in-house beta site named http://beta.news.portal.com. Any test cases for these sites that begin with an open statement should specify a relative URL as the argument to open rather than an absolute URL (one starting with a protocol such as http: or https:). Selenium-IDE will then create an absolute URL by appending the open command’s argument onto the end of the value of Base URL.