Dashboard > Selenium IDE > Home > Getting Started with Selenium IDE
Selenium IDE Log In View a printable version of the current page.
Getting Started with Selenium IDE
Added by Pam, last edited by Adam Koch on Nov 10, 2008  (view change)
Labels: 

This is a very basic text overview of how to get started writing tests in Selenium IDE. There is also a video introduction here: http://wiki.openqa.org/display/SIDE/Recording+a+Test. In order to write effective tests in Selenium IDE, you should have a solid understanding of HTML. Selenium IDE can copy your actions automatically, but it cannot always verify results or find the proper element for you. Other than that, it's fairly easy.

Install It

Installation is very easy, simply go to the Firefox extensions page https://addons.mozilla.org/en-US/firefox/addon/2079 and add the extension to Firefox. Yes, the Selenium IDE only works with Firefox, although you can run the tests generated by Selenium IDE in other browsers using the TestRunner that comes with Selenium Core http://wiki.openqa.org/display/SEL/Getting+Started+with+Selenium+Core.

Make a quick script

  1. Browse to a page you'd like to test. Perhaps... http://wiki.openqa.org/
  2. Open the IDE in Firefox (Tools -> Selenium IDE).
  3. If it's not already activated, click on the red record button on the right hand side of the IDE.
  4. Click through several links, and enter a search term.
  5. Submit the search, and limit it by the Location drop down.

You will see the commands representing your actions getting added to the table as you go. The commands should look something like this:
Snapshot of simple script
(The full HTML of the text is located at the bottom if you want to copy and paste under the "Source" tab.)

The "Command" column

The "Command" column represents the command that must be issued to duplicate your action. Some of these commands are very straight-forward:

  • 'open' will open a URL and wait for it to load.
  • 'click' will act just as if you had clicked on the link or button yourself.
  • 'select' chooses a selection from a drop down list.

The "Target" column

The "Target" column represents what you are trying to click on or interact with. If you look at the sample script above, you will notice a variety of different formats in the "Target" column. These are called "locators" in Selenium IDE, and can be represented a variety of ways:

  • URLs - "/dashboard.action" - represents a url. The first part of the URL is the Base URL up at the top, and this URL is relative to that.
  • HTML id - "spacelink-SIDE" - this is the HTML id of the link
  • Text - "link=Recording a Test" - the text of the link
  • HTML name = "searchQuery.queryString" - like the
  • XPath - "//input[@value='Search']" - XPath is an XML-like language that can be used to specify the location of an element in a document
  • Label - "label-Selenium IDE" - selects the item with the visible label of Selenium IDE.

There are other kinds of identifiers as well, such as HTML Dom, or a CSS-style reference, but those get more complicated. You can read more about them here http://release.openqa.org/selenium-core/0.8.0/reference.html.

The "Value" column

The "Value" column represents any other data you might pass on to the command, also known as an argument or a parameter. The contents of the column varies from command to command, but is usually some kind of value - either the text you want to type, or the text you want to compare something to, or a second locator that is required to select an item.

The best way to understand these values is to click on the command you are trying to use, and look at the bottom, on the Reference tab. It will give you information on how the command works, and what all the arguments are.

Run your script

You're now ready to run your script, right?

  1. Click on the red record button to STOP recording
  2. Make sure you have your test browser window selected (so you don't navigate away from this tutorial!)
  3. Click on the "Play current test case" button - the green arrow with one highlighted line by it.
Ooops!

Does it fail?? Mine did! Don't worry - all it means is that Selenium IDE needs to know a little bit more about what you're trying to do. You might see the error "[error] Element spacelink-SIDE not found" or something similar. That means that it went to click on the link, and it wasn't there. Basically, the page wasn't loaded yet.

What you have to do here is change the "click" to "clickAndWait", so that when it clicks the link it waits for the page to load completely. There are times when "click" is what you want, but usually you will want the "clickAndWait".

To edit a command:

  1. Click on the row with the command you want to edit in the table
  2. Look below it where there are input fields that you can type into
  3. By Command, click beside the "click" text, and start typing "AndWait"
  4. You will notice a drop down, to help you select which command to call.
  5. Choose or finish typing "clickAndWait"

Do this for all the "click" commands in the automated script and now your script will work! But wait a minute, you say, we didn't actually verify anything... how do we even know the site is working? Or that we got the right search results?

Check your data

Here's were it gets a little more interesting, since there's a million functions to sort through and not all of them are just click and go.
Let's add a couple of checks to the script, so we can see how it works:

  1. Click on the second line in your script (in the table area)
  2. In your browser window, highlight the title of the page, or some important text, such as "Welcome"
  3. Right-click on your highlighted text, and you will see some commands have been added to the menu that pops up
  4. Choose the verifyTextPresent option that shows your highlighted text. The command should be inserted just below the first command.
  5. Now go down to your "clickAndWait" command. Choose the line in the table AFTER the clickAndWait item.
  6. Right-click and select "Insert New Command"
  7. In the Command Input, select "assertTextNotPresent" and in the target type "Mercury", or something else that shouldn't be on the page
  8. Re-run your test, and you can see that the checks are working!

Verifying contents on inputs

Sometimes you will need to verify the contents on inputs, and this can be more complicated than just verifying text is present. The most common way is the right-click menu. There's a sub-menu called "Show All Commands" that lists more options. However, this menu doesn't show up for checkboxes or select boxes.

The most tricky part of verifying check boxes or select boxes is actually figuring out how to specify it. If it has an "id" element, you can simply use that. But if the ID element is missing, you may have to use XPath to specify where the element is. You can learn more about XPath here http://www.w3schools.com/XPath/default.asp. Here are some samples:

 
* //input[@value='Search'] - an input button with the text "Search" on it
* //table[@id='proTable']/tbody/tr[2]/td[6]/div[7] - the contents of the 7th div in the 6th column of the 2nd row of the "proTable" table.
* //div[@id='salary_currency-drop']/ul/li - the first list item in a div called "salary_currency-drop"
* //*[@id="joining1"] - a radio box (or any element, really) with id "joining1"
Handy Tools
A very useful Firefox plugin for working with XPath is XPather http://addons.mozilla.org/en-US/firefox/addon/1192. It will show the XPath of elements, even when Firebug http://addons.mozilla.org/en-US/firefox/addon/1843 cannot. Although, in most cases, if you inspect the element in Firebug, and right click on the element in Firebug, you can "Copy XPath". Both good tools, but if you're only going with one, look at Firebug first.

If you are following the example above, here is one you can try:

  1. Run the script above, it should end on the search page
  2. Click on the blank table row below the last line of the script
  3. To find the ID of the select drop down, inspect the element using Firebug (or view the source)
  4. In the command input, type "assertSelectedLabel" - this will check the input based on the visible text that is showing
  5. Put in the target for the search element, either the HTML ID: "newSpaceKey", or XPath:
     //*[@id="newSpaceKey"]
  6. In the Value column, put the text that should be selected: "Selenium IDE".
  7. Run the test to make sure it works

Your finished script should look something like this:

Verify vs. Assert

You will notice some of these commands start with "assert" and some start with "verify". "assert" will stop the entire execution of the script. This is useful for checking you are on the right page, or if some critical step has been reached. "verify" will log any error, but then keep on going with the test. This is useful for checking the values of inputs when there are a lot on the page.

Test Cases vs. Test Suites

Those of you who are professional testers or developers probably know about this, but Selenium IDE is so easy, even non-technical folks can be called in to help. So, here is a description of the differences between a Test Case and a Test Suite.

  • Test Case - this is one script, one set of instructions, saved in one file. If you look at the menu, you will see "Save Test Case" near the top. Probably a good idea to do this now.
  • Test Suite - this is a collection of Test Cases, just a listing of locations of individual scripts, also in HTML format. If you look at the file menu, you will see near the bottom a set of commands for Test Suites. You can run an entire SET of test cases at once by using a Test Suite. If you work with Test Suites in Selenium IDE, it's important that you save BOTH the Test Case and the Test Suite after making changes.

More Information

Full HTML version of the sample script

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://wiki.openqa.org/" />
<title>simpleScript</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">simpleScript</td></tr>
</thead><tbody>
<tr>
	<td>open</td>
	<td>/dashboard.action</td>
	<td></td>
</tr>
<tr>
	<td>verifyTextPresent</td>
	<td>Where do I start?</td>
	<td></td>
</tr>
<tr>
	<td>verifyTextPresent</td>
	<td>Selenium IDE (SIDE)</td>
	<td></td>
</tr>
<tr>
	<td>verifyTextPresent</td>
	<td>Welcome to Confluence</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>spacelink-SIDE</td>
	<td></td>
</tr>
<tr>
	<td>assertTextNotPresent</td>
	<td>Mercury</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>link=Recording a Test</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>searchQuery.queryString</td>
	<td>assert</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>//input[@value='Search']</td>
	<td></td>
</tr>
<tr>
	<td>select</td>
	<td>newSpaceKey</td>
	<td>label=Selenium IDE</td>
</tr>
<tr>
	<td>assertValue</td>
	<td>//input[@name='searchQuery.queryString' and @value='assert']</td>
	<td>assert</td>
</tr>
<tr>
	<td>assertSelectedLabel</td>
	<td>newSpaceKey</td>
	<td>Selenium IDE</td>
</tr>
</tbody></table>
</body>
</html>

This is a very good "Getting Started" guide.

Just one comment though...

The 'select' command in the last examples of the script should be changed to 'selectAndWait'. Otherwise it won't find  the specified patterns because the page would not have loaded yet.

 P.S.

Selenium is great, I love it!

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators