100% found this document useful (1 vote)
462 views

Test Automation and Advanced Selenium-CombinedBook

The document discusses test automation and the Selenium framework. It covers topics around the benefits of test automation such as increased speed, reduced costs, improved quality. It also discusses Selenium and its use for automating web application testing.

Uploaded by

Rajendra P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
462 views

Test Automation and Advanced Selenium-CombinedBook

The document discusses test automation and the Selenium framework. It covers topics around the benefits of test automation such as increased speed, reduced costs, improved quality. It also discusses Selenium and its use for automating web application testing.

Uploaded by

Rajendra P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 215

Test Automation & Advanced Selenium

©2016 Capgemini. All rights reserved.


The information contained in this document is proprietary and confidential. For
Capgemini only.

Page 0-1
Test Automation & Advanced Selenium

Page 0-2
Test Automation & Advanced Selenium

Page 0-3
Test Automation & Advanced Selenium

Page 0-4
Test Automation & Advanced Selenium

Page 0-5
Test Automation & Advanced Selenium

Page 0-6
Test Automation & Advanced Selenium

Page 0-7
Test Automation & Advanced Selenium

Page 0-8
Test Automation & Advanced Selenium

Page 0-9
Test Automation & Advanced Selenium

Page 0-10
Test Automation & Advanced Selenium

Page 0-11
Test Automation & Advanced Selenium

Page 0-12
Test Automation & Advanced Selenium

Page 0-13
Test Automation & Advanced Selenium

Page 0-14
Test Automation & Advanced Selenium

Page 0-15
Test Automation & Advanced Selenium

Page 0-16
Test Automation & Advanced Selenium

Page 0-17
Test Automation & Advanced Selenium

Page 0-18
Test Automation & Advanced Selenium

Page 0-19
Test Automation & Advanced Selenium

Page 0-20
Test Automation & Advanced Selenium Introduction to Automation

Page 01-1
Test Automation & Advanced Selenium Introduction to Automation

Page 01-2
Test Automation & Advanced Selenium Introduction to Automation

Page 01-3
Test Automation & Advanced Selenium Introduction to Automation

Automation is the linking of disparate systems and software in such a way that they
become self-acting or self-regulating.

Page 01-4
Test Automation & Advanced Selenium Introduction to Automation

Page 01-5
Test Automation & Advanced Selenium Introduction to Automation

Test Automation and its Benefits:

Why automate Testing?


In today´s fast moving world, it is a challenge for any company to
continuously maintain and improve the quality and efficiency of
software systems development. In many software projects, testing is
neglected because of time or cost constraints. This leads to a lack of
product quality, followed by customer dissatisfaction and ultimately to
increased overall quality costs.

The main reasons for these added costs are primarily:


1.poor test strategy
2.underestimated effort of test case generation
3.delay in testing
4.subsequent test maintenance

Test automation can improve the development process of a software


product in many cases. The automation of tests is initially associated
with increased effort, but the related benefits will quickly pay off.
Automated tests can run fast and frequently, which is cost-effective
for software products with a long maintenance life. When testing in an
agile environment, the ability to quickly react to ever-changing
software systems and requirements is necessary. New test cases are
generated continuously and can be added to existing automation in
parallel to the development of the software itself.
In both manual and automated testing environments test cases need
to be modified for extended periods of time as the software project
progresses. It is important to be aware that complete coverage of all
tests using test automation is unrealistic. When deciding what tests to
automate first, their value vs. the effort to create them needs to be
considered. Test cases with high value and low effort should be
automated first. Subsequently test cases with frequent use, changes,
and past errors; as well as test cases with low to moderate effort in
setting up the test environment and developing the automation project
are best suited for automation.

Page 01-6
Test Automation & Advanced Selenium Introduction to Automation

Optimization of Speed, Efficiency, Quality and the Decrease


of Costs:
The main goal in software development processes is a
timely release. Automated tests run fast and frequently, due
to reused modules within different tests. Automated
regression tests which ensure the continuous system
stability and functionality after changes to the software were
made lead to shorter development cycles combined with
better quality software and thus the benefits of automated
testing quickly outgain the initial costs.

Advance a Tester´s Motivation and Efficiency:


Manual testing can be mundane, error-prone and therefore
become exasperating. Test automation alleviates testers'
frustrations and allows the test execution without user
interaction while guaranteeing repeatability and accuracy.
Instead testers can now concentrate on more difficult test
scenarios.

Increase of Test Coverage:


Sufficient test coverage of software projects is often
achieved only with great effort. Frequent repetition of the
same or similar test cases is laborious and time consuming
to perform manually.

Some examples are:


Regression test after debugging or further development of
software
Testing of software on different platforms or with different
configurations
Data-driven testing (creation of tests using the same
actions but with many different inputs)
Test automation allows performing different types of testing
efficiently and effectively.

Page 01-7
Test Automation & Advanced Selenium Introduction to Automation

Add the notes here.

Page 01-8
Test Automation & Advanced Selenium Introduction to Automation

In Above example “Add Users With Valid Data”

To execute the test case, we need to login to the application. We also need to check
if the user is already logged in or not. And the other we need to check is if the
logged in person is having access to “Add Users” or Not. If the above Two
Conditions are passed then we should execute the rest Else we should return the
test as failed.

Page 01-9
Test Automation & Advanced Selenium Introduction to Automation

Add the notes here.

Page 01-10
Test Automation & Advanced Selenium Introduction to Automation

Page 01-11
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-1
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-2
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-3
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-4
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-5
Test Automation & Advanced Selenium Introduction to Selenium

Add the notes here.

Page 02-6
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-7
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-8
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-9
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-10
Test Automation & Advanced Selenium Introduction to Selenium

Add the notes here.

Page 02-11
Test Automation & Advanced Selenium Introduction to Selenium

Page 02-12
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-1
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-2
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-3
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-4
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-5
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-6
Test Automation & Advanced Selenium Working With Selenium IDE

1.File Menu

It is very much analogous to the file menu belonging to any other application.
Export Test Case As and Export Test Suite give the liberty to the user to prefer
amid the available unit testing frameworks like jUnit, TestNG etc.
Thus an IDE test case can be exported for a chosen union of programming
language, unit testing framework and tool from the selenium package.

Page 03-7
Test Automation & Advanced Selenium Working With Selenium IDE

The Selenium IDE test cases can be saved into following format:
HTML format
The Selenium IDE test cases can be exported into following formats/programming
languages.
java (IDE exported in Java)
rb (IDE exported in Ruby)
py (IDE exported in Python)
cs (IDE exported in C#)

Page 03-8
Test Automation & Advanced Selenium Working With Selenium IDE

The Selenium IDE test cases can be saved into following format:
HTML format
The Selenium IDE test cases can be exported into following formats/programming
languages.
java (IDE exported in Java)
rb (IDE exported in Ruby)
py (IDE exported in Python)
cs (IDE exported in C#)

Page 03-9
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-10
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-11
Test Automation & Advanced Selenium Working With Selenium IDE

Log/Reference/UI-Element/Rollup Pane
The bottom pane is used for four different functions–Log, Reference, UI-Element,
and Rollup–depending on which tab is selected.

Log
When you run your test case, error messages and information messages showing
the progress are displayed in this pane automatically, even if you do not first select
the Log tab. These messages are often useful for test case debugging. Notice the
Clear button for clearing the Log. Also notice the Info button is a drop-down allowing
selection of different levels of information to log.

Reference
The Reference tab is the default selection whenever you are entering or modifying
Selenese commands and parameters in Table mode. In Table mode, the Reference
pane will display documentation on the current command. When entering or
modifying commands, whether from Table or Source mode, it is critically important
to ensure that the parameters specified in the Target and Value fields match those
specified in the parameter list in the Reference pane. The number of parameters
provided must match the number specified, the order of parameters provided must
match the order specified, and the type of parameters provided must match the type
specified. If there is a mismatch in any of these three areas, the command will not
run correctly.

While the Reference tab is invaluable as a quick reference, it is still often necessary
to consult the Selenium Reference document.

Page 03-12
Test Automation & Advanced Selenium Working With Selenium IDE

Action:
Used to change the state of the AUT(Application under Test)like click on some link,
type a value in edit box, select some options on the page, select a value from drop
down etc.
When action is performed on AUT the test will fail if the action is not achieved.

Accessor:
This command check the state of the application and save the application state in
some variable. It can be used for automatic generation of assertions.

Assertions:
Are very similar to checkpoint in UFT/QTP. Assertion verifies the state of the
application matches it with the expected state and generates the True/False result.

Page 03-13
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-14
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-15
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-16
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-17
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-18
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-19
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-20
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-21
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-22
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-23
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-24
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-25
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-26
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-27
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-28
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-29
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-30
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-31
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-32
Test Automation & Advanced Selenium Working With Selenium IDE

Add the notes here.

Page 03-33
Test Automation & Advanced Selenium Working With Selenium IDE

Page 03-34
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-1
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-2
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-3
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-4
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

1. Architecture
WebDriver's architecture is simpler than Selenium RC's.

It controls the browser from the OS level


All you need are your programming language's IDE (which contains your Selenium
commands) and a browser.
You first need to launch a separate application called Selenium Remote Control
(RC) Server before you can start testing
The Selenium RC Server acts as a "middleman" between your Selenium
commands and your browser
When you begin testing, Selenium RC Server "injects" a Javascript program called
Selenium Core into the browser.
Once injected, Selenium Core will start receiving instructions relayed by the RC
Server from your test program.
When the instructions are received, Selenium Core will execute them as Javascript
commands.
The browser will obey the instructions of Selenium Core, and will relay its response
to the RC Server.
The RC Server will receive the response of the browser and then display the
results to you.
RC Server will fetch the next instruction from your test script to repeat the whole
cycle.

Page 04-5
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

2. Speed
WebDriver is faster than Selenium RC since it speaks directly to the
browser uses the browser's own engine to control it.

• Selenium RC is slower since it uses a Javascript program called


Selenium Core. This Selenium Core is the one that directly controls the
browser, not you.

3. Real-life Interaction
WebDriver interacts with page elements in a more realistic way. For
example, if you have a disabled text box on a page you were testing,
WebDriver really cannot enter any value in it just as how a real person
cannot.

• Selenium Core, just like other Javascript codes, can access disabled
elements. In the past, Selenium testers complain that Selenium Core
was able to enter values to a disabled text box in their tests. Differences
in API

4. API
Selenium RC's API is more matured but contains redundancies and often
confusing commands.

• For example, most of the time, testers are confused whether to use type
or typeKeys; or whether to use click, mouseDown, or mouseDownAt.
Worse, different browsers interpret each of these commands in different
ways tool
• WebDriver's API is simpler than Selenium RC's. It does not contain
redundant and confusing commands.

5. Browser Support
WebDriver can support the headless HtmlUnit browser

• HtmlUnit is termed as "headless" because it is an invisible browser - it is


GUI-less.
• It is a very fast browser because no time is spent in waiting for page
elements to load. This accelerates your test execution cycles.
• Since it is invisible to the user, it can only be controlled through
automated means.
• Selenium RC cannot support the headless HtmlUnit browser. It needs a
real, visible browser to operate on.

Page 04-6
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-7
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Add the notes here.

Page 04-8
Test Automation & Advanced Selenium Selenium 2.0 – Web Driver

Page 04-9
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-1
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-2
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-3
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-4
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-5
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-6
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-7
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-8
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Single-Page Applications are an exception to this.


The difference between these two methods comes not from their behavior, but from
the behavior in the way the application works and how browser deal with it.
navigate().to() navigates to the page by changing the URL like doing
forward/backward navigation.
Whereas, get() refreshes the page to changing the URL.
So, in cases where application domain changes, both the method behaves
similarly. That is, page is refreshed in both the cases. But, in single-page
applications, while navigate().to() do not refreshes the page, get() do.
Moreover, this is the reason browser history is getting lost when get() is used due
to application being refreshed.

Page 05-9
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-10
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-11
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-12
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-13
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

CSS selectors for Selenium with example


When we don't have an option to choose Id or Name, we should prefer using CSS
locators as the best alternative.
CSS is "Cascading Style Sheets" and it is defined to display HTML in structured
and colorful styles are applied to webpage.
Selectors are patterns that match against elements in a tree, and as such form one
of several technologies that can be used to select nodes in an XML document. Visit
to know more W3.Org Css selectors
CSS has more Advantage than Xpath
CSS is much more faster and simpler than the Xpath.
In IE Xpath works very slow, where as Css works faster when compared to Xpath.

Page 05-14
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Click():
Click a link / button:
To click on an object through webdriver first we need to find out which locator we
are going to use. Is it ID, name, xpath, or css? For this purpose we can utilize
firebug / xpath checker to find out is there any id / name exists for the object we are
going to perform action upon. Then write the code as below:
driver.findElement(By.xpath("//a[@href='CustomerInfo.htm']")).click();
In the above line of code “driver” could be FirefoxDriver, InternetExplorerDriver,
ChromeDriver, HtmlUnitDriver, etc. On one of these browsers we are going to find
an element and then click as per the code.
findElement is an API provided by the webdriver which requires argument
“By.xpath”. The “xpath” can be replaced by one of the below methods if we need to
identify the element with any other attributes such as css, name, classname, etc.

“Check / Uncheck “ a checkbox


To “Check / Uncheck” a checkbox, the object needs to be identified using
findElement method and then just click. To find out whether the checkbox is
checked or not utilize the method – element.isSelected()
WebElement kancheck = driver.findElement(By.name("kannada"));
kancheck.click();
System.out.println(kancheck.isSelected());
Above code snippet will first click the checkbox named kannada and then verifies
whether it is clicked or not.

Page 05-15
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Click():
Click a link / button:
To click on an object through webdriver first we need to find out which locator we
are going to use. Is it ID, name, xpath, or css? For this purpose we can utilize
firebug / xpath checker to find out is there any id / name exists for the object we are
going to perform action upon. Then write the code as below:
driver.findElement(By.xpath("//a[@href='CustomerInfo.htm']")).click();
In the above line of code “driver” could be FirefoxDriver, InternetExplorerDriver,
ChromeDriver, HtmlUnitDriver, etc. On one of these browsers we are going to find
an element and then click as per the code.
findElement is an API provided by the webdriver which requires argument
“By.xpath”. The “xpath” can be replaced by one of the below methods if we need to
identify the element with any other attributes such as css, name, classname, etc.

“Check / Uncheck “ a checkbox


To “Check / Uncheck” a checkbox, the object needs to be identified using
findElement method and then just click. To find out whether the checkbox is
checked or not utilize the method – element.isSelected()
WebElement kancheck = driver.findElement(By.name("kannada"));
kancheck.click();
System.out.println(kancheck.isSelected());
Above code snippet will first click the checkbox named kannada and then verifies
whether it is clicked or not.

Page 05-16
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Select a radio button


Follow the same steps which are used in Checkbox to select a radio button and
then verify the status using isSelected() method.
WebElement gender =
driver.findElement(By.xpath("//input[@name='male']"));
gender.click();
System.out.println(gender.isSelected());

Clear();
The clear() method executes an "Automation Atom", which is a JavaScript
function intended to provide the smallest basic unit of automation
functionality for a browser. In the case of clear(), that function sets the
value property of the element to an empty string (''), then fires the
onchange event on the element. The atoms function you're interested in is
bot.action.clear()
click
clear
sendKeys
submit
Select – selectByVisibleText etc.
getText
getAttribute

Page 05-17
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

When to use .click() method


You can use .click() method to click on any button of software web application.
Means element's type = "button" or type = "submit", .click() method will works for
both.

When to use .submit() method


If you will look at firebug view for any form's submit button then always It's type will
be "submit". In this case, .submit() method Is very good alternative of .click()
method.

Page 05-18
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Method Name: selectByIndex


Purpose: To Select the option based on the index given by the user.
There is an attribute called "values" which will have the index values.
Example:
WebElement element=driver.findElement(By.name("Mobiles"));
Select se=new Select(element);
se.selectByIndex(1);

Method Name: selectByValue


Purpose: To Select the options that have a value matching with the given
argument by the user.
Example:
WebElement element=driver.findElement(By.name("Mobiles"));
Select se=new Select(element);
se.selectByValue("nokia");

Method Name: selectByVisibleText


Purpose: To Select all options that display text matching the given argument. It will
not look for any index or value, it will try to match the VisibleText (which will display
in dropdown)
Example:
WebElement element=driver.findElement(By.name("Mobiles"));
Select se=new Select(element);
se.selectByVisibleText("HTC");

Page 05-19
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Method Name: deselectByIndex


Purpose: To Deselect the option at the given index. The user has to provide the
value of index.
Example:
se.deselectByIndex(1);

Method Name: deselectByValue


Purpose: To Deselect all options that have a value matching the given argument.
Example:
se.deselectByValue("nokia");

Method Name: deselectByVisibleText


Purpose: To Deselect all options that display text matching the given argument.
Example:
se.deselectByVisibleText("HTC");

Method Name: deselectAll


Purpose: To Clear all selected entries. This works only when the SELECT supports
multiple selections. It throws NotImplemented eError if the "SELECT" does not
support multiple selections. In select it mandatory to have an attribute
multiple="multiple“
Example:
se.deselectAll();

Page 05-20
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

When to use .click() method


You can use .click() method to click on any button of software web application.
Means element's type = "button" or type = "submit", .click() method will works for
both.

When to use .submit() method


If you will look at firebug view for any form's submit button then always It's type will
be "submit". In this case, .submit() method Is very good alternative of .click()
method.

Page 05-21
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Simple alert
Simple alerts just have a OK button on them. They are mainly used to display some
information to the user.

Confirmation Alert
This alert comes with an option to accept or dismiss the alert. To accept the alert
you can use Alert.accept() and to dismiss you can use the Alert.dismiss().

Prompt Alerts
In prompt alerts you get an option to add text to the alert box. This is specifically
used when some input is required from the user. We will use
the sendKeys() method to type something in the Prompt alert box.

Page 05-22
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Steps for understanding window handling:

Window A has a link "Link1" and we need to click on the link (click event).
Window B displays and we perform some actions.

The entire process can be fundamentally segregated into following steps:


Step 1 : Clicking on Link1 on Window A
A new Window B is opened.
Step 2 : Save reference for Window A
Step 3 : Create reference for Window B
Step 4 : Move Focus from Window A to Window B
Window B is active now
Step 5 : Perform Actions on Window B
Complete the entire set of Actions
Step 6 : Move Focus from Window B to Window A
Window A is active now

Page 05-23
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Alerts are different from regular windows. The main difference is that alerts are
blocking in nature. They will not allow any action on the underlying webpage if they
are present. So if an alert is present on the webpage and you try to access any of
the element in the underlying page you will get following exception:
UnhandledAlertException: Modal dialog present

Page 05-24
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-25
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Synchronization can be classified into two categories:

1. Unconditional
2. Conditional Synchronization

Unconditional :
In this we just specify timeout value only. We will make the tool to wait until certain
amount of time and then proceed further.
Examples: Wait() and Thread.Sleep();

The main disadvantage for the above statements are, there is a chance of
unnecessary waiting time even though the application is ready.

The advantages are like in a situation where we interact for third party systems like
interfaces, it is not possible to write a condition or check for a condition. Here in this
situations, we have to make the application to wait for certain amount of time by
specifying the timeout value.

Conditional Synchronization:
We specify a condition along with timeout value, so that tool waits to check for the
condition and then come out if nothing happens.
It is very important to set the timeout value in conditional synchronization, because
the tool should proceed further instead of making the tool to wait for a particular
condition to satisfy.

In Selenium we have implicit Wait and Explicit Wait conditional statements

Page 05-26
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page Load Synchronization:


Default page navigation timeout can be set.
Below statement will set the navigation timeout as 50
Means that selenium script will wait for maximum 50 seconds for page to
load
If page does not load within 50 seconds, it will throw an exception
Syntax
driver.manage().timeouts().pageLoadTimeout(50,TimeUnit.SECONDS);

Page 05-27
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-28
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-29
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-30
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-31
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-32
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Add the notes here.

Page 05-33
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Add the notes here.

Page 05-34
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Page 05-35
Test Automation & Advanced Selenium Testing Web Applications Using Web Driver API

Answer 1:
True

Answer 2:
Javascript

Page 05-36
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-1
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-2
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-3
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-4
Test Automation & Advanced Selenium Web Driver Test with Xunit

A research survey performed in 2013 across 10,000 Java projects hosted on


GitHub found that JUnit, (in a tie with slf4j-api), was the most commonly included
external library. Each library was used by 30.7% of projects.

Page 06-5
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-6
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-7
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-8
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-9
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-10
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-11
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-12
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-13
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-14
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-15
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-16
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-17
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-18
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-19
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-20
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-21
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-22
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-23
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-24
Test Automation & Advanced Selenium Web Driver Test with Xunit

Aggregating tests in suites:


Using Suite as a runner allows you to manually build a suite containing tests from
many classes. It is the JUnit 4 equivalent of the JUnit 3.8.x static Test suite()
method. To use it, annotate a class with @RunWith(Suite.class) and
@SuiteClasses(TestClass1.class, ...). When you run this class, it will run all the
tests in all the suite classes.

Example:
The class above is a placeholder for the suite annotations, no other implementation
is required.
Note : @RunWith annotation, which specifies that the JUnit 4 test runner to use is
org.junit.runners.Suite for running this particular test class. This works in
conjunction with the @Suite annotation, which tells the Suite runner which test
classes to include in this suite and in which order.

Page 06-25
Test Automation & Advanced Selenium Web Driver Test with Xunit

We need to specify the class names along with packages in between the classes
tags.
All the classes specified in the xml will get executes which have TestNG
annotations.

Page 06-26
Test Automation & Advanced Selenium Web Driver Test with Xunit

Add the notes here.

Page 06-27
Test Automation & Advanced Selenium Web Driver Test with Xunit

Page 06-28
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-1
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-2
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-3
Test Automation & Advanced Selenium Selenium Web Driver – Advance

1. Architecture
WebDriver's architecture is simpler than Selenium RC's.

It controls the browser from the OS level


All you need are your programming language's IDE (which contains your Selenium
commands) and a browser.
You first need to launch a separate application called Selenium Remote Control
(RC) Server before you can start testing
The Selenium RC Server acts as a "middleman" between your Selenium commands
and your browser
When you begin testing, Selenium RC Server "injects" a Javascript program called
Selenium Core into the browser.
Once injected, Selenium Core will start receiving instructions relayed by the RC
Server from your test program.
When the instructions are received, Selenium Core will execute them as Javascript
commands.
The browser will obey the instructions of Selenium Core, and will relay its response
to the RC Server.
The RC Server will receive the response of the browser and then display the results
to you.
RC Server will fetch the next instruction from your test script to repeat the whole
cycle.

Page 07-4
Test Automation & Advanced Selenium Selenium Web Driver – Advance

2. Speed
WebDriver is faster than Selenium RC since it speaks directly to the
browser uses the browser's own engine to control it.

• Selenium RC is slower since it uses a Javascript program called


Selenium Core. This Selenium Core is the one that directly controls the
browser, not you.

3. Real-life Interaction
WebDriver interacts with page elements in a more realistic way. For
example, if you have a disabled text box on a page you were testing,
WebDriver really cannot enter any value in it just as how a real person
cannot.

• Selenium Core, just like other Javascript codes, can access disabled
elements. In the past, Selenium testers complain that Selenium Core
was able to enter values to a disabled text box in their tests. Differences
in API

4. API
Selenium RC's API is more matured but contains redundancies and often
confusing commands.

• For example, most of the time, testers are confused whether to use type
or typeKeys; or whether to use click, mouseDown, or mouseDownAt.
Worse, different browsers interpret each of these commands in different
ways tool
• WebDriver's API is simpler than Selenium RC's. It does not contain
redundant and confusing commands.

5. Browser Support
WebDriver can support the headless HtmlUnit browser

• HtmlUnit is termed as "headless" because it is an invisible browser - it is


GUI-less.
• It is a very fast browser because no time is spent in waiting for page
elements to load. This accelerates your test execution cycles.
• Since it is invisible to the user, it can only be controlled through
automated means.
• Selenium RC cannot support the headless HtmlUnit browser. It needs a
real, visible browser to operate on.

Page 07-5
Test Automation & Advanced Selenium Selenium Web Driver – Advance

1. Architecture
WebDriver's architecture is simpler than Selenium RC's.

It controls the browser from the OS level


All you need are your programming language's IDE (which contains your Selenium
commands) and a browser.
You first need to launch a separate application called Selenium Remote Control
(RC) Server before you can start testing
The Selenium RC Server acts as a "middleman" between your Selenium commands
and your browser
When you begin testing, Selenium RC Server "injects" a Javascript program called
Selenium Core into the browser.
Once injected, Selenium Core will start receiving instructions relayed by the RC
Server from your test program.
When the instructions are received, Selenium Core will execute them as Javascript
commands.
The browser will obey the instructions of Selenium Core, and will relay its response
to the RC Server.
The RC Server will receive the response of the browser and then display the results
to you.
RC Server will fetch the next instruction from your test script to repeat the whole
cycle.

Page 07-6
Test Automation & Advanced Selenium Selenium Web Driver – Advance

2. Speed
WebDriver is faster than Selenium RC since it speaks directly to the
browser uses the browser's own engine to control it.

• Selenium RC is slower since it uses a Javascript program called


Selenium Core. This Selenium Core is the one that directly controls the
browser, not you.

3. Real-life Interaction
WebDriver interacts with page elements in a more realistic way. For
example, if you have a disabled text box on a page you were testing,
WebDriver really cannot enter any value in it just as how a real person
cannot.

• Selenium Core, just like other Javascript codes, can access disabled
elements. In the past, Selenium testers complain that Selenium Core
was able to enter values to a disabled text box in their tests. Differences
in API

4. API
Selenium RC's API is more matured but contains redundancies and often
confusing commands.

• For example, most of the time, testers are confused whether to use type
or typeKeys; or whether to use click, mouseDown, or mouseDownAt.
Worse, different browsers interpret each of these commands in different
ways tool
• WebDriver's API is simpler than Selenium RC's. It does not contain
redundant and confusing commands.

5. Browser Support
WebDriver can support the headless HtmlUnit browser

• HtmlUnit is termed as "headless" because it is an invisible browser - it is


GUI-less.
• It is a very fast browser because no time is spent in waiting for page
elements to load. This accelerates your test execution cycles.
• Since it is invisible to the user, it can only be controlled through
automated means.
• Selenium RC cannot support the headless HtmlUnit browser. It needs a
real, visible browser to operate on.

Page 07-7
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Headless browsers are typically used in following situations:


1. You have a central build tool which does not have any browser installed on it. So
to do the basic level of sanity tests after every build you may use the headless
browser to run your tests.
2. You want to write a crawler program that goes through different pages and
collects data, headless browser will be your choice. Because you really don’t care
about opening a browser. All you need is to access the webpages.
3. You would like to simulate multiple browser versions on the same machine. In
that case you would want to use a headless browser, because most of them support
simulation of different versions of browsers. We will come to this point soon.

Things to pay attention to before using headless browser


Headless browsers are simulation programs, they are not your real browsers. Most
of these headless browsers have evolved enough to simulate, to a pretty close
approximation, like a real browser. Still you would not want to run all your tests in a
headless browser. JavaScript is one area where you would want to be really careful
before using a Headless browser. JavaScript are implemented differently by
different browsers. Although JavaScript is a standard but each browser has its own
little differences in the way that they have implemented JavaScript. This is also true
in case of headless browsers also. For example HtmlUnit headless browser uses
the Rihno JavaScript engine which not being used by any other
browser.

Selenium support for headless browser


Selenium supports headless testing using its class called HtmlUnitDriver. This class
internally uses HtmlUnit headless browser. HtmlUnit is a pure Java implementation.
HtmlUnitWebDriver can be created as mentioned below:

HtmlUnitDriver unitDriver = new HtmlUnitDriver();

Page 07-8
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-9
Test Automation & Advanced Selenium Selenium Web Driver – Advance

GhostDriver is the project that provides the code that exposes the WebDriver API
for use within PhantomJS.
PhantomJS bakes the GhostDriver code into itself, and ships it as part of its
downloadable executable.
Thus, to use "GhostDriver" with PhantomJS, only PhantomJS is needed.

Page 07-10
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Native apps are those written using the iOS or Android SDKs.
Mobile web apps are web apps accessed using a mobile browser (Appium supports
Safari on iOS and Chrome or the built-in 'Browser' app on Android). Hybrid apps
have a wrapper around a "webview" -- a native control that enables interaction with
web content. Projects like Phonegap, make it easy to build apps using web
technologies that are then bundled into a native wrapper, creating a hybrid app.

Appium was designed to meet mobile automation needs according to a philosophy


outlined by the following four tenets:

You shouldn't have to recompile your app or modify it in any way in order to
automate it.
You shouldn't be locked into a specific language or framework to write and run your
tests.
A mobile automation framework shouldn't reinvent the wheel when it comes to
automation APIs.
A mobile automation framework should be open source, in spirit and practice as
well as in name.

Page 07-11
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-12
Test Automation & Advanced Selenium Selenium Web Driver – Advance

This example assumes that Selenium Server is running on localhost with


the default port of 4444. The nice thing about this is you can run
Selenium Server on any machine, change the URL to point to the new
machine and run the tests. For example, I run the test code from my
Mac OS X computer but I run Selenium Server on a Window XP machine.
This way I can launch Internet Explorer tests from my Mac OS X
computer.

Page 07-13
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-14
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-15
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Add the notes here.

Page 07-16
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Add the notes here.

Page 07-17
Test Automation & Advanced Selenium Selenium Web Driver – Advance

Page 07-18
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-1
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-2
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-3
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-4
Test Automation & Advanced Selenium Selenium Frameworks

1. Architecture
WebDriver's architecture is simpler than Selenium RC's.

It controls the browser from the OS level


All you need are your programming language's IDE (which contains your Selenium
commands) and a browser.
You first need to launch a separate application called Selenium Remote Control
(RC) Server before you can start testing
The Selenium RC Server acts as a "middleman" between your Selenium
commands and your browser
When you begin testing, Selenium RC Server "injects" a Javascript program called
Selenium Core into the browser.
Once injected, Selenium Core will start receiving instructions relayed by the RC
Server from your test program.
When the instructions are received, Selenium Core will execute them as Javascript
commands.
The browser will obey the instructions of Selenium Core, and will relay its response
to the RC Server.
The RC Server will receive the response of the browser and then display the results
to you.
RC Server will fetch the next instruction from your test script to repeat the whole
cycle.

Page 08-5
Test Automation & Advanced Selenium Selenium Frameworks

2. Speed
WebDriver is faster than Selenium RC since it speaks directly to the
browser uses the browser's own engine to control it.
Selenium RC is slower since it uses a Javascript program called
Selenium Core. This Selenium Core is the one that directly controls
the browser, not you.
3. Real-life Interaction
WebDriver interacts with page elements in a more realistic way. For
example, if you have a disabled text box on a page you were testing,
WebDriver really cannot enter any value in it just as how a real
person cannot.
Selenium Core, just like other Javascript codes, can access disabled
elements. In the past, Selenium testers complain that Selenium Core
was able to enter values to a disabled text box in their tests.
Differences in API
4. API
Selenium RC's API is more matured but contains redundancies and
often confusing commands.
For example, most of the time, testers are confused whether to use
type or typeKeys; or whether to use click, mouseDown, or
mouseDownAt. Worse, different browsers interpret each of these
commands in different ways tool
WebDriver's API is simpler than Selenium RC's. It does not contain
redundant and confusing commands.
5. Browser Support
WebDriver can support the headless HtmlUnit browser
HtmlUnit is termed as "headless" because it is an invisible browser -
it is GUI-less.
It is a very fast browser because no time is spent in waiting for page
elements to load. This accelerates your test execution cycles.
Since it is invisible to the user, it can only be controlled through
automated means.
Selenium RC cannot support the headless HtmlUnit browser. It needs
a real, visible browser to operate on.

Page 08-6
Test Automation & Advanced Selenium Selenium Frameworks

1.File Menu
It is very much analogous to the file menu belonging to any other application.
Export Test Case As and Export Test Suite give the liberty to the user to prefer
amid the available unit testing frameworks like jUnit, TestNG etc.
Thus an IDE test case can be exported for a chosen union of programming
language, unit testing framework and tool from the selenium package.

Page 08-7
Test Automation & Advanced Selenium Selenium Frameworks

The Selenium IDE test cases can be saved into following format:
HTML format
The Selenium IDE test cases can be exported into following formats/programming
languages.
java (IDE exported in Java)
rb (IDE exported in Ruby)
py (IDE exported in Python)
cs (IDE exported in C#)

Page 08-8
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-9
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-10
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-11
Test Automation & Advanced Selenium Selenium Frameworks

The Selenium IDE test cases can be saved into following format:
HTML format
The Selenium IDE test cases can be exported into following formats/programming
languages.
java (IDE exported in Java)
rb (IDE exported in Ruby)
py (IDE exported in Python)
cs (IDE exported in C#)

Page 08-12
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-13
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-14
Test Automation & Advanced Selenium Selenium Frameworks

Log/Reference/UI-Element/Rollup Pane
The bottom pane is used for four different functions–Log, Reference, UI-Element,
and Rollup–depending on which tab is selected.

Log
When you run your test case, error messages and information messages showing
the progress are displayed in this pane automatically, even if you do not first select
the Log tab. These messages are often useful for test case debugging. Notice the
Clear button for clearing the Log. Also notice the Info button is a drop-down
allowing selection of different levels of information to log.

Reference
The Reference tab is the default selection whenever you are entering or
modifyingSelenese commands and parameters in Table mode. In Table mode, the
Reference pane will display documentation on the current command. When
entering or modifying commands, whether from Table or Source mode, it is critically
important to ensure that the parameters specified in the Target and Value fields
match those specified in the parameter list in the Reference pane. The number of
parameters provided must match the number specified, the order of parameters
provided must match the order specified, and the type of parameters provided must
match the type specified. If there is a mismatch in any of these three areas, the
command will not run correctly.

While the Reference tab is invaluable as a quick reference, it is still often necessary
to consult the Selenium Reference document.

Page 08-15
Test Automation & Advanced Selenium Selenium Frameworks

Action: Used to change the state of the AUT(Application under Test)


like click on some link, type a value in edit box, select some options on the page,
select a value from drop down etc.
When action is performed on AUT the test will fail if the action is not achieved.

Accessor:-
This command check the state of the application and save the application state in
some variable. It can be used for automatic generation of assertions.

Assertions:
Are very similar to checkpoint in UFT/QTP. Assertion verifies the state of the
application matches it with the expected state and generates the True/False result.

Page 08-16
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-17
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-18
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-19
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-20
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-21
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-22
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-23
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-24
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-25
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-26
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-27
Test Automation & Advanced Selenium Selenium Frameworks

Add the notes here.

Page 08-28
Test Automation & Advanced Selenium Selenium Frameworks

Page 08-29
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Test Automation & Advanced


Selenium
Lab Book Version 1.0

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 1 / 18
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Document Revision History

Date Revision No. Author Summary of Changes


Jan 2016 1.1 Ritika Verma New contents creation
& Shubhasmit
Gupta –
Automation
CoE

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 2 / 18
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Table of Contents
Document Revision History ................................................................................................ 2
Table of Contents ............................................................................................................... 3
Getting Started ................................................................................................................... 4
Lab Demo 1: Example (Basic Selenium IDE Flow) ............................................................ 5
Lab Demo: Example (Selenium IDE) (Cont.…) .................................................................. 6
Lab Demo: Example (Selenium IDE) (Cont.…) .................................................................. 7
Lab Demo 2: Learning Selenium IDE (Modifications) ........................................................ 8
Lab 1. Learning Selenium IDE(Basic Flow) .................................................................... 9
Lab 2. Learning Selenium IDE(Performing Validations) ............................................... 10
Lab 3. Create a new account (using Selenium Webdriver) .......................................... 11
Lab 4. Validations in Selenium (using Selenium Webdriver) ........................................ 13
Lab 5. Alert and window handling (using Selenium Webdriver) ................................... 14
Lab 6. WebDriver with JUnit/TestNG (using Selenium Webdriver with Junit and
TestNG) 15
Lab 7. Advance Selenium (Chrome Driver and IE Driver) ............................................ 16
Lab 8. Advance Selenium (RemoteWebDriver)............................................................ 17
Appendices ....................................................................................................................... 18
Appendix A: Selenium Standards ........................................................................ 18

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 3 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Getting Started

Overview
This lab book is a guided tour for learning Test Automation & Advanced Selenium. It
comprises solved examples and ‘To Do’ assignments. Follow the steps provided in the
solved examples and work out the ‘To Do’ assignments given.

Setup Checklist for Selenium


Here is what is expected on your machine in order for the lab to work.
Minimum System Requirements
 Intel Pentium 90 or higher (P166 recommended)
 Microsoft Windows 95, 98, or NT 4.0, 2k, XP.
 Memory: 512MB of RAM
 Internet Explorer 6.0 or higher
 Mozilla Firefox( Add-ons: Firebug, Firepath, Selenium IDE)

Instructions
 For all coding standards refer Appendix A. All lab assignments should refer
coding standards.
 Create a directory by your name in drive <drive>. In this directory, create a
subdirectory Selenium_Assign. For each lab exercise create a directory as
lab <lab number>.

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 4 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab Demo 1: Example (Basic Selenium IDE Flow)

 Understand the process of automation testing of a web application on


Goals Selenium IDE
 Learn to manage document spacing
Time 60 minutes

Go to the Web Page for which


you want to carry out the test

Hit the record button on


IDE

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 5 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab Demo: Example (Selenium IDE) (Cont.)

Enter the text on Web


Page and submit

IDE should be updated, stop the


recorder and add the assertions

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 6 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab Demo: Example (Selenium IDE) (Cont.)

Perform operations on
the web page

Play
Button

Hit the play button to play


the recorded scripts

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 7 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab Demo 2: Learning Selenium IDE (Modifications)


 Understand the process of further modifications and validations in
Goals automation testing of a web application on Selenium IDE
 Learn to manage document spacing

Time 60 minutes

Basic URL: http://demo.opencart.com/

1. Follow the steps from Lab Demo 1

2. In order to add new command, go to the command where the new command needs to be added
and then do right click , click on ‘Insert New Command’

3. ‘Command’ dropdown provides options/ keywords to perform the operation

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 8 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 1. Learning Selenium IDE(Basic Flow)

 Understand the basic process of automation testing of a web application in


Goals Selenium IDE
 Learn to manage document spacing
Time 60 minutes

Basic URL: http://demo.opencart.com/

1. Open the URL on Firefox


2. Start recording on Selenium IDE
3. Go to 'Desktops' tab
4. Click on 'Mac'
5. Select 'Name(A-Z)' from the 'Sort By' dropdown
6. Click on 'Add to Cart' button
7. Stop the recording on Selenium IDE
8. Playback the whole test case

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 9 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 2. Learning Selenium IDE(Performing


Validations)

Goals  Understand the process of automation testing of a web application


 Learn to manage document spacing
Time 60 minutes

Basic URL: http://demo.opencart.com/

1. Open the URL on Firefox


2. Start recording on Selenium IDE
3. Verify title of the page
4. Go to 'Desktops' tab
5. Click on 'Mac'
6. Select 'Name(A-Z)' from the 'Sort By' dropdown
7. Click on 'Add to Cart' button
8. Enter ‘Mobile’ in ‘Search’ text box and click on ‘Search’ button
9. Wait for page to load
10. Clear the text from ‘Search Criteria’ text box
11. Click on ‘Search in product descriptions’ check box and click on ‘Search’ button
12. Stop the recording on Selenium IDE
13. Add the step after Step 5 where verify the 'Mac' heading
14. Change the value from ‘Mobile’ to ‘Monitors’
15. Save the test case
16. Playback the whole test case.
17. Playback set by step
18. Add the step after Click on 'Mac' where verify the 'Mac' heading
19. Save the test case
20. Export the test case as 'Java/JUnit/webDriver'
21. Run the whole Test case and check the 'Pass' Status
22. Create another test case with the same flow
23. Create the test suite for the above test cases

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 10 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 3. Create a new account (using Selenium


Webdriver)

Goals  Understanding the scenario from end to end and automating the same
 Analyze the requirement and perform validations accordingly
Time 120 minutes

Basic URL: http://demo.opencart.com/

Please ensure that the variables have to be defined before it is being used.

Part 1: Launch Application

1. Launch the URL on Firefox


2. Verify 'Title' of the page
3. Click on 'My Account' dropdown
4. Select 'Register' from dropdown
5. ‘Register Account’ page will open up, verify the heading ‘Register Account’
6. Click on 'Continue' button at the bottom of the page
7. Verify warning message 'Warning: You must agree to the Privacy Policy!'

Automate and validate the different sections of ‘Register Account’ page:

Part 2: For 'Your Personal Details'

1. Enter data in 'First Name' text box


2. Verify if 33 characters can be entered in 'First Name' text box by clicking
on 'Continue' button.
3. If not, verify error message.
4. Enter data in 'Last Name' text box
5. Verify if 33 characters can be entered in 'First Name' text box by clicking
on 'Continue' button.
6. If not, verify error message.
7. Enter valid 'E-mail'.
8. Enter 'Telephone' which must be between 3 and 32 characters.

Part 3: For 'Your Address'

1. Enter 'Address 1' which should contain characters between 3 and 128

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 11 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

2. Enter 'City' which should contain characters between 2 and 128


3. Enter 'Post Code' which should contain characters between 2 and 10
4. Select 'India' from 'Country' Dropdown
5. Select 'Region/State' from dropdown

Part 4: For 'Password'

1. Enter 'Password' which must be between 4 and 20 characters.


2. Enter 'Password Confirm'.

Part 4: For 'Newsletter'

1. Click on 'Yes' Radio button


2. Click on checkbox for 'I have read and agree to the Privacy Policy'.
3. Click on 'Continue' button
4. Verify message 'Your Account Has Been Created!'
5. Click on 'Continue'
6. Click on link 'View your order history' under 'My Orders'

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 12 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 4. Validations in Selenium (using Selenium


Webdriver)
Goals  Understanding the scenario from end to end and automating the same

Time 120 minutes

Basic URL: http://demo.opencart.com/

After login on the ‘Open Cart’, create a test script following the below
mentioned steps:

1. Login with credentials created in Lab 1


2. Go to 'Components' tab and click
3. Select 'Monitors'
4. Select 25 from 'Show' dropdown
5. Click on 'Add to cart' for the first item
6. Click on 'Specification' tab
7. Verify details present on the page
8. Click on 'Add to Wish list' button.
9. Verify message 'Success: You have added Apple Cinema 30" to your wish list!'
10. Enter 'Mobile' in ' Search' text box.
11. Click on 'Search' button
12. Click on 'Search in product descriptions' check box
13. Click on link 'HTC Touch HD' for the mobile 'HTC Touch HD'
14. Clear '1' from 'Qty' and enter '3'
15. Click on 'Add to Cart' button
16. Verify success message 'Success: You have added HTC Touch HD to your
shopping cart!'
17. Click on 'View cart' button adjacent to search button
18. Verify Mobile name added to the cart
19. Click on 'Checkout' button
20. Click on 'My Account' dropdown
21. Select 'Logout' from dropdown
22. Verify 'Account Logout' heading
23. Click on 'Continue'

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 13 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 5. Alert and window handling (using


Selenium Webdriver)
Goals Learning alert handling and window handling basics in selenium webdriver

Time 120 minutes

Base URL: https://ispace.ig.capgemini.com/sitepages/index.aspx

1. Launch the URL


2. Go to 'Application' tab
3. Click on checkbox 'Stationery Request'
4. Verify the new title ‘Stationary’
5. On ‘Stationery’ tab, click on 'Submit to collect your Stationery >>>' link
6. Switch to alert as shown below.
7. Verify text on the alert 'Please add product(s) to cart'
8. Verify if 'Ok' button is present on the alert
9. Click on 'Ok' button
10. Click on ‘Photocopy’ tab, click on ‘Save Request’ button
11. Switch to alert and verify text ‘No changes made’
12. Verify if ‘Ok’ button is present
13. Click on ‘Ok’ button present on alert
14. Click on ‘Logout’ button
15. Close the ‘Stationery’ window

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 14 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 6. WebDriver with JUnit/TestNG (using


Selenium Webdriver with Junit and TestNG)
Goals Learning how to write webdriver automation testcases using Junit and TestNG

Time 120 minutes

1. Consider the flow mentioned in Lab 3 & Lab 4, complete the task using Selenium
WebDriver and JUnit.
[NOTE: All the verifications should be using JUnit Assertions]

2. Consider the flow mentioned in Lab 3 & Lab 4, complete the task using Selenium
WebDriver and TestNG.
[NOTE: All the verifications should be using TestNG Assertions. Testcases
should have proper TestNG Reporter logging as well.]

3. Create one TestNG test suite for both the testcases created for question
number 2 along with testing.xml and execute the test suite. Provide the
Reports as well.

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 15 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 7. Advance Selenium (Chrome Driver and IE


Driver)
Goals Learning how to write webdriver automation testcases for Chrome and IE
browser
Time 120 minutes

1. Consider the flow mentioned in Lab 3 & Lab 4, make necessary changes to
execute the same flow on both Chrome and Internet Explorer browser.

2. Consider the Question number 1 and make it JUnit test case.


[NOTE: All the verifications should be using JUnit Assertions]

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 16 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Lab 8. Advance Selenium (RemoteWebDriver)


Goals Learning how execute Selenium scripts using RemoteWebDriver

Time 120 minutes

1. Consider the flow mentioned in Lab 3 & Lab 4, make necessary changes to
execute the same flow using RemoteWebDriver and Selenium Grid on Firefox,
Chrome and Internet Explorer browser.
[NOTE: Set Platform, BrowserName and Version to DesiredCapabilities]

2. Consider the flow mentioned in Lab 4 and take screenshot after each steps.
Save all the screenshots inside a folder called ‘Screenshots’ in the root of the
Java project.

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 17 / 18 
TEST AUTOMATION & ADVANCED
SELENIUM LAB BOOK

Appendices

Appendix A: Selenium Standards

Key points to keep in mind:


Selenium standards help you reach the widest possible audience.
There are many technologies that are associated with HTML because they are used on
web pages or in conjunction with HTML.

For each of the above, please follow coding conventions specified by that technology.
Sometimes you are going to have to break rules and use non-standard syntax for good
reason. Try to keep this to the minimum.

How to follow Selenium standards:

See the W3C site for more information on locator types and keyword statements.
The important thing to remember is that proper keywords are essential to assist validation
software in checking your document.
Use Selenium IDE to find the locators for the elements.
Refer to W3C for technical and syntax information.
Always use the comments with the codes for proper understanding.

Some simple Selenium standards:


Names of Selenium files should always end with the extension .java.
Correct: foo.java
Incorrect: foo.bar

©2016 Capgemini. All rights reserved.

The information contained in this document is proprietary and confidential. For Capgemini only. | 18 / 18 

You might also like