Ebook QA QE 1 L4 Automation With Selenium WebDriver
Ebook QA QE 1 L4 Automation With Selenium WebDriver
Course(s):
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.
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
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
Black-Box testing
White-Box testing
Unit testing
Types
System testing
Integration testing
Acceptance 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
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
Manual Testing
Framework or
Automation Automation Tool
Library Files
Automated Test
Execution
Faster Test
Results
Automation Lifecycle
Capability to save tests as HTML and convert to WebDriver Java, Ruby, Python, and C#
Options settings
User Extensions
Features of Selenium
Duration: 30 min.
Problem Statement:
Demonstrate the features of Selenium.
Assisted Practice: Guidelines
This is the Java class hierarchy of WebDriver and third-party driver executable required to execute tests.
Remote WebDriver
Selenium
Classes
Duration: 30 min.
Problem Statement:
Demonstrate how Selenium web driver is installed and integrated in Eclipse.
Assisted Practice: Guidelines
HTML Tags
Siblings
Attributes
Parent
! You will see ID, name, and class attributes in many of the elements but, they are optional.
findElement() Method
Syntax:
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
CSSSelector driver.findElement(By.cssSelector(“input.login”);
XPath driver.findElement(By.xpath(“//input[@class=‘login’]”);
linkText driver.findElement(By.linkText(“Gmail”));
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.
Locators are key to robust tests, and if one can select good locators, a test becomes more resilient.
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.
Timeouts are an interface for managing timeout behavior for WebDriver instances.
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
• 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:
Best practices:
Duration: 40 min.
Problem Statement:
Demonstrate how elements are located using Selenium WebDriver.
Assisted Practice: Guidelines
1. Demonstrate ID as a locator.
XPath is the XML path and query language for selecting nodes from an XML document which is a
W3C recommendation.
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”
! 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:
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
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.
Radio buttons and checkboxes can be handled by below methods of WebElement class:
The following methods are available in Select class provided by Selenium. These are applicable for drop-
down as well as multi-select components.
• selectByVisibleText()
• Select an option
• selectByValue()
• selectByIndex()
The following image shows how a complex HTML table would appear on a webpage:
HTML Table Methods
Duration: 60 min.
Problem Statement:
Demonstrate how web elements are handled in Selenium.
Assisted Practice: Guidelines
Duration: 60 min.
Problem Statement:
Demonstrate how to automate calendars on the web page
Assisted Practice: Guidelines
Steps to perform:
JavaScript alerts
Alert = driver.switchTo().alert() // Tells the driver to switch focus on alert 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
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
The two types of parameters the window() method can take are:
Exception to be handled
NoSuchWindowException // This exception triggers when the system tries to switch focus on a window that
does not exist.
HTML 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.
Right click
Double click
Mouse hover
User Interactions Automation
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()
selectMultipleRows.perform();
Working with External Elements
Duration: 60 min.
Problem Statement:
Using Selenium WebDriver, write a program to handle alerts.
Assisted Practice: Guidelines
Browser profile
contain
be
special
light-weight
settings
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:
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.
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
Duration: 30 min.
Problem Statement:
Demonstrate installation and configuration of AutoIT.
Assisted Practice: Guidelines
Duration: 60 min.
Problem Statement:
Demonstrate how file uploads are handled in AutoIT.
Assisted Practice: Guidelines
Features
Sikuli is preferred when the UI elements are not constantly changing and are stable.
Sikuli: Advantages
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:
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
Duration: 20 min.
Problem Statement:
Demonstrate the usage of JDBC in Selenium.
Assisted Practice: Guidelines
Duration: 90 min.
Problem Statement:
You are asked to develop a functionality using Selenium webdriver to
handle various web elements.
Before the Next Class
▪ Database handling
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