Agenda: Day Topic Artifact & Expectation
Agenda: Day Topic Artifact & Expectation
3 How to Handle Windows & Alert Create a java class to handle Alert , Pop up
How to Handle a Select Element and List of Windows & WebElement(s)
WebElements The trainee will be able to handle Alert ,
Window & WebElement(s) using Selenium
4 Implicit Wait and Explicit Wait The trainee will be able to understand Wait
Hard Assert & Soft Assert with Junit concept in Selenium and Assert.
Suite JUnit Also how to run the Test cases using Junit
Framework
1
Agenda
Day Topic Artifact & Expectation
5,6
Exercise 1 , Automate 3 Test Cases Generate the code for Automation of 3 Test
7,8
Redo the Project using the Design Pattern POM
The trainee will be able to generate an
Refactoring Project with Page Object Model
automation.
Testing project using POM.
2
Day 1
Prerequisites
Previous knowledge
Java SE (1 year of experience)
HTTP , DOM , Javascript (1 year of experience)
Access to download gherkin-cucumber plugin https://marketplace.eclipse.org/content/cucumber-eclipse-plugin
Access to download chromedriver.exe https://chromedriver.chromium.org/downloads
3
Day 1
What is Software Testing?
Software testing is defined as an activity to check whether the actual results match the expected
results and to ensure that the software system is Defect free.
It involves execution of a software component to evaluate one or more properties of interest.
It can be either done manually or using automated tools.
4
Day 1
Scope & Traceability in SDLC
5
Day 1
Major Phases Software Development Life Cycle
6
Day 1
Types Of Software Testing
Unit Testing
Integration Testing
System Testing
Smoke Testing
Regression Testing
Beta/Acceptance Testing
Performance Testing
Load Testing
Volume Testing
Security Testing
Install Testing
Localization Testing
7
Day 1
8
Day 1
The Analysis and Design Environment
The Development Environment
The Common Build Environment
The Testing Environment:
• This has two components:
• The Systems Integration Testing Environment
• The User Acceptance Testing Environment
The Production Environment.
9
Day 1
Mapping environments vs SDLC?
1?
2?
3?
10
Day 1
What is Automation Software Testing ?
Manual Testing is performed by a human sitting in front of a computer carefully executing the test steps.
Automation Testing means using an automation tool to execute your test case suite.
The automation software can also enter test data into the System Under Test, compare expected and actual
results and generate detailed test reports. Test Automation demands considerable investments of money
and resources.
Successive development cycles will require execution of same test suite repeatedly. Using a test automation
tool, it's possible to automate this test suite and re-play it as required. Once the test suite is automated, no
human intervention or less human intervention is required. This improved ROI of Test Automation.
The goal of Automation is to reduce the number of test cases to be run manually and not to eliminate
Manual Testing altogether.
11
Day 1
Automation Framework Architecture
Development View
Development Testing Infrastructure Under Test App
App 1
Browser1
Web Front End
Eclipse IDE
Automation Framework Publi
c
Back
Test NG & Report NG End
Maven & Selenium & Spring Core & JPA pull/push version
& assets D
B
JDK 1.8
GIT
Master Dev
ESB/EDI
DB Repo
VMware
Browser1
Automation
Framework
Jenkins build & deploy & execute
CI TestNG
12
Day 1
Questions
List the test environments used
in an SDLC Test
Environmen
What are the SDLC Major Phases? t
13
Day 1
What is Selenium?
Selenium is a free (open source) automated testing suite for web applications
across different browsers and platforms. It is quite similar to HP Quick Test
Pro (QTP now UFT) only that Selenium focuses on automating web-based
applications. Testing done using Selenium tool is usually referred as
Selenium Testing.
14
Day 1
Who developed Selenium?
Seeing potential in this idea to help automate other web applications, he made
JavaScriptRunner open-source which was later re-named as Selenium Core.
15
Day 1
Selenium Suite
16
Day 1
Selenium Web Driver Architecture
HTTP over HTTP
Selenium Language
Bindings Web Drivers Web Browsers
FireFox
FireFoxDriver Browser
Java
Safari
SafariDriver Browser
Ruby
Json Wire
Protocol Chrome
ChromeDriver
c# Browser
http://localhost:8080/
{"url":"https://www.softwaretesting Edge
EdgeDriver
Python material.com"} Browser
Opera
Javasc OperaDriver
ript
Browser
So another ThoughtWork's engineer, Paul Hammant, decided to create a server that will act
as an HTTP proxy to "trick" the browser into believing that Selenium Core and the web
application being tested come from the same domain. This system became known as the
Selenium Remote Control or Selenium 1.
18
Day 1
Birth of WebDriver
Simon Stewart created WebDriver circa 2006 when browsers and web applications were
becoming more powerful and more restrictive with JavaScript programs like Selenium Core. It
was the first cross-platform testing framework that could control the browser from the OS level.
19
Day 1
WebDriver vs Selenium RC
20
Day 1
WebDriver vs Selenium RC
21
Day 1
Birth of Selenium Grid
Selenium Grid was developed by Patrick Lightbody to address the need of minimizing test
execution times as much as possible. He initially called the system "Hosted QA." It was
capable of capturing browser screenshots during significant stages, and also of sending out
Selenium commands to different machines simultaneously.
https://www.guru99.com/introduction-to-selenium-
grid.html
22
Day 1
Summary
Selenium IDE, a Firefox add-on that you can only use in creating relatively simple test cases and
test suites.
Selenium Remote Control, also known as Selenium 1, which is the first Selenium tool that allowed
users to use programming languages in creating complex tests.
WebDriver, the newer breakthrough that allows your test scripts to communicate directly to the
browser, thereby controlling it from the OS level.
Selenium Grid is also a tool that is used with Selenium RC to execute parallel tests across
different browsers and operating systems.
Selenium RC and WebDriver was merged to form Selenium 2.
23
Day 1
Automation Framework Architecture
Development View
Development Testing Infrastructure Under Test App
App 1
Browser1
Web UI
Eclipse IDE
Gherkin Cucumber Publi
c
Back
JUnit End
GIT
Master Dev
ESB/EDI
DB Repo
VMware
Browser1
Gherkin
Jenkins build & deploy & execute
CI Junit
24
Day 1
What is the HTML DOM?
The HTML DOM is a
standard object model
and programming interface for HTML.
It defines:
The HTML elements as objects
The properties of all HTML elements
The methods to access all HTML
elements
25
Day 1
Example HTML DOC
Example
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "
Hello World!";
</script>
</body>
The getElementById Method
</html>
The most common way to access an HTML element is to use the id of the element.
In the example above the getElementById method used id="demo" to find the element.
26
Day 1
Exercise
Go to http://demo.guru99.com/v1/
Type in console :
document.getElementById('message23').innerHTML = 'Hola';
27
Day 1
Finding HTML Elements
Method Description
document.getElementById(id) Find an element by element id
Type in console :
>document.getElementsByTagName('label')[1].innerHTML = 'BBB';
>document.getElementsByTagName('label')[0].innerHTML = 'AAA';
>document.getElementsByName('uid')[0].value = '123';
> Modify password input value (write down the script line)
28
Day 1
Changing HTML Elements
Property Description
element.innerHTML = new html content Change the inner HTML of an element
Method Description
Sample :
30
Day 1
Questions
1) What is an attribute in the DOM ?
31
Day 2
Xpath
XML path.
It is a language for
finding any element on
the web page using XML
path expression.
https://www.guru99.com/xpath-selenium.html
32
Day 2
Xpath
Xpath=//tagname[@attribute='value']
@: Select attribute.
Attribute: Attribute name of the element.
33
Day 2
Searching Type
Absolute XPath:
It is the direct way to find the element, but the disadvantage of
the absolute XPath is that if there are any changes made in the
path of the element then that XPath gets failed.
The key characteristic of XPath is that it begins with the single
forward slash(/) ,which means you can select the element from
the root node.
Below is the example of an absolute xpath expression of the
element shown in the below screen.
Absolute xpath:
html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[
1]/b
34
Day 2
Searching Type
Relative Xpath
For Relative Xpath the path starts from the middle of the HTML DOM
structure. It starts with the double forward slash (//), which means it can
search the element anywhere at the webpage.
You can start from the middle of the HTML DOM structure and no need
to write long xpath.
35
Day 2
Exercise using Chrome console
Go to http://demo.guru99.com/v1/
Type $x() in the inspector console section with Chrome
Xpath= $x(“//input[@type='text']”)
Xpath= //label[@id='message23']
Xpath= //input[@value='RESET']
Questions
What is the searching to find all elements with class = barone ?
36
Day 2
References Xpath
Go to https://devhints.io/xpath
Page to practice
http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
Most common functions are :
contains() // font[contains(@class,"head")]
starts-with() // font[starts-with(@class,"head")]
ends-with() // font[ends-with(@class,"head")]
name() //[starts-with(name(), 'h')]
text() //button[text()="Submit"]
37
Day 2
Configure Eclipse IDE
(https://www.techbeamers.com/running-webdriver-tests-using-maven-eclipse/)
38
Day 2
Execute the WebDriver using
ChromeDriver
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.junit.Test;
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\559482\\Desktop\\1818811\\chromedriver.exe");
40
Day 2
Locator Sample
public class ClassNameLocator {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\559482\\chromedriver.exe");
driver.manage().window().maximize();
// System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
//Opening the air bnb home page
driver.get("https://www.uber.com/mx/es");
driver.findElement(By.xpath("//a[@id='1']")).click();
driver.findElement(By.xpath("//input[@name='pickup']")).sendKeys("Tata 3" + Keys.ENTER);
driver.findElement(By.xpath("//a[@data-baseweb='button' and @aria-label='Pedir
ahora']")).click() ;
driver.close();
//closing the driver
driver.quit();
}}
41
Day 2
Questions
1) How can I Check an Xpath search expression (Tools and how )?
2) What is the difference between an absolute search and relative search in Xpath ?
3) How can I join more than 1 search condition in a Xpath Expression (section inside of the [])?
42
Day 2
Questions
1) How can I Check an Xpath search expression (Tools and how )?
2) What is the difference between an absolute search and relative search in Xpath ?
3) How can I join more than 1 search condition in a Xpath Expression (section inside of the [])?
43
Day 3
Alert & Pop Windows Handling
https://www.guru99.com/alert-popup-handling-selenium.html
import org.openqa.selenium*;
public class AlertDemo {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\559482\\Desktop\\1818811\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Alert Message handling
driver.get("http://demo.guru99.com/test/delete_customer.php");
driver.findElement(By.name("cusid")).sendKeys("53920");
driver.findElement(By.name("submit")).submit();
// Switching to Alert
Alert alert = driver.switchTo().alert();
String MainWindow=driver.getWindowHandle();
// To handle all new opened window.
Set<String> s1=driver.getWindowHandles();
Iterator<String> i1=s1.iterator();
while(i1.hasNext())
{
String ChildWindow=i1.next();
if(!MainWindow.equalsIgnoreCase(ChildWindow))
{
// Switching to Child window
driver.switchTo().window(ChildWindow);
driver.findElement(By.name("emailid")).sendKeys("gaurav.3n@gmail.com");
driver.findElement(By.name("btnLogin")).click();
// Closing the Child Window.
driver.close();
}
}
// Switching to Parent window i.e Main Window.
driver.switchTo().window(MainWindow);
45
Day 3
WebElement & WebElements
https://www.guru99.com/find-element-selenium.html
WebElement
Selenium Webdriver represents all the HTML elements as
WebElements. This class provides a mechanism to represent
them as objects & perform various actions on the related
elements. Typically, the findElement method in WebDriver
returns an object of class webElement.
WebElements
FindElements() it returns you WebElements i.e
List<WebElement> of multiple elements. It return 1 if only one
element present in it or multiple if presents more.
List<WebElement> listOfElements =driver.findElements(By.xpath("//div"));
46
Day 3
WebElement & WebElements
Example of WebElement
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\559482\\Desktop\\1818811\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/ajax.html");
// Find the radio button for “No” using its ID and click on it
driver.findElement(By.id("no")).click();
47
Day 3
WebElement & WebElements
Example of WebElements
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\559482\\Desktop\\1818811\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/ajax.html");
Methods
selectByVisibleText() and deselectByVisibleText()
selectByValue() and deselectByValue()
selectByIndex() and deselectByIndex()
IsMultiple()
DeselectAll()
49
Day 3
Questions
1) How can I access a popup Windows or another tab window using Selenium ?
50
Day 3
Questions
1) How can I access a popup Windows or another tab window using Selenium ?
51
Day 4
Implicit and Explicit Wait
https://www.guru99.com/implicit-explicit-waits-selenium.html
Implicit Wait
The implicit wait will tell to the web driver to wait for certain amount of time
before it throws a "No Such Element Exception". The default setting is 0. Once
we set the time, web driver will wait for that time before throwing an exception.
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
52
Day 4
Implicit and Explicit Wait
https://www.guru99.com/implicit-explicit-waits-selenium.html
Explicit Wait
The explicit wait is used to tell the Web Driver to wait for certain conditions
(Expected Conditions) or the maximum time exceeded before throwing an
"ElementNotVisibleException" exception.
The explicit wait is an intelligent kind of wait, but it can be applied only for
specified elements. Explicit wait gives better options than that of an implicit wait
as it will wait for dynamically loaded Ajax elements.
53
Day 4
Implicit and Explicit Wait
https://www.guru99.com/implicit-explicit-waits-selenium.html
JUnit is an open source Unit Testing Framework for JAVA. It is useful for Java
Developers to write and run repeatable tests. Erich Gamma and Kent Beck
initially develop it. It is an instance of xUnit architecture. As the name implies, it
is used for Unit Testing of a small chunk of code
56
Day 4
Junit @Annotation
@Before
@After
@Test
@BeforeClass
@AfterClass
@Ignore
@RunWith
57
Day 4
Junit @Annotation
Annotations Description
58
Day 4
Junit @Annotation
Annotations Description
59
Day 4
Junit Assert
https://junit.org/junit4/javadoc/4.8/org/junit/Assert.html
https://www.guru99.com/junit-assert.html
Assert is a method useful in determining Pass or Fail status of a test case, The
assert methods are provided by the class org.junit.Assert which extends
java.lang.Object class.
There are various types of assertions like Boolean, Null, Identical etc.
60
Day 4
Junit Assert
Method Description
1. void assertEquals(boolean expected, It checks whether two values are equals similar to equals
boolean actual) method of Object class
2. void assertFalse(boolean condition) functionality is to check that a condition is false.
6. void fail() If you want to throw any assertion error, you have fail() that
always results in a fail verdict.
7. void assertSame([String message] "assertSame" functionality is to check that the two objects
refer to the same object.
8. void assertNotSame([String "assertNotSame" functionality is to check that the two objects
message] do not refer to the same object.
61
Day 4
Junit Framework
https://www.guru99.com/junit-assert.html
Example of Assert
String string1="Junit";
String string2="Junit";
String string3="test";
String string4="test";
String string5=null;
int variable1=1;
intvariable2=2;
int[] airethematicArrary1 = { 1, 2, 3 };
int[] airethematicArrary2 = { 1, 2, 3 };
//Assert statements
assertEquals(string1,string2);
assertSame(string3, string4);
assertNotSame(string1, string3);
assertNotNull(string1);
assertNull(string5);
assertTrue(variable1<variable2);
assertArrayEquals(airethematicArrary1, airethematicArrary2);
62
Day 4
Junit Framework
Reference of all Junit Assert
https://www.journaldev.com/21681/junit-assertions
1 JUnit Assertions
1.1 fail()
1.2 assertNull() and assertNotNull()
1.3 assertSame() and assertNotSame()
1.4 assertTrue() and assertFalse()
1.5 assertEquals() and assertNotEquals()
1.6 assertArrayEquals()
1.7 assertIterableEquals()
1.8 assertThrows()
1.9 assertDoesNotThrow()
1.10 assertAll()
1.11 assertTimeout()
1.12 assertTimeoutPreemptively()
63
Day 4
Junit Test Suite
https://www.guru99.com/create-junit-test-suite.html
To run the suite test, you need to annotate a class using below-
mentioned annotations:
@Runwith(Suite.class)
@SuiteClasses(test1.class,test2.class……) or
@Suite.SuiteClasses ({test1.class, test2.class……})
With above annotations, all the test classes in the suite will start
executing one by one.
64
Day 4
Junit Advanced Features
65
Day 4
Questions
1) What is the difference between an Implicit Wait and an Explicit Wait ?
66
Day 5
Lab 1
67
Day 6
Lab 1
68
Day 7
Page Object Model is a Design Pattern which has become popular in Selenium
Test Automation. It is widely used design pattern in Selenium for enhancing
test maintenance and reducing code duplication. Page object model (POM)
can be used in any kind of framework such as modular, data-driven,
keyword driven, hybrid framework etc. A page object is an object-oriented
class that serves as an interface to a page of your Application Under Test.
The tests then use the methods of this page object class whenever they need
to interact with the User Interface (UI) of that page.
The benefit is that if the UI changes for the page, the tests themselves don’t
need to change, only the code within the page object needs to change.
Subsequently, all changes to support that new UI is located in one place.
69
Day 7
70
Day 7
Code maintainability:
There is a clean separation between test code and page specific code such as
locators and layout which becomes very easy to maintain code. Code changes
only on Page Object Classes when a UI change occurs. It enhances test
maintenance and reduces code duplication.
Object Repository:
Each page will be defined as a java class. All the fields in the page will be
defined in an interface as members. The class will then implement the interface.
Readability:
Improves readability due to clean separation between test code and page
specific code
71
Day 7
72
Day 7
73
Day 7
Example HomePage
package tcs.pageob.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
this.driver = driver;
}
travelIcon.click();
}
}
74
Day 7
Example TravelPage
WebDriver driver;
@FindBy(how=How.XPATH, using="//input[@name='pickup']") WebElement fromTravelInput;
@FindBy(how=How.XPATH, using="//a[@data-baseweb='button' and @aria-label='Pedir ahora']") WebElement requestTravelButton;
75
Day 7
Example RequestTravelTest
@Test
public void test() {
uberTravelPage.setfromTravelInput("TATA 3");
uberTravelPage.clickRequestTravelButton();
76
Day 8
ReFactoring Test Cases of Lab
77
Day 9
Add Framework Cucumber - Gherkin
78
Day 9
Add Framework Cucumber - Gherkin
79
Thank You.
80