Automation using
Selenium
Advanced Level Real-Time Training in
SELENIUM Testing Tool with
Complete Project Support.
Glister Technologies Solutions
•Introduction to Testing
Content of •Test - Automation Introduction
•Test-Automation Strategy
Selenium •Java Concepts , Core Java
•Overview of Selenium Components
•Selenium IDE & RC
•Selenium Web driver 2.0
•Selenium Grid
•Object Identification
•XPATH, Object Locators
•HTML,XML,CSS
•JUnit - Framework
•TestNG - Framework
•Selenium - Maven
•Selenium using Mobile
•Emulator & Simulator
•Selenium Automation for Android & IOS
•Real – Time Projects – Best Practise
•Continues Project Support.
Approach & Importance in Test-Automation
Record & Play back it’s not a
Complete Automation Testing.
Automation Strategy & Framework is
important in Test-Automation
Projects.
Our Automation Training Provided by
Test- Architect.
Customized Based Training using
Various Real Time – APPS.
End to End Framework based Training
with Real time Scenarios.
Automation Introduction
Automation is the integration of
testing tools into the test environment
in such a manner that the test
execution, logging, and comparison of
results are done with little human
intervention.
Atesting tool is a software application
which helps automate the testing
Process of Automation
Unstable softw are: If the softw are
is still under developm ent and
undergoing m any changes autom ation
testing w ill not be that
effective.
Once in a blue m oon test scripts:
Do not autom ate test scripts w hich
will be run once in a w hile.
Code and docum ent review : Do not
try to autom ate code and docum ent
Features of Automation
Testing workbenches provide a range
of tools to reduce the time required
and total testing costs.
Systems such as Junit support the
automatic execution of tests.
Most testing workbenches are open
systems because testing needs are
organisation-specific.
They are sometimes difficult to
Advantages of Automation Testing
Automated testing is cheaper.
Automated testing is faster.
Automated testing is more reliable.
Automated testing reduces human and
technical risks.
Automated testing is more powerful and
versatile.
Overview of Supported
Technologies
Java
JavaScript
HTML
CSS
Ant
XML
Locators
Java Concepts
Java is:
oplatform independent programming language
osimilar to C++ in syntax
osimilar to Smalltalk in mental paradigm
Pros: also ubiquitous to net
Cons: interpreted, and still under
development (moving target)
Java Features
Java has some interesting features:
oautomatic type checking,
oautomatic garbage collection,
osimplifies pointers; no directly accessible
pointer to memory,
osimplified network access,
omulti-threading!
Java Security
Pointer denial - reduces chances of
virulent programs corrupting host,
Applets even more restricted -
oMay not
run local executables,
Read or write to local file system,
Communicate with any server other than the
originating server.
How it works…!
Compile-time Compile-time Environment
Environment
Class
Loader Java
Class
Bytecode Libraries
Java Verifier
Source
(.java)
Just in
Java Java
Time
Bytecodes Interpreter Java
Compiler
move locally Virtual
or through machine
Java network
Compiler
Runtime System
Java Operating System
Bytecode
(.class )
Hardware
Object-Oriented
Java supports OOD
oPolymorphism
oInheritance
oEncapsulation
Javaprograms contain nothing but
definitions and instantiations of classes
oEverything is encapsulated in a class!
Java Advantages
Portable - Write Once, Run Anywhere
Security has been well thought through
Robust memory management
Designed for network programming
Multi-threaded (multiple simultaneous tasks)
Dynamic & extensible (loads of libraries)
o Classes stored in separate files
o Loaded only when needed
JavaScript
Browsers have limited functionality
◦ Text,
◦ images
◦ tables
◦ frames
JavaScript allows for interactivity
Browser/page manipulation
◦ Reacting to user actions
A type of programming language
◦ Easy to learn
◦ Developed by Netscape
Example Statements
<script language="JavaScript">
window.prompt('Enter your
name:','');
</script>
<form>
<input type="button"
Value="Press"
onClick="window.alert('Hello')
;">
</form>
Selenium Introduction
Test tool for web applications
Runs in any mainstream browser
Supports tests in many languages
Selenium(pure HTML, no backend
required)
Java, C#, Perl, Python, Ruby
Record/playback (Selenium IDE)
Open Source with corporate backing
Lives at selenium.openqa.org
What is Selenium?
Selenium automates browsers. Selenium
has the support of some of the largest
browser vendors who have taken (or are
taking) steps to make Selenium a native
part of their browser.
It is also the core technology in countless
other browser automation tools, APIs and
frameworks.
Why selenium?
Selenium is probably the best option for
automated testing of Websites today.
It is becoming increasingly popular and
it is the first choice of automation testers
as well as organizations for automating
the testing of Web-based applications for
both the GUI as well as the functionality.
Selenium can also be used as a unit
testing tool for JavaScript
You can use opensource.Selenium tool
selenium IDE is a plugin to firefox to
record and playback tests (like
WinRunner, QTP).
You can then export the recorded test in
most language e.g. html, Java , .net , perl ,
ruby etc. The exported test can be run in
any browser and any platform using
“selenium remote control”.
The following graph shows the popularity
of Selenium along with other open source
automation testing tools.
Advantages of Selenium
Free!
Can test across multiple browsers
Mimics actual user experience
Ajax / CSS support
Use language of choice
Large user community
Great tools: CubicTest, Grid, HRMES
Overview of Selenium Components
Selenium IDE - Plugin to Firefox to record and play test
in firefox and also export tests in different languages.
Selenium RC- Allows playing of exported test in
different platform/OS.
Selenium Grid -Allows to control lots of selenium
machines.
Selenium Web driver 2.0-Driving a browser natively as a
user would either locally or on a remote machine using
the Selenium Server it marks a leap forward in terms of
browser automation.
Selenium IDE
Easy record and playback.
Intelligent field selection will use IDs,
names, or XPath as needed.
Autocomplete for all common Selenium
commands.
Walk through tests.
Debug and set breakpoints.
Save tests as HTML, Ruby scripts, or any
other format. Support for Selenium user-
extensions.js file.
Option to automatically assert the title of
Setup:
o Open selenium IDE
o Go to Options -->Options
o Select WebDriver Tab
o Check the Enable WebDriver Play back check box
o In text box type firefox or internet explorer or
chrome Click OK
o Record a test case in Selenium IDE
Selenium RC
Selenium Remote Control (RC) is a server, written
in Java, that accepts commands for the browser via
HTTP.
RC makes it possible to write automated tests for a
web application in any programming language, which
allows for better integration of Selenium in existing unit
test frameworks.
To make writing tests easier, Selenium project currently
provides client drivers for PHP, Python, Ruby, .NET, Perl
and Java. The Java driver can also be used with JavaScript
(via the Rhino engine).
A new instance of selenium RC server is needed to
launch html test case - which means that the port
should be different for each parallel run.
However, for Java/PHP test case only one Selenium RC
instance needs to be running continuously.
Selenium Grid
Selenium-Grid allows you run your tests on
different machines against different
browsers in parallel.
That is, running multiple tests at the same
time against different machines running
different browsers and the operating
systems.
Essentially, Selenium-Grid support
distributed test execution.
It allows for running your tests in
a distributed test execution environment.
Generally speaking, there’s two reasons why
you might want to use Selenium-Grid.
To run your tests against multiple browsers, multiple
versions of browser, and browsers running on different
operating systems.
To reduce the time it takes for the test suite to complete a
test pass.
Selenium-Grid 2.0
Selenium-Grid 2.0 is the latest release as of the
writing of this document (5/26/2012).
It is quite different from version 1 of Selenium-
Grid. In 2.0 Selenium-Grid was merged with the
Selenium-RC server.
Now, you only need to download a single .jar file
to get the remote Selenium-RC-Server and
Selenium-Grid all in one package.
Selenium-Grid 1.0
Version 1 was the first general release of
Selenium-Grid.
If you are new to Selenium-Grid you should use
version 2. It’s been updated and has new features,
and supports Selenium-Web driver. Legacy test
systems may still be using version
Selenium IDE-RC-Grid
Selenium Web driver
Selenium Web Driver is the successor to
Selenium RC.
Selenium Web Driver accepts commands
(sent in Selenese, or via a Client API) and
sends them to a browser.
This is implemented through a browser-
specific browser driver, which sends
commands to a browser, and retrieves
results.
Most browser drivers actually launch and
access a browser application (such as
Firefox or Internet Explorer); there is also
an HtmlUnit browser driver, which
simulates a browser using HtmlUnit.
Unlike in Selenium 1, where the
Selenium RC server was necessary
to run tests, Selenium Web Driver
does not need a special server to
execute tests.
Instead, the Web Driver directly
starts a browser instance and
controls it. However, Selenium
Grid can be used with Web Driver
to execute tests on remote
systems.
Selenium IDE Selenium RC Webdriver
Works only on mozilla Works on almost all Works on latest
browsers.Does not work versions of almost all
on latest version of browsers - Firefox,
firefox/IE IE(6,7,8), OPera, Chrome
Record and run tool No Record and run No Record and run
No server required to Server is required to No server required to
start start start
Core engine is Core engine is Javascript Interacts natively with
Javascript based based browser application
Very simple to use. Its a simple and small API Complex and a bit large
API as compared to RC
Not at all object Less Object orinted API Purely Object oriented
oriented API
Cannot move mouse Cannot move mouse Can move mouse cursor
with it with it
Full xpaths have to be Full xpaths have to be No need to append
appended with appended with 'xapth=\\' 'xpath=\\'
'xapth=\\' syntax syntax
Object Identification
To identify the objects such as Links, Buttons, Edit
boxes, Drop downs, etc on the application Selenium
uses a concept called “Locators”.
There are around 8 different types of locators.
Out of them, explaining only four as they are widely
used while automating the test cases using Selenium.
1. id = id – By default Selenium IDE takes “id” as
Locator
Every Web Page will be having some HTML Source
code. This can be viewed using “View –> Page
Source / View source” on the browser. In the
following picture we can see “id” attribute of a
HTML tag is used as a locator to identify an object.
JUnit
JUnit is a fram ework for w riting
unit tests
A unit test is a test of a single
class
A test case is a single test of a
single m ethod
A test suite is a collection of
test cases
Unit testing is particularly
im portant w hen softw are requirem ents
change frequently
Code often has to be refactored to
JUnit is a unit testing framework for the
Java programming language.
JUnit has been important in the development of
test-driven development, and is one of a family
of unit testing frameworks collectively known as
xUnit that originated with JUnit.
Second, use this First, select a Test class
pulldown menu
Third, Run As JUnit
The Testing Problems
Should write
Do
programmers
few
Why?
I am so busy
It is difficult
45
TestNG
Automated testing framework
NG = Next Generation
Similar to JUnit (especially JUnit 4)
Not a JUnit extension (but inspired by JUnit)
Designed to be better than JUnit, especially
when testing integrated classes
Created by Dr. Cédric Beust (of Google)
Open source (http://testng.org)
Locators
Element Locators
ID: id=foo
Name: name=foo
First ID, then name: identifier=foo
DOM: document.forms[‘myform’].myDropdown
XPath: xpath=//table[@id='table1']//tr[4]/td[2]
Link Text: link=sometext
CSS Selector: css=a[href=“#id3”]
Sensible defaults, e.g. xpath if starts with //
selenium.click("btnG");
Element Filters
Element filters can be used with a locator
to refine a list of candidate elements. They
are currently used only in the 'name'
element-locator.
Filters look much like locators, ie.
filterType=argument Supported element-
filters are:
value=value Pattern
Matches elements based on their values.
This is particularly useful for refining a list
of similarly-named toggle-buttons .
index=index
String-match Patterns
Various Pattern syntaxes are available for matching string
values:
glob: pattern: Match a string against a "glob" (aka
"wildmat") pattern. "Glob" is a kind of limited regular-
expression syntax typically used in command-line shells. In
a glob pattern, "*" represents any sequence of characters,
and "?" represents any single character. Glob patterns
match against the entire string.
regexp: regexp: Match a string using a regular-
expression. The full power of JavaScript regular-
expressions is available.
exact: string: Match a string exactly, verbatim, without
any of that fancy wildcard stuff.
If no pattern prefix is specified, Selenium assumes that it's
a "glob" pattern.
Selenium-Maven
If you're using Maven, you will find all
Selenium Maven artifacts directly in the
central Maven repository
here: http://repo1.maven.org/maven2/org/
seleniumhq/selenium/
In order to start using Default
Selenium or one of the new Web
Driver implementations in your Maven
project, just add the following dependency
to your pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</gro
Overview of Selenium Maven artifacts
Selenium using Mobiles
Types of Mobile Testing
Emulator
Real device(tethered to workstation)
Real device in a real location on a real network
Selenium Automation for Android &
IOS
The Android Driver uses the RemoteWeb-Driver.
The client side is your test code(Java code).
The server side is an application that gets installed
on the android emulator or device.(android-
server.apk)
The client and the server communicate using the
Wire Protocol which consists of REST requests
JSON and HTTP.
The application executes the tests in the context of
an Android Web View.
UNPACK
~/android_sdk
UPDATE
$ cd~/andriod_sdk/tools
$ ./android update sdk
CREATE AVD
$ ./android create avd \
-n my_android \
-t 8 \
-c 100M
START EMULATOR
$ ./emulator -avd my_android \
-no-audio \
-no-boot- anim \
-scale .8 &
INSTALL SELENIUM APK
$ cd~/android_sdk/platform-tools/
$ ./adb -e install \
-r ~/selenium/android/prebuilt/android-
server.apk
PORT FORWARDING
$ ./adb forward tcp:8080 tcp:8080
LAUNCH APP
$ adb –s shell am start –n\
org.openga.selenium.android.app/
org.openga.selenium.android.app.Mainactivity
Sample Codings of Selenium
driver. get("http://www.google.com"); To open an application
driver.findElement(By.id("passwd-id")); Finding Element using Id
driver.findElement(By.name("passwd")); Finding Element using
Name
driver.findElement(By. Xpath("//input[@id=’passwd-
id’]")); Finding Element using Xpath
element.sendKeys("some text"); To type some data
element. clear(); clear the contents of a text field or text area
driver.findElement(By. Xpath("//select")); Selecting the value
findElement(By.id("submit")).click(); To click on Any
button/Link
driver.switchTo().window("window Name"); Moving from one
window to another window
driver.switchTo().frame("frame Name"); swing from frame to
frame (or into iframes)
driver.switchTo().frame("frameName.0.child"); to access sub
frames by separating the path with a dot, and you can specify the
frame by its index too.
driver.switchTo().alert(); Handling Alerts
driver. Navigate().to("http://www.example.com"); To Navigate
Particular URL
driver. Navigate().forward(); To Navigate Forward
driver. Navigate().back(); To Navigate Backward
driver. close() Closes the current window
driver. Quit() Quits the driver and closes every associated window.
driver.switch_to_alert() Switches focus to an alert on the page.
driver. Refresh() Refreshes the current page
driver.get_screenshot_as_file('/Screenshots/foo.png') The full
path you wish to save your screenshot to
driver.get_screenshot_as_base64() Gets the screenshot of the
current window as a base64 encoded string
select.findElements(By.tagName("option")); Selecting the
value
select.deselectAll(); This will deselect all OPTIONs from the first
SELECT on the page
select.selectByVisibleText("Edam"); select the OPTION with
the displayed text of “Edam”
Reach Us
Email:
[email protected]Web: www.thecreatingexperts.com
Powered By
Glister Tech – www.glistertech.com