Q #1) What Is Automation Testing?
Q #1) What Is Automation Testing?
Selenium is not just a single tool or a utility, rather a package of several testing
tools and for the same reason it is referred to as a Suite. Each of these tools is
designed to cater different testing and test environment requirements.
The suite package constitutes of the following sets of tools:
Q #5) What are the testing types that can be supported by Selenium?
Selenium supports the following types of testing:
1. Functional Testing
2. Regression Testing
Q #6) What are the limitations of Selenium?
Following are the limitations of Selenium:
Reports can only be generated using third party tools like TestNG or Junit.
As Selenium is a free tool, thus there is no ready vendor support though the
user can find numerous helping communities.
Feature
Selenium
IDE
Selenium RC
WebDriver
Browser
Compatibility
Selenium IDE
comes as a
Firefox
plugin, thus it
supports only
Firefox
Selenium RC
supports a
varied range
of versions of
Mozilla
Firefox,
Google
Chrome,
Internet
Explorer and
Opera
WebDriver
supports a
varied range
of versions of
Mozilla
Firefox,
Google
Chrome,
Internet
Explorer and
Opera.
Also supports
HtmlUnitDrive
r which is a
GUI less or
headless
browser.
Record and
Playback
Selenium IDE
supports
record and
playback
feature
Selenium RC
doesn't
supports
record and
playback
feature
WebDriver
doesn't
support
record and
playback
feature
Server
Requirement
Selenium IDE
doesn't
require any
server to be
started
before
executing the
test scripts
Selenium RC
requires
server to be
started before
executing the
test scripts
WebDriver
doesn't
require any
server to be
started before
executing the
test scripts
Architecture
Selenium IDE
is a Javascript
based
Selenium RC
is a JavaScript
based
WebDriver
uses the
browser's
Selenium
IDE
Selenium RC
WebDriver
framework
Framework
native
compatibility
to automation
Object
Oriented
Selenium IDE
is not an
object
oriented tool
Selenium RC
is semi object
oriented tool
WebDriver is
a purely
object
oriented tool
Dynamic
Finders
(for locating
web elements
on a
webpage)
Selenium IDE
doesn't
support
dynamic
finders
Selenium RC
doesn't
support
dynamic
finders
WebDriver
supports
dynamic
finders
Handling
Alerts,
Navigations,
Dropdowns
Selenium IDE
doesn't
explicitly
provides aids
to handle
alerts,
navigations,
dropdowns
Selenium RC
doesn't
explicitly
provides aids
to handle
alerts,
navigations,
dropdowns
WebDriver
offers a wide
range of
utilities and
classes that
helps in
handling
alerts,
navigations,
and
dropdowns
efficiently and
effectively.
WAP
(iPhone/Andro
id) Testing
Selenium IDE
doesn't
support
testing of
iPhone/Andrio
d
Selenium RC
doesn't
support
testing of
iPhone/Andrio
d applications
WebDriver is
designed in a
way to
efficiently
support
testing of
Feature
Feature
Selenium
IDE
Selenium RC
applications
WebDriver
iPhone/Androi
d
applications.
The tool
comes with a
large range of
drivers for
WAP based
testing.
For example,
AndroidDriver
,
iPhoneDriver
Listener
Support
Selenium IDE
doesn't
support
listeners
Selenium RC
doesn't
support
listeners
WebDriver
supports the
implementati
on of
Listeners
Speed
Selenium IDE
is fast as it is
plugged in
with the webbrowser that
launches the
test. Thus,
the IDE and
browser
communicate
s directly
Selenium RC
is slower than
WebDriver as
it doesn't
communicate
s directly with
the browser;
rather it
sends
selenese
commands
over to
Selenium
Core which in
turn
communicate
s with the
WebDriver
communicate
s directly with
the web
browsers.
Thus making
it much
faster.
Feature
Selenium
IDE
Selenium RC
WebDriver
browser.
Q #8) When should I use Selenium IDE?
Selenium IDE is the simplest and easiest of all the tools within the Selenium
Package. Its record and playback feature makes it exceptionally easy to learn with
minimal acquaintances to any programming language. Selenium IDE is an ideal tool
for a nave user.
Q #9) What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
Q #10) What are the different types of locators in Selenium?
Locator can be termed as an address that identifies a web element uniquely within
the webpage. Thus, to identify web elements accurately and precisely we
have different types of locators in Selenium:
ID
ClassName
Name
TagName
LinkText
PartialLinkText
Xpath
CSS Selector
DOM
Verify: Verify command also checks whether the given condition is true or false.
Irrespective of the condition being true or false, the program execution doesnt halts
i.e. any failure during verification would not stop the execution and all the test steps
would be executed.
Q #12) What is an Xpath?
Xpath is used to locate a web element based on its XML path. XML stands for
Extensible Markup Language and is used to store, organize and transport arbitrary
data. It stores data in a key-value pair which is very much similar to HTML tags.
Both being markup languages and since they fall under the same umbrella, Xpath
can be used to locate HTML elements.
The fundamental behind locating elements using Xpath is the traversing between
various elements across the entire page and thus enabling a user to find an element
with the reference of another element.
Q #13) What is the difference between / and // in Xpath?
Single Slash / Single slash is used to create Xpath with absolute path i.e. the
xpath would be created to start selection from the document node/start node.
Double Slash // - Double slash is used to create Xpath with relative path i.e. the
xpath would be created to start selection from anywhere within the document.
Q #14) What is Same origin policy and how it can be handled?
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:// http://www.softwaretestinghelp.com/resources/, the origin
is a combination of http, softwaretestinghelp.com, 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.softwaretestinghelp.com, then I would be
able to access the pages within the same domain such as
http://www.softwaretestinghelp.com/resources or
http://www.softwaretestinghelp.com/istqb-free-updates/. The other domains like
google.com, seleniumhq.org would no more be accessible.
So, In order to handle same origin policy, Selenium Remote Control was introduced.
Q #15) When should I use Selenium Grid?
Selenium Grid can be used 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.
Q #16) What do we mean by Selenium 1 and Selenium 2?
Selenium RC and WebDriver, in a combination are popularly known as Selenium 2.
Selenium RC alone is also referred as Selenium 1.
Q #17) Which is the latest Selenium tool?
WebDriver
Q #18) How do I launch the browser using WebDriver?
The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
Q #19) What are the different types of Drivers available in WebDriver?
The different drivers available in WebDriver are:
FirefoxDriver
InternetExplorerDriver
ChromeDriver
SafariDriver
OperaDriver
AndroidDriver
IPhoneDriver
HtmlUnitDriver
script. Thus, subsequent test step would only execute when the 30 seconds have
elapsed after executing the previous test step/command.
Explicit Wait: Explicit waits are used to halt the execution till the time a particular
condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit
waits are applied for a particular instance only.
Q #21) How to type in a textbox using Selenium?
User can use sendKeys(String to be entered) to enter the string in the textbox.
Syntax:
WebElement username = drv.findElement(By.id(Email));
// entering username
username.sendKeys(sth);
Q #22) How can you find if an element in displayed on the screen?
WebDriver facilitates the user with the following methods to check the visibility of
the web elements. These web elements can be buttons, drop boxes, checkboxes,
radio buttons, labels etc.
1. isDisplayed()
2. isSelected()
3. isEnabled()
Syntax:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(gbqfba)).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id(gbqfba)).isDisplayed();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(gbqfb)).isEnabled();
Q #23) How can we get a text of a web element?
Get command is used to retrieve the inner text of the specified web element. The
command doesnt require any parameter but returns a string value. It is also one of
the extensively used commands for verification of messages, labels, errors etc
displayed on the web pages.
Syntax:
String Text = driver.findElement(By.id(Text)).getText();
The command finds the element using link text and then click on that element and
thus the user would be re-directed to the corresponding page.
The above mentioned link can also be accessed by using the following command.
driver.findElement(By.partialLinkText(Goo)).click();
The above command find the element based on the substring of the link provided in
the parenthesis and thus partialLinkText() finds the web element with the specified
substring and then clicks on it.
Q #27) How to handle frame in WebDriver?
An inline frame acronym as iframe is used to insert another document with in the
current HTML document or simply a web page into a web page by enabling nesting.
Select iframe by id
driver.switchTo().frame(ID of the frame);
Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName(iframe).get(0));
Locating iframe using index
frame(index)
driver.switchTo().frame(0);
-----------frame(Name of Frame)
driver.switchTo().frame(name of the frame);
frame(WebElement element)
Select Parent Window
driver.switchTo().defaultContent();
Q #28) When do we use findElement() and findElements()?
findElement(): findElement() is used to find the first element in the current web
page matching to the specified locator value. Take a note that only first matching
element would be fetched.
Syntax:
WebElement element
=driver.findElements(By.xpath(//div[@id=example]//ul//li));
findElements(): findElements() is used to find all the elements in the current web
page matching to the specified locator value. Take a note that all the matching
elements would be fetched and stored in the list of WebElements.
Syntax:
List <WebElement> elementList
=driver.findElements(By.xpath(//div[@id=example]//ul//li));
Q #29) How to find more than one web element in the list?
At times, we may come across elements of same type like multiple hyperlinks,
images etc arranged in an ordered or unordered list. Thus, it makes absolute sense
to deal with such elements by a single piece of code and this can be done using
WebElement List.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
void dismiss() The accept() method clicks on the Cancel button as soon as
the pop up window appears.
void accept() The accept() method clicks on the Ok button as soon as the
pop up window appears.
String getText() The getText() method returns the text displayed on the alert
box.
Syntax:
// accepting javascript alert
Alert alert = driver.switchTo().alert();
alert.accept();
Q #33) How can we handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing,
that means, it doesnt support testing of windows based applications. However
Selenium alone cant help the situation but along with some third party
intervention, this problem can be overcome. There are several third party tools
available for handling window based pop ups along with the selenium like AutoIT,
Robot class etc.
Q #34) How to assert title of the web page?
//verify the title of the web page
assertTrue(The title of the window is incorrect.,driver.getTitle().equals(Title of the
page));
Q #35) How to mouse hover on a web element using WebDriver?
WebDriver offers a wide range of interaction utilities that the user can exploit to
automate mouse and keyboard events. Action Interface is one such utility which
simulates the single user interactions.
Thus, In the following scenario, we have used Action Interface to mouse hover on a
drop down which then opens a list of options.
Sample Code:
1
2
3
4
5
6
7
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
10
import org.openqa.selenium.firefox.FirefoxDriver;
11
12
13
WebDriver driver;
14
@Before
15
16
17
driver.get("https://google.com");
18
19
@After
20
21
driver.quit();
22
23
24
@Test
25
26
27
28
29
30
31
@Test: Annotation lets the system know that the method annotated as @Test
is a test method. There can be multiple test methods in a single test script.
@Before: Method annotated as @Before lets the system know that this
method shall be executed every time before each of the test method.
@After: Method annotated as @After lets the system know that this method
shall be executed every time after each of the test method.
@Ignore: Method annotated as @Ignore lets the system know that this
method shall not be executed.
package TestNG;
import org.testng.annotations.*;
@Test(priority=0)
@Test(priority=1)
10
@Test(priority=2)
11
12
13
Reusability of code
Maximum coverage
Recovery scenario
Easy Reporting
# JXL jar
POI jar
POI is regularly
updated and released
Feature
Selenium
Browser
Compatibili
ty
Selenium supports
almost all the popular
browsers like Firefox,
Chrome, Safari,
Internet Explorer,
Opera etc
Distribution
Selenium is distributed
as an open source tool
and is freely available
QTP is distributed as
a licensed tool and is
commercialized
Application
under Test
Selenium supports
testing of only web
based applications
Feature
Selenium
Quick Test
Professional (QTP)
windows based
application
Object
Repository
Object Repository
needs to be created as
a separate entity
QTP automatically
creates and
maintains Object
Repository
Language
Support
Selenium supports
multiple programming
languages like Java,
C#, Ruby, Python, Perl
etc
Vendor
Support
As Selenium is a free
tool, user would not
get the vendors
support in
troubleshooting issues