Author: Roman Tverdokhlebov
Reviewer: Brian Rock
Introduction: This course describes the basics of Selenium, its components and how to start work with it. A few simple examples are provided for better understanding.
Background: Web applications (applications that are accessed via a web browser over a network such as the Internet or an intranet) are used throughout now and it's completely impossible to overestimate their role in our life. Many applications (like CRM systems, office apps and many other) became online.
Essential advantages of web-applications are: you can access them from everywhere, your data in most cases is stored on the server and there is no reason to worry about its safety and accessibility, you need not download, install and setup anything on your computer in order to make use of them.
Main disadvantages of web-applications are: they are rendered by a browser, so it's difficult to ensure the same layout for all the users, a lot of people interact with a server at the same time, data transferred between a client and a server can be trapped or substituted, user can affect application functionality and interface changing browser settings, small hole in application security may result in great loss for many people.
So it is very important to put great efforts into web apps testing! There are a lot of different tools for web apps testing automation, but Selenium can be recommended because of:
Main Selenium components are:
Task
The following test cases will be used to demonstrate the basic capabilities of Selenium:
Tools
The simplest way to automate web application test case is to record it using Selenium IDE for FireFox. So only two tools are required:
Test recording


First column contains Selenium commands. Select any command to see its short description. Second column contains targets. For command “open” target is URL to be browsed, for commands “type” and “click” argument “target” contains element id. Third column contains optional values, e.g., string to be entered into an input field.
Test suite forming
It looks like there is only one single test case, but actually there is a test suite with one test case. To see test suite press vertical separator or create new test case using menu File:

Having created an empty test case and recorded two test scenarios in the same fashion, we will get the test suite with two test cases. Next, let’s execute it.
Execution & debug
There are two ways to execute test cases: with IDE and with Selenium TestRunner.
Select first test case “Selenium” and click “Play current test case” button to execute it. In most cases test failed. Why? Because page has not been loaded completely and verification was performed when body text wasn't received and parsed. So we should modify test case and insert one more command. Select the last command “verifyTextPresent”, click option “Insert new command” in context menu and fill in appropriate data to improve the test case:

Target = “30000” means that we should wait until page load, but not more than 30 seconds. Run test again, it should succeed.
In Selenium IDE you can toggle breakpoint, set speed of the execution, run particular commands, or walk step by step through test script:

Using “Play with Selenium Test Runner” button it is possible to execute test cases in much more informative way. You can review all your test scripts, see test execution, time spent and test results in one single window:
Test export
Having saved recorded test scripts, you’ll get an HTML file like the following:

It isn’t very useful since you can’t use it anywhere except Selenium IDE. But you can transform test scripts to different programming languages. Just navigate to Options menu, select Format option and choose suitable format:

Exported test scripts can be executed outside Selenium IDE using Selenium RC, e.g., in case of Java in Eclipse or as standalone set of JUnit tests, but this theme is out of scope for the current course. Hope you enjoyed this introduction to Selenium course!
Resources:
1) Selenium HQ - http://seleniumhq.org/
2) Selenium Projects - http://seleniumhq.org/projects/
3) Selenium IDE - http://seleniumhq.org/projects/ide/
4) Selenium intro - http://seleniumhq.org/movies/intro.mov
5) Selenium in Wikipedia - http://en.wikipedia.org/wiki/Selenium_(software)
6) Selenium Tutorial - http://www.jroller.com/selenium/