Sie sind auf Seite 1von 16

SUDHEER REDDY ANKIREDDYGARI (G)

SELENIUM WEB DRIVER

Selenium RC (Selenium Remote Control)


Selenium RC is a tool which is written in java that allows a user to construct test scripts for a
web based application in which ever programming language he/she chooses. Selenium RC came
as result to overcome various disadvantages incurred by Selenium IDE or Core.
Loopholes and restrictions which were imposed while using Selenium Core made it difficult for
the user to leverage the benefits of the tool to its totality. Thus it made the testing process a
cumbersome and a far reaching task.
One of the crucial restrictions was same origin policy.
Problem of same origin policy:
The problem of same origin policy disallows to access the DOM of a document from an origin
that is different from the origin we are trying to access the document.
Origin is a sequential combination of scheme, host and port of the URL. For example, for a URL
http://www.seleniumhq.org/projects/, the origin is a combination of http, seleniumhq.org, 80
correspondingly.
Thus the Selenium Core (JavaScript Program) cannot access the elements from an origin that is
different from where it was launched.
For Example, if I have launched the JavaScript Program from http://www.seleniumhq.org/,
then I would be able to access the pages within the same domain such as
http://www.seleniumhq.org/projects/ or http://www.seleniumhq.org/download/. The other
domains like google.com, yahoo.com would no more be accessible.
Thus, to test the application using Selenium Core, one has to install the entire application on the
Selenium Core as well as web server to overcome the problem of same origin policy.

Page 1 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

So, In order to govern the same origin policy without the need of making a separate copy of
Application under test on the Selenium Core, Selenium Remote Control was introduced. While
Jason Huggins was demoing Selenium, another fellow colleague at ThoughtWorks named Paul
Hammant suggested a work around of same origin policy and a tool that can be wired up with a
programming language of our choice. Thus Selenium RC came into existence.
Unlike selenium IDE, selenium RC supports a wide range of browsers and platforms.

Workflow Description

User creates test scripts in a desired programming language.


Page 2 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

For every programming language, there is a designated client library.

Client library deports the test commands to the selenium server.

Selenium server deciphers and converts the test commands into JavaScript commands
and sends them to the browser.

Browser executes the commands using selenium core and sends results back to the
selenium server

Selenium server delivers the test results to the client library.

There are a few pre-requisites to be in place before creating Selenium RC scripts:

A Programming Language Java, C#, Python etc.

An Integrated Development Environment Eclipse, Netbeans etc.

A Testing Framework (optional) JUnit, TestNG etc.

And Selenium RC setup off course

Configuring Selenium RC using Eclipse


This tutorial describes Eclipse setup to use with Selenium. First download all the necessary
packages:
1. Download Java JDK from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Download Eclipse IDE for Java Developers :
http://www.eclipse.org/downloads/
3. Download and Install Selenium IDE firefox plugin(needs browser restart):
http://seleniumhq.org/download/
4. Download Selenium RC server and Selenium Client Drivers for Java
Selenium standalone server
http://seleniumhq.org/download/

Page 3 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

When all these packages are downloaded install first Java JDK. After install setup the
Environment
variables
(java
home,
path).
After that extract Eclipse to folder C:\ECLIPSE

After Eclipse, extract Selenium RC and Selenium Client Drivers to folder C:\SELENIUM

Page 4 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

Navigate url:https://www.eclipse.org/downloads/download.php?file=/oomph/epp/neon/R/eclipseinst-win64.exe
The next step is launching Eclipse(execute eclipse.exe from eclipse folder). After few seconds
there will be displayed a window. Here You can create a Workspace. Click on Browse and select
Your work location, make new folder (i.e. C:\ Selenium_JUnit) and click OK.

Page 5 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

Select any one and install (automatic installation will done)

Now You will be navigated to the Eclipse home screen. Click on Workbench

Page 6 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

The next step is Project creation. Click on File -> New -> Project. In wizard click on Java ->
Java Project. Click on Next.

On next screen fill the Project Name field, select Use default JRE and click on Finish.

After click on Finish, the Project will be created. On next window click on Yes and Your project
will be displayed at the left side.

By expanding the project the there will be displayed default src folder and under this folder
another folder JRE System Library. Here are listed the JRE system library files associated to
the project.
Next step is configuring the Selenium Client driver to this Project. Right Click on created project
at the left side. On new window select Build Path -> Configure Build Path. Click on Libraries tab
Page 7 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

and
after
click
on
Add
External
JARs
button.
Select Selenium Client Drivers from C:\SELENIUM folder (Selenium Server JAR file
should not be added) and Click on OK button. Now the build path is configured and the project
is ready to be used.

Right Click on src in package explorer and select New -> Other- > Java- > Package and
click on Next.

On next window You will create a new Java package. Enter Your package name into Name field
and click on Finish.

Page 8 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

The package is created and listed in explorer at the left side under the folder src.
Next step is adding a java class. Right Click on Package in package explorer and select New ->
Other > Java -> Class.

Click on the Next button and on next window fill the Name field and click on Finish. The .java
file is created.

Page 9 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

After

creation

of

first

class

or

test

run

selenium

server

from

Later write sample program to launch browser and site like below and execute

Page 10 of 16

cmd

prompt,

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

Selenium server and browser will launch like below,

Advantages and disadvantages of selenium RC:


Coming on to the advantages and disadvantages of selenium RC, refer the following figure.

Page 11 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

Selenium Grid
With selenium RC, life of a tester has always been positive and favorable until the emerging
trends raised a demand to execute same or different test scripts on multiple platforms and
browsers concurrently so as to achieve distributed test execution, testing under different
environments and saving execution time remarkably. Thus, catering these requirements selenium
grid was brought into the picture.
Selenium Grid was introduced by Pat Lightbody in order to address the need for executing the
test suites on multiple platforms simultaneously.

Install TestNG in Eclipse


It is easy to install TestNG, as it comes as a plugin for Eclipse IDE. Prerequisite for installing
TestNG is your Internet connection should be up & running during installation of this plugin and
Page 12 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

Eclipse IDE should be installed in your computer. Please see Download and Install Eclipse to
setup Eclipse to you system.
Steps to follow:
1) Launch the Eclipse IDE and from Help menu, click Install New Software.

2) You will see a dialog window, click Add button.

3) Type name as you wish, lets take TestNG and type http://beust.com/eclipse/ as location.
Click OK.
Page 13 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

4) You come back to the previous window but this time you must see TestNG option in the
available software list. Just Click TestNG and press Next button.

5) Click I accept the terms of the license agreement then click Finish.
6) You may or may not encounter a Security warning, if in case you do just click OK.
7) Click Next again on the succeeding dialog box until it prompts you to Restart the Eclipse.
8) You are all done now, just Click Yes.
9) Proceed with your workplace.

Page 14 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER

10) After restart, verify if TestNG was indeed successfully installed. Right click on you project
and see if TestNG is displayed in the opened menu.

Test NG suite Creation:


Steps:
1). Create multiple Test NG classes and run individually,
2). Refresh the project and observe test-out folder created,
3). Open index.html, itll open in eclipse win down and click on xml file
4). Xml file will be open at right side copy the xml content
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" name="Default suite">
<test verbose="2" name="Default test">
<classes>
<class name="webdriver.sample2"/>
</classes>
</test> <!-- Default test -->

</suite> <!-- Default suite -->

5).Create new file under the project and paste the above code and save it as testngsuite.xml and
modify that xml according to over need like below by adding other testing classes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" name="Default suite">
<test verbose="2" name="Default test">
<classes>
<class name="webdriver.sample2"/>
<class name="webdriver.sample3"/>
<class name="webdriver.sample"/>

Page 15 of 16

SUDHEER REDDY ANKIREDDYGARI (G)


SELENIUM WEB DRIVER
</classes>
</test> <!-- Default test -->

</suite> <!-- Default suite -->

6).Save the file and right click on the testingsute.xml file and run as testng class and observe all
the testing classes add to the testing file will execute one by one after completion of execution
refresh the project and click on emailable-report.html suite results will be displayed

Page 16 of 16

Das könnte Ihnen auch gefallen