Automation Testing
Automation Testing
By Kannathasan E
Topics to be covered
● What is Manual and automation testing?
● Setup
● Why Java and Selenium Required
● Selenium overview
● HTML Basic
● Selenium locator and types
● Selenium webdriver hierarchy
● Basic Selenium commands
● Alert Handling
● Drop down handling
● File Uploading
● Window handling
● Screenshots
● Waits in selenium
● iFrame handling
Topics to be covered
● Keyboard and Mouse hover handling
● JavascriptExecutor
● WebDriver Manager
● Web Table
● TestNG framework - (Data Provider)
● How to read the data from excel file - Apache POI
● Basic of Maven
● Basic of POM
● What is framework and it is types?
● Data Driven framework and explanation with demo.
● Basic of Git and it commands
Overview of Testing
Manual Testing vs Automation Testing
Manual Testing
● Performing the testing without using any tools is known as Manual
Testing. Here a tester / person will do the testing.
Automation Testing
● Performing the testing with the help of tools is known as Automation
Testing. Here instead of a person, a tool will perform the testing. The
tool used for replacing the person is nothing but a Test Automation
tool (Selenium , Test Complete etc.,)
● Automation testing helps in reducing the test execution time.
How can a tool perform Testing ?
● Testers will do some coding and put the developed code into the
Automation tool. Automation tool will perform testing with the help of
the code developed by the testers.
When to Automate?
Setup
● Download Java 11 version-
https://www.oracle.com/in/java/technologies/javase/jdk11-archive
-downloads.html
● Java -version
● JAVA_HOME - JDK path - In user variable environment
● Path - Add JDK till Bin
● Eclipse -
https://www.eclipse.org/downloads/packages/release/2019-12/r
● Go to the software which is download and click the exe file
● ChromeDriver - https://chromedriver.chromium.org/downloads
● https://googlechromelabs.github.io/chrome-for-testing/
Why JAVA?
● Open source
● Widely used
● Matured language existing over 20 years
● Used in multiple companies
● Lot of libraries available
● Based on OOPS
● Selenium with Java have most of the Jobs in the market
Why JAVA?
● Open source
● Widely used
● Matured language existing over 20 years
● Used in multiple companies
● Lot of libraries available
● Based on OOPS
● Selenium with Java have most of the Jobs in the market
Software required
● Java - Installing Java 8 - Setting environment Variables
● Human readable code to machine readable code (0’s and 1’s) ( By Compiler) it
is under Jdk(Java development kit) -> bin->javac
● Java Runtime environment ( You can only run) -> Jre file you can see only Java
file
What is IDE?
● Integrated Development Environment
● Eclipse or Intellij
● Intellij Download
Selenium
Selenium in simple terms is a Test Automation Tool. i.e. Instead of a person
performing testing manually, Selenium tool will automatically perform the testing
with the help of developed code.
Type of Applications that Selenium can automate
● Selenium can only automate Web Applications (i.e. The applications which run
on the browser).
Example: https://www.msn.com
● Selenium cannot automate Desktop Applications or Mobile Applications (i.e.
The applications which don't run on the browsers).
Example: Skype, Adobe PDF Reader and many more.
● Selenium is a free tool (Opensource) (i.e. You don’t need to pay any license
amount for using Selenium tool.)
Different Browsers supported by Selenium
Different Operating Systems / Programming Languages
supported by Selenium
Different Components in Selenium
Selenium is not a single tool. Instead it is a combination of tools like
Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid. Out
of all these tools, Selenium RC is outdated and can be ignored completely.
Different versions of Selenium
Java Concept you should Aware
● Array
● String
● Interface
● Class
● Conditional statements
● Abstract Class
● Abstract Method
● Inheritance
● List / Set
● Return Type
● Exception handling
● File Handling
HTML Tags
<html> HTML Document
<head> Page Information
<title> Name in the title bar
<body> Page Contents
Lists
<ul> Unordered List
<ol> ordered List
<li> List item
<dl> Definition List
<dt> Definition Term
<dd> Term Description
Continue..,
Links
Forms
<form> Forms
sendKeys("[email protected]");
● Even though id is the most preferred locator, obviously it is not realistic for all
objects to have ids on a web page. In some cases, developers will give non-unique
ids on a web page, in that case id should be avoided.
● NoSuchElementException Happens when the locators are unable to find or
access elements on the web page or application. Ideally, the exception occurs due
to the use of incorrect element locators in the findElement(By, by) method.
● To handle this exception, use the wait command. Use Try/Catch to ensure that the
program flow is interrupted if the wait command doesn’t help.
Name Locator
● This is also the most efficient way to locate an element with a name
attribute. With this strategy, the first element with the value name
attribute will be returned.
● In case it is having the same name it will perform the action of the first
finding the element
● driver.findElement(By.name("login")).sendKeys("seleniumtesting@yah
oo.com"); //name locator for text box
LinkText Locator
● Selenium linkText locator is used for identifying the hyperlinks on a
web page. It can be identified with the help of an anchor tag “a”. In
order to create the hyperlinks on a web page, you can use anchor
tags.
● when we have various hyperlinks with the exact text on the web page,
Selenium would go on to choose the one that appears first.
● driver.findElement(By.partiallinkText("Difficulty")).click();
//partiallinkText locator for links
Tag Name Locator
● The TagName locator in Selenium can use HTML tag names such as
div, button, input, anchor tag, and so on to identify web page
elements.
● By.tagName("a");
("a"): The tagName locator returns all the elements from the page that
contains a specified tag “a”
https://dzone.com/articles/locating-elements-by-tagname-in-selenium
Class Name Locator
● Use the Class attribute for identifying the object
● https://dzone.com/articles/selenium-java-tutorial-class-name-locator-i
n-selen
CSS Syntax
CSS Selector Locator
● https://www.toolsqa.com/selenium-webdriver/css-selectors-in-seleniu
m/
● CSS selector is always faster than Xpath
XPATH
● XPath stands for XML (Extensible Markup Language) Path language
There are two types of XPath in Selenium.
Absolute XPath
Relative XPath
Absolute Xpath
● It is the easiest way to find the element but if any changes are made
in the path of the element then this XPath gets failed. So, This is the
main disadvantage of absolute XPath.
● It begins with a single forward slash (/) which selects the element
from the root HTML node
● E.g - /html/body/div/div[1]/div[2]/form/div[3]/div/div/div[2]/input
● isMultiple(): boolean
● isMultiple() " method, which determines whether the web element in say
supports multiple selections. It returns a boolean value, i.e., True/False,
without taking any argument.
Drop down Method syntax - deselect
When the application is slow and network issue Implicit wait is better choice
Implicit Wait Selenium
● Selenium tries to find the element without bothering about whether elements
are loaded or not, and selenium throws NoSuchElementException if the
element is not present.
● Implicitly wait is one of the ways to request selenium not throw any exception
until provided time.
● The default wait time of the selenium is 500 milliseconds, implicitly wait
overrides the default wait time of the selenium.
● If the element is found before implicitly wait time, selenium moves to the next
commands in the program without waiting to complete the implicitly wait
time; this wait is also called dynamic wait
● Once you set implicit wait, it will be applicable to all calls of findElement() and
findElements() methods.
Implicit Wait Selenium
● You must be thinking, sleep() and implicit wait sound same in behavior then
what is difference? Why should we use implicit wait over sleep()?
● Because Implicit wait is a dynamic wait. When we use sleep() method, it
makes the current thread idle unconditionally. It means if we set sleep
timeout as 5 seconds, thread will wait for 5 seconds completely (If not
interrupted). But if we use implicit wait, it waits for an element to be present
but does not sit idle. It keeps polling for element and returns as soon as
element is found.
● So if we set implicit wait as 10 seconds and element is found in 5
seconds, driver will NOT wait for remaining 5 seconds. It saves 5 seconds
of execution time. In short , sleep will sit idle for specified timeout and after
timeout we need to look for element explicitly but implicit wait does both
steps together and that too dynamically.
Pros and cons of Implicit Wait
● We cannot mention any explicit condition to be met before performing any
operation using Implicit Wait.
● Implicit Wait, will not bother if the element is hidden or can be interacted. If
the element is present in the DOM, it will immediately release the wait and will
start performing the further operations which are not desirable at most of the
situations.
● Implicit Wait is applicable for all the web elements found using the web driver
and implicit wait has power until driver.quit() is encountered.
● We can't control the polling time-frequency using implicit wait.
Explicit Wait Selenium
● Explicit wait can be called as conditional wait / WebdriverWait.
● The explicit wait is used to tell the Web Driver to wait for certain conditions or
the maximum time limit before throwing an Exception .
● WebDriver throws "ElementNotVisibleException" if explicit wait fails.
● WebDriverWait is the class
● ExpectedConditions is the class / ExpectedCondition is Interface
https://learn-automation.com/parallel-execution-in-selenium/
Where to see the Reports? In TestNG
How to run failure test cases
@Test Attributes
How to run group of test cases
DataProvider in TestNG
Advantage of TestNG
● @Test: Methods annotated with @Test are called test methods that serve as a
unit test. In @Test methods, we will write the logic of the application which we
want to automate.
● We can pass attributes to our test method. The output depends on these test
methods for success or failure.
Read data from Excel
Dependency
1. Apache POI
Apache POI, where POI stands for (Poor Obfuscation Implementation) is an API that offers a collection of
Java libraries that helps us to read, write, and manipulate different Microsoft files such as excel sheets,
power-point, and word files.
https://mvnrepository.com/artifact/org.apache.poi/poi
https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
Pre- condition
Steps to implement
1. Locate the file 2. Locate the workbook & Sheet 3. Read the data from the cell (Rows & Column)