Beruflich Dokumente
Kultur Dokumente
11/17/2014
Shiva Shanmugam
s.shiva@tcs.com
Confidentiality Statement
Include the confidentiality statement within the box provided. This has to be legally
approved
Confidentiality and Non-Disclosure Notice
The information contained in this document is confidential and proprietary to TATA
Consultancy Services. This information may not be disclosed, duplicated or used for any
other purposes. The information contained in this document may not be released in
whole or in part outside TCS for any purpose without the express written permission of
TATA Consultancy Services.
Table of Content
1.
Introduction ............................................................................................................................................................... 4
2.
Selenium ................................................................................................................................................................... 4
2.1
Selenium Features............................................................................................................................................ 4
2.2
2.2.1
2.2.2
Selenium RC ............................................................................................................................................... 6
2.2.3
2.2.4
1.
Introduction
Web Browser Automation is a process where certain steps in the web browser are performed repetitively
to ensure the correct operation of the web applications functionality.
With Web Browser Automation Tools it is possible to check accessibility and performance by
periodically running some transaction scenarios for certain services. The main purpose of these tools is to
record a specific transaction scenario for a browser, play it back by injecting JavaScript into web pages and
then to provide the corresponding results.
Why and When To Automate?
2.
Selenium
Selenium is a robust set of tools that supports rapid development of test automation for web-based
applications.
It provides a rich set of testing functions specifically geared to the needs of testing of a web application.
It operations are highly flexible, allowing many options for locating UI elements and comparing
expected test results against actual application behavior.
2.1 Selenium Features
Supports Cross Browser Testing. The Selenium tests can be run on multiple browsers.
Allows scripting in several languages like Java, C#, PHP and Python.
Assertion statements provide an efficient way of comparing expected and actual results.
Inbuilt reporting mechanism.
2.2.1
Selenium IDE
Now perform the operations on the application as you are testing the application.
Once you are done with the recording click on the stop recording button and save the test case
through the file menu. By default it will be saved as a selenese script (HTML format)
2.2.2
Selenium RC
Selenium Server
Selenium server receives selenium commands from the test program , interprets them, and report back to
the program the results of running those tests.
The Browser receives the selenese commands from Selenium server using simple HTTP GET/POST
requests.
We can use any programming languages that can send HTTP requests to automate selenium tests in the
browser.(pearl python etc..)
Selenium Client
Also known as Client Libraries(CL) provides a programming interface(API), is a set of functions , which
runs selenese commands from the program.
The CL takes the selenese command and passes it to the selenium server for processing and also receives
the result of the command and passes back to the program.
2.2.3
HtmlUnitDriver
FirefoxDriver
InternetExplorerDriver
Chrome Driver
OperaDriver
Fetching a Page
WebDriver navigates to a page by using get command by passsing URL. It will wait until the page
has fully loaded.
driver.get("http://www.google.com");
Popup Dialogs
There is built in support for handling popup dialog boxes.(alerts, confirms, prompts)
After youve triggered an action that opens a popup, you can access the alert with the following:
Alert alert = driver.switchTo().alert();
This will return the currently open alert object. With this object you can now accept, dismiss, read its
contents or even type into a prompt.
alert. accept();
alert. dismiss();
alert. getText();
alert. sendKeys(String keysToSend);
Execution
Follow below steps to execute web driver code from eclipse
From selenium IDE, File -> Export Test case -> Junit 4(Web Driver)
In Eclipse, Create a Class in Test script name inside a Package
Put the Test program inside the class
Download the selenium java client jar(http://www.seleniumhq.org/download/) and add to class
path
Right click on the program and select Run As -> Junit Test
2.2.4
Selenium Grid
Grid allows to
scale by distributing tests on several machines ( parallel execution )
manage multiple environments from a central point, making it easy to run the tests against a vast
combination of browsers / OS.
minimize the maintenance time for the grid by allowing you to implement custom hooks to leverage
virtual infrastructure for instance.
A grid consists of a single hub, and one or more nodes.Both are started using the selenium-server.jar
executable.
The Hub is the central point that will receive all the test request and distribute them to right nodes.
Open a command prompt and navigate to the directory where you copied the selenium-server-standalone
file.
Type the following command:
java -jar selenium-server-standalone-2.14.0.jar -role hub
The hub will automatically start-up using port 4444 by default. To change the default port, we can add
the optional parameter -port when we run the command.
We can view the status of the hub by opening a browser window and navigating to:
http://localhost:4444/grid/console
To start the node
Regardless on whether you want to run a grid with new WebDriver functionality, or a grid with
Selenium 1 RC functionality, or both at the same time, you use the same selenium-server-standalone jar file
to start the nodes.
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:4444/grid/register
Using grid to run tests
Configure RC node by
10
11
Contact
For more information, contact gsl.cdsfiodg@tcs.com (Email Id of ISU)
IT Services
Business Solutions
Consulting
All content / information present here is the exclusive property of Tata Consultancy Services Limited (TCS). The content /
information contained here is correct at the time of publishing. No material from here may be copied, modified, reproduced,
republished, uploaded, transmitted, posted or distributed in any form without prior written permission from TCS.
Unauthorized use of the content / information appearing here may violate copyright, trademark and other applicable laws,
and could result in criminal or civil penalties. Copyright 2011 Tata Consultancy Services Limited
12