Sie sind auf Seite 1von 33

What is Selenium?

Selenium is a free (open source) automated testing suite for web applications across different
browsers and platforms. It is quite similar to HP Quick Test Pro (QTP) only that Selenium focuses on
automating web-based applications.
Selenium is not just a single tool, but a suite of softwares, each catering to different testing needs of an
organization. It has four components.
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
Web Driver
Selenium Grid

At the moment, Selenium RC and WebDriver are merged into a single framework to form Selenium 2.
Selenium 1, by the way, refers to Selenium RC.
Who developed Selenium?
Since Selenium is a collection of different tools, it had different developers as well. Below are the key
persons who made notable contributions to the Selenium Project

Birth of Selenium Core
Primarily, Selenium was created by Jason Huggins in 2004. An engineer at ThoughtWorks, he was
working on a web application that required frequent testing. Having realized that the repetitious
manual testing of their application was becoming more and more inefficient, he created a JavaScript
program that would automatically control the browser's actions. He named this program as the
"JavaScriptTestRunner."
Seeing potential in this idea to help automate other web applications , he made JavaScriptRunner open-
source which was later re-named as Selenium Core.
The Same Origin Policy Issue
Same Origin policy prohibits JavaScript code from accessing elements from a domain that is
different from where it was launched. Example, the HTML code in www.google.com uses a
JavaScript program "randomScript.js". The same origin policy will only allow randomScript.js to
access pages within google.com such as google.com/mail, google.com/login, or google.com/signup.
However, it cannot access pages from different sites such as yahoo.com. because they belong to
different domains.


This is the reason why prior to Selenium RC, testers needed to install local copies of both Selenium
Core (a JavaScript program) and the web server containing the web application being tested so they
would belong to the same domain
Birth of Selenium Remote Control (Selenium RC)
Unfortunately; testers using Selenium Core had to install the whole application under test and the web
server on their own local computers because of the restrictions imposed by thesame origin policy. So
another ThoughtWork's engineer, Paul Hammant, decided to create a server that will act as an HTTP
proxy to "trick" the browser into believing that Selenium Core and the web application being tested
come from the same domain. This system became known as the Selenium Remote
Control or Selenium 1.
Birth of Selenium Grid

Selenium Grid was developed by Patrick Lightbody to address the need of minimizing test execution
times as much as possible. He initially called the system "Hosted QA." It was capable of capturing
browser screenshots during significant stages, and also of sending out Selenium commands to
different machines simultaneously.
Birth of Selenium IDE

Shinya Kasatani of Japan created Selenium IDE, a Firefox extension that can automate the browser
through a record-and-playback feature. He came up with this idea to further increase the speed in
creating test cases. He donated Selenium IDE to the Selenium Project in 2006.
Birth of WebDriver
Simon Stewart created WebDriver circa 2006 when browsers and web applications were becoming
more powerful and more restrictive with JavaScript programs like Selenium Core.It was the first
cross-platform testing framework that could control the browser from the OS level.
Birth of Selenium 2

In 2008, the whole Selenium Team decided to merge WebDriver and Selenium RC to form a more
powerful tool called Selenium 2, with WebDriver being the core. Currently, Selenium RC is still
being developed but only in maintenance mode. Most of the Selenium Project's efforts are now focused
on Selenium 2.
So, Why the Name Selenium?
It came from a joke which Jason cracked one time to his team. Another automated testing framework
was popular during Selenium's development, and it was by the company called Mercury
Interactive (yes, the company who originally made QTP before it was acquired by HP). Since
Selenium is a well-known antidote for Mercury poisoning, Jason suggested that name. His teammates
took it, and so that is how we got to call this framework up to the present.


Brief Introduction Selenium IDE
Selenium Integrated Development Environment (IDE) is the simplest framework in the Selenium
suite and is the easiest one to learn. It is a Firefox plugin that you can install as easily as you can with
other plugins. However, because of its simplicity, Selenium IDE should only be used as a prototyping
tool. If you want to create more advanced test cases, you will need to use either Selenium RC or
WebDriver.


Brief Introduction Selenium Remote Control (Selenium RC)
Selenium RC was the flagship testing framework of the whole Selenium project for a long time. This
is the first automated web testing tool that allowed users to use a programming language they
prefer.As of version 2.25.0, RC can support the following programming languages:
Java
C#
PHP
Python
Perl
Ruby

Brief Introduction WebDriver
The WebDriver proves itself to be better than both Selenium IDE and Selenium RC in many
aspects. It implements a more modern and stable approach in automating the browser's actions.
WebDriver, unlike Selenium RC, does not rely on JavaScript for automation. It controls the browser
by directly communicating to it.
The supported languages are the same as those in Selenium RC.
Java
C#
PHP
Python
Perl
Ruby

Selenium Grid
Selenium Grid is a tool used together with Selenium RC to run parallel tests across different
machines and different browsers all at the same time. Parallel execution means running multiple tests at
once.
Features:
Enables simultaneous running of tests in multiple browsers and environments.
Saves timeenormously.
Utilizes the hub-and-nodes concept. The hub acts as a central source of Selenium commands to
each node connected to it.
Note on Browser and Environment Support
Because of their architectural differences, Selenium IDE, Selenium RC, and WebDriver support
different sets of browsers and operating environments.

Selenium
IDE
Selenium RC WebDriver
Browser
Support
Mozilla
Firefox
Mozilla Firefox
Internet Explorer
Google Chrome
Safari
Opera
Internet Explorer versions 6 to 9, both 32 and 64-
bit

Firefox 3.0, 3.5, 3.6, 4.0, 5.0, 6, 7 and above
(current version is 16.0.1)


Selenium
IDE
Selenium RC WebDriver
Konqueror
Others

Google Chrome 12.0.712.0 and above
(current version is 22.0.1229.94 m)

Opera 11.5 and above
(current version is 12.02)

Android - 2.3 and above for phones and tablets
(devices & emulators)

iOS 3+ for phones (devices & emulators) and
3.2+ for tablets (devices & emulators)

HtmlUnit 2.9 and above
(current version is 2.10)
Operating
System
Windows
Mac OS X
Linux

Windows
Mac OS X
Linux
Solaris
All operating systems where the browsers above can
run.
How to Choose the Right Selenium Tool for Your Need
Tool Why Choose ?
Selenium IDE
To learn about concepts on automated testing and Selenium, including:
Selenese commands such as type, open,
clickAndWait, assert, verify, etc.
Locators such as id, name, xpath, css selector, etc.
Executing customized JavaScript code using
Tool Why Choose ?
runScript
Exporting test cases in various formats.
To create tests with little or no prior knowledge in programming.
To create simple test cases and test suites that you can export later to
RC or WebDriver.
To test a web application against Firefox only.
Selenium RC
To design a test using a more expressive language than Selenese
To run your test against different browsers (except HtmlUnit) on
different operating systems.
To deploy your tests across multiple environments using Selenium
Grid.
To test your application against a new browser that supports
JavaScript.
To test web applications with complex AJAX-based scenarios.
WebDriver
To use a certain programming language in designing your test case.
To test applications that are rich in AJAX-based functionalities.
To execute tests on the HtmlUnit browser.
To create customized test results.
Selenium Grid
To run your Selenium RC scripts in multiple browsers and operating
systems simultaneously.
To run a huge test suite, that need to complete in soonest time possible.
A Comparison between Selenium and QTP
Quick Test Professional(QTP) is a proprietary automated testing tool previously owned by the
companyMercury Interactive before it was acquired by Hewlett-Packard in 2006. The Selenium
Tool Suite has many advantages over QTP (as of version 11) as detailed below -
Advantages of Selenium over QTP
Selenium QTP
Open source, free to use, and free of
charge.
Commercial.
Highly extensible Limited add-ons
Can run tests across different browsers
Can only run tests in Firefox , Internet
Explorerand Chrome
Supports various operating systems Can only be used in Windows
Supports mobile devices Supports mobile devise using 3
rd
party software
Can execute tests while the browser is
minimized
Needs to have the application under test to be
visible on the desktop
Can execute tests in parallel.
Can only execute in parallel but using Quality
Center which is again a paid product.

Advantages of QTP over Selenium
QTP Selenium
Can test both web and desktop
applications
Can only test web applications
Comes with a built-in object repository Has no built-in object repository
Automates faster than Seleniumbecause it
is a fully featured IDE.
Automates at a slower rate because it does not
have a native IDE and only third party IDE can
be used for development
Data-driven testing is easier to perform
because it has built-in global and local
data tables.
Data-driven testing is more cumbersome since
you have to rely on the programming language's
capabilities for setting values for your test data
Can access controls within the
browser(such as the Favorites bar, Address
bar, Back and Forward buttons, etc.)
Cannot access elements outside of the web
application under test
Provides professional customer support No official user support is being offered.
Has native capability to export test datainto
external formats
Has no native capability to export runtime data
onto external formats
Parameterization Support is in built
Parameterization can be done via programming
but is difficult to implement.
Test Reports are generated automatically No native support to generate test /bug reports.

Though clearly, QTP has more advanced capabilities, Selenium outweighs QTP in three main areas:
Cost(because Selenium is completely free)
Flexibility(because of a number of programming languages, browsers, and platforms it can
support)
Parallel testing(something that QTP is capable of but only with use of Quality Center)
Summary
The entire Selenium Tool Suite is comprised of four components:
Selenium IDE, a Firefox add-on that you can only use in creating relatively simple test
cases and test suites.
Selenium Remote Control, also known as Selenium 1, which is the first Selenium tool
that allowed users to use programming languages in creating complex tests.
WebDriver, the newer breakthrough that allows your test scripts to communicate directly
to the browser, thereby controlling it from the OS level.
Selenium Gridis also a tool that is used with Selenium RC to execute parallel tests across
different browsers and operating systems.
Selenium RC and WebDriver was merged to form Selenium 2.
Selenium is more advantageous than QTP in terms of costs and flexibility. It also allows you
to run tests in parallel, unlike in QTP where you are only allowed to run tests sequentially.














Installation of Selenium IDE
What you need
Mozilla Firefox
Active internet connection

If you do not have Mozilla Firefox yet, you can download it from http://www.mozilla.org/en-
US/firefox/new.

Steps
Launch Firefox and navigate to http://seleniumhq.org/download/. Under the Selenium IDE section,
click on the link that shows the current version number.

For security, a Firefox notification will pop up. Click on "Allow."

Wait until Firefox completes the download and then click "Install Now."


Wait until installation is completed. In the pop-up window, click "Restart Now."


After Firefox has restarted, launch Selenium IDE using either of two ways:
By pressing Ctrl+Alt+S
By clicking on the Firefox menu button > Web Developer> Selenium IDE

Selenium IDE should launch as shown below

Installation of Firebug
Firebug is a Firefox add-on that we will use to inspect the HTML elements of the web application
under test. It will provide us the name of the element that our Selenese command would act upon.
Step 1
Use Firefox to navigate to Firebug's download page (https://getfirebug.com/downloads/) and click on
the download link.

Step 2
Firefox will take you to its Firebug download section. Click the "Add to Firefox" button.

Step 3
Wait for Firefox to complete downloading this add-on. On the dialog box that comes after,
click "Install Now."

Step 4
Wait for installation to complete. A notification will pop-up saying, "Firebug has been installed
successfully." You can immediately close this pop-up.

Note: In case you do not see above pop-up , no worries! This pop-up appears for a few seconds and
disappears.
You do not need to restart Firefox after installing Firebug.
Step 5
Launch Firebug by doing either of these two methods:
Press F12
Click on the Firebug button on the upper right corner of the Firefox window.

Step 6
Firebug should launch at the bottom of Firefox as shown below


Plugins
Selenium IDE can support additional Firefox add-ons or plugins created by other users. You can
visit here for a list of Selenium add-ons available to date. Install them just as you do with other Firefox
add-ons.
By default, Selenium IDE comes bundled with 4 plugins:
1. Selenium IDE: C# Formatters
2. Selenium IDE: Java Formatters
3. Selenium IDE: Python Formatters
4. Selenium IDE: Ruby Formatters
These four plugins are required by Selenium IDE to convert Selenese into different formats.
The Plugins tab shows a list of all your installed add-ons, together with the version number and
name of the creator of each.


User Extensions
Selenium IDE can support user extensions to provide advanced capabilities. User extensions are in the
form of JavaScript files. You install them by specifying their absolute path in either of these two fields
in the Options dialog box.
Selenium Core extensions (user-extensions.js)
Selenium IDE extensions


You will be able to find tons of user extensions here.




Introduction to Selenium IDE


Selenium IDE (Integrated Development Environment) is the simplest tool in the Selenium Suite. It is a
Firefox add-on that creates tests very quickly through its record-and-playback functionality. This feature
is similar to that of QTP. It is effortless to install and easy to learn.
Because of its simplicity, Selenium IDE should only be used as a prototyping tool - not an overall solution
for developing and maintaining complex test suites.
Though you will be able to use Selenium IDE without prior knowledge in programming, you should at least
be familiar with HTML, JavaScript, and the DOM (Document Object Model) to utilize this tool to its full
potential. Knowledge of JavaScript will be required when we get to the section about the Selenese command
"runScript".
Selenium IDE supports autocomplete mode when creating tests. This feature serves two purposes:
It helps the tester to enter commands more quickly.
It restricts the user from entering invalid commands.

Features of Selenium IDE


Menu Bar
It is located at the topmost portion of the IDE. The most commonly used menus are the File, Edit, and Options
menus.
File menu
It contains options to create, open, save, and close tests.
Tests are saved in HTML format.
The most useful option is "Export" because it allows you to turn your Selenium IDE test cases into file formats
that can run on Selenium Remote Control and WebDriver
"Export Test Case As..." will export only the currently opened test case.
"Export Test Suite As..." will export all the test cases in the currently opened test suite.


As of Selenium IDE v1.9.1, test cases can be exported only to the following formats:
.cs (C# source code)
.java (Java source code)
.py (Python source code)
.rb (Ruby source code)


Edit Menu
It contains usual options like Undo, Redo, Cut, Copy, Paste, Delete, and Select All.
The two most important options are the "Insert New Command" and "Insert New Comment".


The newly inserted command or comment will be placed on top of the currently selected line.


Commands are colored black.
Comments are colored purple.


Options menu
It provides the interface for configuring various settings of Selenium IDE.
We shall concentrate on the Options and Clipboard Format options.


Clipboard Format

The Clipboard Format allows you
to copy a Selenese command
from the editor and paste it as a
code snippet.
The format of the code follows the
option you selected here in
Clipboard Format's list.
HTML is the default selection.
For example, when you choose Java/JUnit 4/WebDriver as your clipboard format, every Selenese command
you copy from Selenium IDE's editor will be pasted as Java code. See the illustration below.


Selenium IDE Options dialog box
You can launch the Selenium IDE Options dialog box by clicking Options > Options... on the menu bar.
Though there are many settings available, we will concentrate on the few important ones.


Default Timeout Value. This refers to the time that Selenium has to wait for a certain element to appear or
become accessible before it generates an error. Default timeout value is 30000ms.
Selenium IDE extensions. This is where you specify the extensions you want to use to extend Selenium IDE's
capabilities. You can visit http://addons.mozilla.org/en-US/firefox/and use "Selenium" as keyword to search for
specific extensions.
Remember base URL. Keep this checked if you want Selenium IDE to remember the Base URL every time you
launch it. If you uncheck this, Selenium IDE will always launch with a blank value for the Base URL.
Autostart record. If you check this, Selenium IDE will immediately record your browser actions upon startup.
Locator builders.This is where you specify the order by which locators are generated while recording. Locators
are ways to tell Selenium IDE which UI element should a Selenese command act upon. In the setup below,
when you click on an element with an ID attribute, that element's ID will be used as the locator since "id" is the
first one in the list. If that element does not have an ID attribute, Selenium will next look for the "name"
attribute since it is second in the list. The list goes on and on until an appropriate one is found.


Base URL Bar


It has a dropdown menu that remembers all previous values for easy access.
The Selenese command "open" will take you to the URL that you specified in the Base URL.
In this tutorial series, we will be using http://newtours.demoaut.com as our Base URL. It is the site for Mercury
Tours, a web application maintained by HP for web testing purposes. We shall be using this application because
it contains a complete set of elements that we need for the succeeding topics.
The Base URL is very useful in accessing relative URLs. Suppose that your Base URL is set to
http://newtours.demoaut.com. When you execute the command "open" with the target value "signup",
Selenium IDE will direct the browser to sign-up page. See the illustration below.


Toolbar


Playback Speed. This controls the speed of your Test Script Execution.

Record.This starts/ends your recording session. Each browser action is entered as a Selenese
command in the Editor.

Play entire test suite. This will sequentially play all the test cases listed in the Test Case Pane.

Play current test case. This will play only the currently selected test case in the Test Case Pane.

Pause/Resume. This will pause or resume your playback.

Step. This button will allow you to step into each command in your test script.

Apply rollup rules. This is an advanced functionality. It allows you to group Selenese
commands together and execute them as a single action.

Test Case Pane

In Selenium IDE, you can open more than one
test case at a time.
The test case pane shows you the list of
currently opened test cases.
When you open a test suite, the test case pane
will automatically list all the test cases contained
in it.
The test case written in bold font is the currently
selected test case
After playback, each test case is color-coded to
represent if it passed or failed.
o Green color means "Passed."
o Red color means "Failed."
At the bottom portion is a summary of the
number of test cases that were run and failed.
Editor
You can think of the editor as the place where all the action happens. It is available in two views: Table and
Source.

Table View

Most of the time, you will work on
Selenium IDE using the Table View.
This is where you create and modify
Selenese commands.
After playback, each step is color-
coded.


To create steps, type the name of the
command in the "Command" text
box.
It displays a dropdown list of
commandsthat match with the entry
that you are currently typing.
Target is any parameter (like
username , password) for a command
and Value is the input value (like
tom,123pass) for those Targets.

Source View

It displays the steps in HTML
(default) format.
It also allows you to edit your
scriptjust like in the Table View.
Log Pane
The Log Pane displays runtime messages during execution. It provides real-time updates as to what Selenium
IDE is doing.
Logs are categorized into four types:
Debug - By default, Debug messages are not displayed in the log panel. They show up only when you filter them.
They provide technical information about what Selenium IDE is doing behind the scenes. It may display
messages such as a specific module has done loading, a certain function is called, or an external JavaScript file
was loaded as an extension.
Info - It says which command Selenium IDE is currently executing.
Warn - These are warning messages that are encountered in special situations.
Error - These are error messages generated when Selenium IDE fails to execute a command, or if a condition
specified by "verify" or "assert" command is not met.



Logs can be filtered by type. For example, if you choose to select the "Error" option from the dropdown list,
the Log Pane will show error messages only.


Reference Pane
The Reference Pane shows a concise description of the currently selected Selenese command in the
Editor. It also shows the description about the locator and value to be used on that command.


UI-Element Pane
The UI-Element is for advanced Selenium users. It uses JavaScript Object Notation (JSON) to define
element mappings. The documentation and resources are found in the "UI Element Documentation" option
under the Help menu of Selenium IDE.

An example of a UI-element screen is shown below.


Rollup Pane
Rollup allows you to execute a group of commands in one step.A group of commands is simply called as a
"rollup." It employs heavy use of JavaScript and UI-Element concepts to formulate a collection of commands
that is similar to a "function" in programming languages.
Rollups are reusable; meaning, they can be used multiple times within the test case. Since rollups are groups
of commands condensed into one, they contribute a lot in shortening your test script.

An example of how the contents of the rollup tab look like is shown below.

Summary
Selenium IDE (Integrated Development Environment) is the simplest tool in the Selenium Suite.
It must only be used as a prototyping tool.
Knowledge of JavaScript and HTML is required for intermediate topics such as executing the "runScript" and
"rollup" commands.A rollup is a collection of commands that you can reuse to shorten your test scripts
significantly.Locators are identifiers that tell Selenium IDE how to access an element.
Firebug (or any similar add-on) is used to obtain locator values.
The menu bar is used in creating, modifying, and exporting test cases into formats useable by Selenium RC and
WebDriver.
The default format for Selenese commands is HTML.
The "Options" menu provides access to various configurations for Selenium IDE.
The Base URL is useful in accessing relative URLs.
The Test Case Pane shows the list of currently opened test cases and a concise summary of test runs.
The Editor provides the interface for your test scripts.
The Table View shows your script in tabular format with "Command", "Target", and "Value" as the columns.
The Source View shows your script in HTML format.
The Log and Reference tabs give feedback and other useful information when executing tests.
The UI-Element and Rollup tabs are for advanced Selenium IDE users only. They both require considerable
effort in coding JavaScript.
UI-Element allows you to conveniently map UI elements using JavaScript Object Notation (JSON).

Das könnte Ihnen auch gefallen