0% found this document useful (0 votes)
13 views

Ebook QA QE 1 L4 Automation With Selenium WebDriver

Uploaded by

Priyanka Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Ebook QA QE 1 L4 Automation With Selenium WebDriver

Uploaded by

Priyanka Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 119

Automation with Selenium WebDriver

You Already Know

Course(s):

Software Testing: Get a high paying Job In Technology


▪ Explain software testing and software tester
- Software testing
- Software tester

▪ Describe methodologies used in software testing


- Software Development Life Cycle (SDLC)
- Waterfall and Agile methodologies
- Software Testing Life Cycle (STLC)

▪ List the differences between manual testing and automation


testing
- Manual vs. Automation
▪ Demonstrate bugs in a software
- Bugs
- Bug tool
A Day in the Life of a Test Engineer

Joe, a Test Engineer for Abq Inc., has been working hard. His company
is facing employee bandwidth problem in testing a project given by an
e-learning company. The company has decided to use automation
testing to solve this problem.

Joe has been asked to design a functionality to automate testing using


Selenium.

In this lesson, we will learn how to solve this real-world scenario to


help Joe effectively and quickly complete his task.
Learning Objectives

By the end of this lesson, you will be able to:

Work with Selenium IDE and WebDriver

Develop automation scripts for application

Work with radio buttons, drop-down list, multi-select, and


checkboxes

Work with external elements like frames, alerts, pop-ups, and


sub-windows
Testing Basics
Software Testing

Software testing is the process of evaluating a system or its components to ensure that the
software system is defect free.

Testing: Checking if the tangible result matches the projected or the expected
output.

High analytical skills required to test an application for all possible use cases
with minimum test cases.
Why Software Testing

Software testing checks the quality of a software application for its:

Functionality

Efficiency

Reliability

Usability

Maintainability

Portability
Types of Testing

Software testing can be broadly classified as manual testing and automation testing.

Software Testing

Manual Automation

Testing a software manually, without Testing a software using scripts or


any automated tool or script another software
Manual Testing

Includes the most primitive types of testing

A new application must be tested manually


before automating the testing process

Test cases are manually executed


Manual Testing: Types

Black-Box testing

White-Box testing

Unit testing
Types

System testing

Integration testing

Acceptance testing
Automation Testing

Uses a third-party software to test the


application or product

Involves automation of a manual process

Used mainly in load, performance, and stress


testing

Saves time, improves accuracy, and increases


test coverage
Manual Testing vs. Automation Testing

Manual Testing Automation Testing

Requires human intervention for test execution Uses tools to execute test cases

Time consuming and labour intensive Saves time, cost, and manpower

Any application can be tested manually Recommended only for stable systems

Reliable as testing is performed by scripts and


Not as accurate as automation testing
tools

Not cost effective for high-volume regression Not cost effective for low-volume regression

Suitable when the test cases need to be executed Suitable for frequent execution of same set of test
for a limited number of times cases
Real-Time Implementation of Testing Techniques: HR Payroll System
What is Selenium and How it is Used in the Industry
What Is Automation?

Software test automation refers to the activities and efforts that automate manual tasks and
operations in a software test process using well-defined strategies and systematic solutions.

Test Test
Script Execution

Test
Automation
Automation for Agility

Test automation is the only way to achieve agility.

Manual Testing

Framework or
Automation Automation Tool
Library Files

Automated Test
Execution

Test Execution Test Data


Environment

Faster Test
Results
Automation Lifecycle

Decision to Test Planning Execution and Test Program


Test Tool
Automate and Management of Review and
Acquisition
Testing Development Tests Assessment
Automation Tools
There are various Test Automation tools available and each has its own advantages and limitations. Some of the tools are:

Selenium Quick Test Appium


Testing Professional FitNesse

Silk Test Eggplant TestComplete


Ranorex

Rational Watir Tricentis Tosca SOATest


Functional Test
Brief History of Selenium

3.0 beta was


released for the Selenium RC
Selenium was Selenium Grid officially was
invented by Jason R. The name was attendees of the
came into deprecated with
Huggins and team in changed to Selenium
existence in the release of
Thoughtworks in Selenium RC Conference held
2008 WebDriver 3.0
2004 in Bangalore on
June 2016

The original Selenium IDE WebDriver was Selenium 3.0


name was was created by merged with was released in
JavaScript Test wrapping the Selenium RC in October 2016
Runner core code into 2009
IDE
Uses of Selenium in the Industry

Plays a key role in DevOps Helps in parallel execution of


large number of tests

Provides faster Provides behavior-driven


feedback and agility development with
Cucumber and JBehave

Provides improved Supports Mobile Test


coverage across platforms, Automation along with
browsers, and mobile Appium
devices in terms of quality
Features of Selenium
Features of Selenium IDE

Record and playback

Autofilling locators: ID, name, link, XPath, CSS, and DOM

Dropdown selection of Selenium commands

Features of debugging tests

Capability to save tests as HTML and convert to WebDriver Java, Ruby, Python, and C#

Support for Selenium user-extensions.js file

Scheduler for scheduling your tests


Adding Selenium IDE to the Browser

Installing IDE (from addons.mozilla.org)

Various menu options

Test Cases and Test Suites

Commands or Targets or Value

Assertions, Accessors, and Actions

Getting locators: Select

Locating elements on page: Find

Testing Results: shades of green and red

Options settings

User Extensions
Features of Selenium

Duration: 30 min.

Problem Statement:
Demonstrate the features of Selenium.
Assisted Practice: Guidelines

Steps to demonstrate the features of Selenium:

1. Describe the features of Selenium.


WebDriver Architecture
WebDriver Architecture

This is the Java class hierarchy of WebDriver and third-party driver executable required to execute tests.

FindsByClassName FindsById JavascriptExecuter WebDriver TakeScreenshot FindsByLinkText FindsByName FindsByTagName

Remote WebDriver
Selenium
Classes

FirefoxDriver ChromeDriver SafariDriver InternetExplorerDriver

geckodriver.exe chromedriver.exe Safaridriver IEDriverServer.exe Drivers

Firefox Chrome Safari Internet Explorer Browsers


WebDriver Advantages

1. Keeps the costs down 2. Emulates the user

3. Keeps it simple and


4. An open source project
flexible

Reference - http://www.aosabook.org/en/selenium.html by Simon Stewart - Creator of WebDriver


WebDriver Installation and Integration in Eclipse

Duration: 30 min.

Problem Statement:
Demonstrate how Selenium web driver is installed and integrated in Eclipse.
Assisted Practice: Guidelines

Steps to demonstrate WebDriver installation and configuration in Eclipse:

1. Download Selenium Standalone Server jar.

2. Launch Eclipse and create a Java project.

3. Configure WebDriver with Eclipse.


Multiple Ways to Locate Elements
Typical HTML Page Elements

HTML Tags

Siblings
Attributes

Parent

Child of div Visible Text or Inner Text


Typical HTML Page Elements

Element HTML Tag Key attributes


Text Field input type=text
Radio Button input type = radio
Checkbox input type=checkbox
Button input type=submit
Text div, span, p -
WebTable table, thead, tbody, th, tr, td -
Frame frame, iframe -
Images img alt, src
DropDown, Multiple Select select multiple
Link(Anchor) a href

! You will see ID, name, and class attributes in many of the elements but, they are optional.
findElement() Method

When do you need to deal with multiple elements on a webpage?

When dynamic elements that


do not have unique ids are
displayed on a page, such as: When there are specific types
When there are groups of
of elements that you want to
• HTML tables displaying radio buttons or checkboxes
find inside a particular
data from database that you need to select based
element, e.g., searching all
• Dropdowns and on input data
links inside the “div”
multiple selects
displaying dynamic data
findElement() Method

Syntax:

List<WebElement> allInputElements = driver.findElements(By.tagName(“input”));


for (WebElement oneInputElemenetAtATime : allInputElements )
{
System.out.println(oneInputElemenetAtATime.getAttribute(“value”));
}

What happens if findElement() and findElements() do not find any such element or elements?
• You will receive an error in your console specifying the same and you should use a different
locating technique to locate elements.
WebDriver Locators

Selenium WebDriver uses eight locators to find the elements on a webpage.


The object identifiers or locators supported by Selenium are:

Id (unique, non-dynamic) driver.findElement(By.id(“Email”));

Name (unique, non-dynamic) driver.findElement(By.name(“EmailID”));

Class (unique, non-dynamic) driver.findElement(By.className(“mandatory”));

CSSSelector driver.findElement(By.cssSelector(“input.login”);

XPath driver.findElement(By.xpath(“//input[@class=‘login’]”);

linkText driver.findElement(By.linkText(“Gmail”));

Partial LinkText driver.findElement(By.partialLinkText(“Inbox”));

TagName driver.findElement(By.tagName(“input”));
WebElement Class Methods

Working with elements on a web page can be further enhanced and made easy by
WebElement class methods.

The following methods help in acting on elements, retrieving information about


elements, and getting positions, size, and visible texts:

• clear() • isEnabled() • findElement() • getCssValue() • getLocation()


• click() • isDisplayed() • findElements() • getAttribute() • getRectangle()
• Submit() • isSelected() • getText() • getSize()
• sendKeys() • getTagName()
• getScreenshotAs()
Locating Guidelines

Locators are key to robust tests, and if one can select good locators, a test becomes more resilient.

Locators should be unique, descriptive, and unlikely to change.

Best options are ID, name, and class if they match the above condition.

LinkText is also subject to change and will not work if your app supports internationalization (i18n).

If an element does not have a unique ID, name, and class, search for parents that have a unique id.

If that is does not work, request developers to provide unique locators.


Timeout Methods

Timeouts are an interface for managing timeout behavior for WebDriver instances.

Method What it does

• implicitlyWait() • Amount of time the driver should wait while


searching for an element (call to findElement) if it is
not immediately available

• pageLoadTimeout() • Amount of time to wait for a page to load completely

• Amount of time to wait for an asynchronous script to


• setScriptTimeout() finish execution

Implicitly waiting vs. putting Thread.sleep():


Implicit wait polls the DOM to wait for a certain amount of time until an element is found. Thread.sleep()
causes executing thread to sleep for specified time.
Synchronizing Automation

Handling synchronization is critical to create resilient tests.

Unconditional Synchronization: Conditional Synchronization:


Make the tool wait for a certain Synchronization Specify conditions along with timeout
amount of time by specifying timeout Categories value to make the tool wait, check for
value before the tool proceeds with the condition, and then proceed with
the execution. the execution.
Why to Use Waits?

A website or webpage comprises


As all elements load at different
various elements other than
intervals, it becomes difficult to
HTML like images, pop-ups, alerts,
automate an element if it is not
and animations. Automation
Waits loaded on the webpage and throws
scripts must run once all elements
ElementNotVisibleException.
are loaded.

Both implicit and explicit waits are used to prevent such a


situation. Both have different implementations. This helps
developers to determine the designing of web pages for quick
loading and reduce the wait time as much as possible.
Limitations of Implicit Wait

Test Case:

• Go to
http://the-internet.herokuapp.com/dynamic_loading/1
• Click on Start button
• Verify that Hello World! comes after clicking on Start

When you put implicit wait in this test case and use TestNG
assertEquals() method to compare the output with Hello
World!, the test fails.
Limitations of Implicit Wait

Test Case Explanation:

• Implicit Wait only waits for the element to be present.


• In this test case, element (id=finish) is present on the page
but is not visible.
• When you click on Start button, it takes time for the element
(id=finish) to become visible.
• Implicit wait finds the element (even though it’s invisible) and
gives the control to the next line of code in your test script.
• Therefore, assertEquals() executes even before the element
is made visible.
• getText() method does not work on invisible elements.
• This is why the test fails.
Explicit Wait

Using Explicit Wait, you can wait for certain conditions:


Apply
condition
• Element to be invisible or visible
Retry
• Alert, frame, or window to be present

• Title of the page to have specific value


Check
result

• Explicit Wait pings the webpage every 500 milliseconds (configurable) to check the condition.
• It returns the controls to the test script once the condition is satisfied.

Syntax:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-passwd")));
Fluent Wait
FluentWait is a parent class of WebDriverWait class. Using this class, you can:

• Make the polling time configurable


• Specify the exceptions to be ignored
• Create custom conditions with your application under test
Syntax:
Program waits for 30 seconds for an element to be present. It checks for the element every five
seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) //
.withTimeout (30,TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);

WebElement searchID = wait.until(new Function<WebDriver, WebElement>()


{ public WebElement apply(WebDriver driver)
{ return driver.findElement(By.id(“login-passwd"));}
Timeouts Guidelines

Best practices:

• Do not use Thread.sleep(), except when Explicit Wait fails.

• Do not use Implicit Wait.

• Avoid using Implicit Wait and Explicit Wait in


combination.

• Test your code in all the browsers (expected as per


requirement) and optimize your wait time.

• Do not give hard-coded waits in your scripts. Make the


script configurable.
Multiple Ways to Locate Elements

Duration: 40 min.

Problem Statement:
Demonstrate how elements are located using Selenium WebDriver.
Assisted Practice: Guidelines

Steps to locate elements in multiple ways using Selenium WebDriver:

1. Demonstrate ID as a locator.

2. Demonstrate class name as locator.

3. Demonstrate name as locator..

4. Demonstrate link text as locator.

5. Demonstrate Xpath as locator.

6. Demonstrate CSS selector as locator.

7. Demonstrate Xpath handling complex and dynamic elements as locator.


Locating Elements through CSS and Xpath
Locating with Xpath

XPath is the XML path and query language for selecting nodes from an XML document which is a
W3C recommendation.

Absolute XPath html/body/div/h2/a - absolute path to get the anchor element


Relative XPath //input – get all “input” elements on the page

Using Index //input[1] – getting all first “input” elements of a parent on the page
Using Attribute Values //input[@value='Login'] – “input” with “value” attribute “Login”

Two Attributes – AND //input[@value='Login'][@type='submit'] – “input” matching two


attribute values
Two Attributes – OR //input[@value='Login‘ or @type='submit'] – “input” matching one of
the attributes
Partial Match - contains //input[contains(@id, 'admin')] – “input” having “id” attribute
containing “admin”

! Do not copy attribute values from this slide to your FirePath field as it may lead to error.
Xpath vs. CSS

Below is the key difference between Xpath and CSS locating techniques:

Objective In XPath In CSS


Find an element inside a node, not necessarily
// [space]
immediate child
Find an element inside a node at an
/ >
immediate level (immediate child)

Indicating attribute @ Nothing


Locating Elements with CSS

Selenium does not change the CSS can change styling by


style of elements. It interacts with declaring which bits of the markup
elements by clicking, getting it wants to alter through the use of
values, typing, sending keys, etc. CSS selectors.

In web design, CSS (Cascading Style Sheets) are used to apply


presentation in terms of colors, fonts, and layout to the
markup (HTML) on a page. These visual properties are stored
in a separate file with .CSS extension.
Locating Elements with CSS
Ways to locate elements with CSS:

Absolute CSS Html>body>div>h2>a - absolute path to get the anchor element


Relative CSS input – get all input elements on the page

Class selector p.step-third – p element that has “class” attribute step-third


Using Attribute Values input[value='Login'] – input with value attribute Login

Two Attributes - AND input[value='Login'][type='submit'] – input matching two attribute values


id Selector table#SiteLinks – table that has id attribute SiteLinks
Starts with - ^= p[id^='step'] – p that has id attribute starting with step
Ends with – $= div[id$='erce'] – div that has id attribute ending with erce

Contains – *= input[id*='admin'] – input that has id attribute containing admin

Following sibling form ~ h3 - following sibling h3 of form element


First following sibling div + h3 – first following sibling h3 of div element

Position in hierarchy div[id='eCommerce'] h4:nth-child(2) – h4 which is second child of div that has
id – eCommerce
Locating Elements Through CSS and XPath

Duration: 60 min.

Problem Statement:
Demonstrate how elements are located through CSS and XPath.
Assisted Practice: Guidelines

Steps to locate elements through CSS and XPath:

1. Demonstrate how to find the element present on the page by using CSS selector.

2. Demonstrate how to find the element present on the page by using Xpath.

3. Push the code to your GitHub repositories.


Handling Various Web Elements
Radio Button and Checkboxes

Radio buttons and checkboxes can be handled by below methods of WebElement class:

Element What can you do? WebElement Methods

• Select a radio button ● Click()


Radio button
• Check if a radio button is selected ● isSelected()

• Select a checkbox • Click()


Checkbox • Deselect a checkbox • Click()
• Check if a checkbox is selected • isSelected()
Drop-Down List

The following methods are available in Select class provided by Selenium. These are applicable for drop-
down as well as multi-select components.

What can you do ? Select class methods

• selectByVisibleText()
• Select an option
• selectByValue()
• selectByIndex()

• Check what options are available • getOptions()

• Check which option is selected first • getFirstSelectedOption()

• Check if it is a drop-down or multi-select • isMultiple()


Multi-Select Options

The following methods are only applicable to multi-select elements:

What can you do ? Select class methods


• deselectByVisibleText()
• Deselect an option • deselectByValue()
• deselectByIndex()

• Get all selected options • getAllSelectedOptions()

• Deselect all • deselectAll()


HTML Tags for Tables

Common tags for HTML Table:

• <table> : Defines an HTML Table

• <tr> : Defines a row

• <th> : Defines a header cell

• <td> : Defines standard (not header) cells in HTML


table.
• <thead> : Groups table header content in HTML table

• <tbody> : Groups the table body content


HTML Table Structure

The following image shows how a complex HTML table would appear on a webpage:
HTML Table Methods

Working with HTML tables in WebDriver:

• No standard methods are provided by


WebDriver to work with HTML tables
• We need to create reusable methods as
part of our framework.

Examples of re-usable methods:

• Finding the number of rows and columns


in a table.
• Finding a particular cell from the table.
• Taking action on a particular cell based on
the content of some other cell.
Handling Various Web Elements

Duration: 60 min.

Problem Statement:
Demonstrate how web elements are handled in Selenium.
Assisted Practice: Guidelines

Steps to handle web elements:

1. Handle various web elements present on the web page.


Date Picker

Duration: 60 min.

Problem Statement:
Demonstrate how to automate calendars on the web page
Assisted Practice: Guidelines

Steps to perform:

1. Create a selenium project.

2. Write code for calendar automation


Working with External Elements
External Elements

JavaScript alerts

Browser Pop-up windows


So far, we have focused on a
single HTML page.
However, the real web
Pop-up windows. For example: file
application includes:
upload, print dialog

Frames and iframes


JavaScript Alerts

WebDriver provides APIs in Alert class to handle JavaScript popups.

JavaScript has three types of pop-ups:

Confirm Box: Contains a Prompt Box: Contains a


Simple Alert Box: Contains a message, a text box to enter a
message along with OK and
message and OK button value along with OK and
Cancel button
Cancel button
JavaScript Alerts

Syntax for Handling Alerts

Alert = driver.switchTo().alert() // Tells the driver to switch focus on alert pop-up window.

Key Operations that can be performed on JavaScript popups

alert.getText() // Gets the text on alert window.


alert.accept() // Accepts the alert (for example, clicking Ok button).
alert.dismiss() // Dismisses the alert (for example, clicking Cancel button ).
alert.sendKeys() // Passes text to be entered in any field on the pop-up window.

Exception to be handled

NoAlertPresentException // This exception triggers when there is no alert, but system is trying to
switch to an alert.
Browser Pop-Ups

Some application designs generate additional browser


First Window window if a button or link is clicked.

Popped-up In some cases, though the focus is on a new window,


window WebDriver object focus remains on the previous window.

This means that executing driver.findElement() or


driver.getTitle() will get results from the previous window.

WebDriver provides API to switch the WebDriver instance


focus from previous window to current window.

You should use driver.close(), instead of driver.quit(), to


close the current window.
Browser Pop-Ups

The screen below shows that clicking on Thanks button invokes another browser window.
Now, the focus is visibly on new window, but WebDriver instance is still on the previous window.
Browser Pop-Ups

WebDriver provides APIs to handle multiple windows.


driver.switchTo().window() //Tells the driver to switch focus to a window by window name or window
handle.
driver.getWindowHandle() //Gets the window handle of the current window.
driver.getWindowHandles() //Gets window handles of all the windows opened by the current driver.

The two types of parameters the window() method can take are:

driver.switchTo().window(windowName) // Where “windowName” is the name of the new window opened


by the browser.
driver.switchTo().window(windowHandle) // Where “windowHandle” is the window handle returned by
driver.getWindowHandle(s)() method.

Exception to be handled

NoSuchWindowException // This exception triggers when the system tries to switch focus on a window that
does not exist.
HTML Frames

HTML frames enable you to display documents in


different sections.

Frames/iFrames can be used to show content from


another website. For example, ads
Frame 2
Frame 1 Frame 3

Frames are like HTML pages embedded in another


Frame 4
HTML page.

Generally, driver.findElement() or other WebDriver


commands do not search inside frames.
Handling Frames

WebDriver provides APIs to handle Frames

driver.switchTo().frame() //Tells driver to switch focus to a frame by ID, name, index, or WebElement
Driver.switchTo().defaultContent() //Tells driver to switch focus back to default page
Driver.switchTo().parentFrame() //Tells driver to switch focus to parent frame.

The frame() method can take three types of parameters:

driver.switchTo().frame(id or name) // ID or name attribute of the frame


driver.switchTo().frame(index) // Position of the frame within the frameset
driver.switchTo().frame(WebElement) // frame WebElement
User Interactions Automation

The Advanced User Interactions API helps to perform


simple to complex actions on a web page, such as:

Right click

Double click

Drag and drop

Pressing and releasing keys

Mouse hover
User Interactions Automation

There are two types of user interactions:

Keyboard interactions Mouse interactions

Click on element:
Pressing a key: keyDown()
Click()/Click(element)
Releasing a key: keyUp()
Click and Hold: clickAndHold()
Typing in a text field: sendKeys()
Right click: contextClick()

Double click: doubleClick()

Drag and Drop: dragAndDrop()

Mouse hover: moveToElement()

Releasing left mouse button: release()


User Interactions Automation

Actions class is used to generate a series of actions.

Actions builder = new Actions(driver);


builder.click(AllRowsOfTable.get(1)) /* 1st Row selected */
.keyDown(Keys.CONTROL)
.click(AllRowsOfTable.get(3)) /* 3rd Row selected */
.click(AllRowsOfTable.get(6)). /* 6th Row selected */
.keyUp(Keys.CONTROL);

Build() method to get action:

Action selectMultipleRows = builder.build();

Execute the action by calling perform().

selectMultipleRows.perform();
Working with External Elements

Duration: 60 min.

Problem Statement:
Using Selenium WebDriver, write a program to handle alerts.
Assisted Practice: Guidelines

Steps to work with external elements:

1. Handle external pop ups.

2. Handle new tabs and new windows.

3. Push the code to your GitHub repositories.


Screenshots and Browser Profiles
Capturing Screenshots

In bug analysis, screenshots are desirable. In automation testing, it is mandatory to take a


screenshot for verification of functionality of test cases. Selenium automatically takes
screenshots during test execution.

• Selenium provides TakesScreenshot interface to capture screenshots


• WebDriver instance has to be type casted to TakesScreenshot
Capturing Screenshots

Screenshots can be captured in Selenium in 3 simple steps.

Steps Sample Code

public static void takeSnapShot(WebDriver


Convert WebDriver object to webdriver String filePath)
TakesScreenshot object
1 {
//Convert web driver object to
TakeScreenShot object
Call getScreenshotAs method to
TakesScreenshot scrObj –
create an image file
2 ((Takesscreenshot)webdriver);
//Call getScreenshotAs method to create an
image file
Copy the file to the desired location File scrFile =
3 scrObj.getScreenshotAs(outputType.FILE);
Browser Profiles

Browser profile

• Set of files maintained by the web browser that


contain personal information, such as
bookmarks, passwords, and user preferences

• Stored in a separate location from the browser


program files

• Multiple profiles, each containing a separate set


of user information are possible

Profile Manager allows creation, removal, renaming, and switching of profiles.


Browser Profiles for Automation

It is advisable to create a separate browser profile while running automation.

To run a good test, an automation profile must:

contain
be
special
light-weight
settings

The profile must be consistent across all development and


test execution machines.
Need for Custom Browser Profiles: Firefox Browser

The default Firefox browser profile is not automation-friendly.

The profile must handle special test needs


required to make the test execution reliable.

The profile must handle packaging and


deploying the special test settings.

The profile must contain just the required


settings and plug-ins needed for test execution.

Selenium copies the entire profile to a temporary


directory each time a new session driving a Firefox
instance is started.
Changing Browser Profiles

Steps to change Firefox browser profiles

Close all the open Firefox instances

On the Windows Start Menu select Run; type firefox.exe -p

Select the required profile from the dialog box

Click Start Firefox button to open a new instance with the


selected profile

In Selenium WebDriver software test, the getProfile


method of profilesIni, an inbuilt WebDriver class must
be used to access the Firefox profile.
Screenshots and Browser Profiles

Duration: 60 min.

Problem Statement:
Demonstrate how screenshots are captured and browser profiles are changed in Selenium.
Assisted Practice: Guidelines

Steps to take screenshots using Selenium WebDriver and set the browser profile:

1. Write a code for screenshots.

2. Run the code.

3. Pushing the code to your GitHub repositories.

4. View browser profile.


AutoIT
AutoIT: Introduction

AutoIT is an open source tool used to automate processes involving Windows and desktop
applications. AutoIT is used as Selenium cannot handle Windows-based activities.

• Third-generation programming language


• Similar to BASIC
• Uses C# and VB for scripting
• A few lines of script are sufficient for automating a
task
• A process can be recorded using AutoIT recorder

AutoIT is effective for automating workflows that work between browser, desktop, and
Selenium.
AutoIT

AutoIT is effective for automating workflows that work between browser, desktop and Selenium
AutoIT: Features

AutoIT performs keyboard actions and supports web and desktop applications. Some of the other
features of AutoIT include:

• Easy-to-learn syntax
• Record and playback
• Compatibility with all Windows OS versions
• Graphical User Interfaces
• Compilation of scripts into standalone executables
• Simulation of keystrokes and mouse movements
• RunAs function
AutoIT: File Upload

Download AutoIT and install

Open Programs > AutoIT Tool > Script Editor

Add AutoIT script in AutoIT editor

Save the file as UploadFile.au3

Convert the file as UploadFile.exe

Run the script from your IDE


AutoIT Installation and Configuration

Duration: 30 min.

Problem Statement:
Demonstrate installation and configuration of AutoIT.
Assisted Practice: Guidelines

Steps to install AutoIT and configure it:

1. Install and configure AutoIT.


Handling File Uploads

Duration: 60 min.

Problem Statement:
Demonstrate how file uploads are handled in AutoIT.
Assisted Practice: Guidelines

Steps to upload files using AutoIT:

1. Handle file upload by SendKeys.

2. Handle file upload by AutoIT Script.


Sikuli for UI Testing
Sikuli for UI Testing
Sikuli is a GUI-based open source automation tool. This tool is used to handle Windows-
based pop-ups and to interact with the elements of a web page. It uses image recognition to
interact with the elements of the web page.

Features

• Easy integration with Selenium


• Automation of anything seen on the screen
• Platform independent
• Easy automation of Flash objects

Sikuli is preferred when the UI elements are not constantly changing and are stable.
Sikuli: Advantages

An open source tool

Can be used for Flash testing, mobile testing, and


Windows/Desktop testing

Images can be captured for the script as it uses


image recognition

Easy integration with Selenium


Sikuli: Classes

Class Description Methods

Used for screen operations; contains predefined


Screen methods for all the commonly performed click, doubleClick, type,
operations on screen elements hover, find

Used for pattern-based operations; associates


Pattern the image file with additional attributes to getFileName, similar, exact
uniquely identify the element
Sikuli: Integration With Selenium

Download and install Sikuli JAR files

Create a Java project in Eclipse and add Sikuli JAR files to


build path

Create a .java class; create an object of Screen/Pattern to


work on images using Selenium
Sikuli for UI Testing

Duration: 50 min.

Problem Statement:
Demonstrate how Sikuli is used for UI testing in Selenium.
Assisted Practice: Guidelines

Steps to integrate Sikuli with Selenium WebDriver and interact with web elements:

1. Integrate Sikuli with Selenium WebDriver.

2. Create Screen class and Pattern class.

3. Push the code to your GitHub repositories.


Selenium and JDBC
Selenium and JDBC

JDBC is required to use Selenium WebDriver for database verification. JDBC is a Java-based
data-access API used to connect to a wide range of databases.

Statement DriverManager

JDBC API:
SQLException Classes and Driver
Interfaces

ResultSet Connection
Database Testing Using Selenium

Three steps must be followed for database testing using Selenium.

Connect to the Send queries to


Process the results
database the database
Selenium and JDBC

Duration: 20 min.

Problem Statement:
Demonstrate the usage of JDBC in Selenium.
Assisted Practice: Guidelines

Steps to use JDBC in Selenium:

1. Create a table in database.

2. Write the JDBC code to integrate with Selenium.

3. Push the code to your GitHub repositories.


Key Takeaways

Software test automation refers to the activities and efforts


that automate manual tasks and operations in a software test
process using well-defined strategies and systematic
solutions.

Selenium WebDriver uses eight locators to find the elements


on a webpage: ID, Name, Class, CSSSelector, Xpath, LineText,
Partial Link Text, and TagName.

AutoIT is an open source tool used to automate Windows and


desktop application processes.

Sikuli is a visual technology used to automate and test


graphical user interfaces using images.
Upload File and Handle Various Web Elements

Duration: 90 min.
Problem Statement:
You are asked to develop a functionality using Selenium webdriver to
handle various web elements.
Before the Next Class

You should know:

▪ Agile and scrum core concepts

▪ Fundamental concepts of Git and GitHub

▪ Basics of Java programming

▪ Implementation of OOPs and Collections

▪ Database handling

▪ Automation using Selenium webdriver


Automating the Amazon Application Using Selenium WebDriver

Duration: 240 min.


Project Objective:
As a Test Engineer, you are asked to automate the Amazon application
using Selenium webdriver.
Background of the Project Statement

The Amazon application has a huge database. The customers are taking more time to find
a particular product. As you are a Test Engineer, your manager has asked you to write an
automation script to get the list of different products in a particular category. Based on the
list, it will be easy for the customers to select the product.
You Are Asked to Do

● Create a Java class for Amazon application


● Open the browser and locate web elements using locators.
● Write automation script using page object design pattern class to store the web elements of
web page.
● Perform transaction management using Selenium and JDBC.
You Must Use the Following

IDE: Eclipse or IntelliJ Programming language: Java Git and GitHub

Selenium Standalone Server


Scrum Specification Document
3.141.59

You might also like