SlideShare a Scribd company logo
2
Most read
6
Most read
16
Most read
SELENIUM WITH JAVA
GOUSALYA RAMACHANDRAN
WHY DO YOU NEED AUTOMATION?
 Automation helps to ease the repetitive tasks of Manual testers. Automation can cover many scenarios
within a little time
 However automation does not replace manual testing.
 In fact, you have to test software manually before you run automated testing.
 Even though manual testing requires much effort, without it you cannot be sure that automation is
possible.
WHAT IS SELENIUM?
 Selenium is an open source automation test suite of different tools focused to automate web
application.
 Selenium consists of the following tools
 Selenium Integrated Development Environment (Selenium IDE)
 Selenium Remote Control (Selenium RC)
 Selenium WebDriver
 Selenium Grid
WHY WAS SELENIUM INTRODUCED?
Repetitive testing
JavaScriptExecutor
As this is pure JS, requires to be
placed within the application
Selenium RC
Allow the JavaScriptExecutor to be
used by different applications
Selenium IDE
Firefox extension that can
automate through a record-and-
playback feature
Selenium WebDriver
Cross platform(not limited to JS)
and control browser from OS
level
Selenium 2
Selenium 3
Improvements
Selenium Grid
Sending selenium commands to
multiple machines
SELENIUM WEBDRIVER
 Unlike other selenium tools, WebDriver does not rely on JavaScript for Automation. It communicates
directly to the browser
 Selenium WebDriver supports Java. C#, Ruby, Python, JS
 Like selenium , WebDriver can only support web based applications. Also, it cannot readily support new
browsers
SELENIUM WEBDRIVER WITH JAVA - INSTALLATION
1. Install Java
2. Install Eclipse IDE
3. Download selenium client jar file from https://selenium.dev/downloads/
4. Create a Java project
5. Import the downloaded jar files to your library
SELENIUM WEBDRIVER WITH JAVA - BASIC COMMANDS
 Getting a web page
 driver.get("www.javatpoint.com")
 driver.Navigate().to("https://javatpoint.com/selenium-tutorial");
<html>
<head>
</head>
<body>
<form method="post" action="">
<input type="text" id="Input1" name="Input tag 1" class="MyClass" value="This is the first input"/>
</body>
</html>
 Locating elements (Some of them are listed below)
 driver.findElement(By.id("id")) //Input1
 driver.findElement(By.name("id")) //Input tag 1
 driver.findElement(By.xpath("id")) // //input
 driver.findElement(By.cssSelector("id")) //input#Input1
 driver.findElement(By.tagName("id")) // input
 driver.findElement(By.className("id")) // MyClass
SELENIUM WEBDRIVER WITH JAVA – BASIC COMMANDS
 Basic Input field commands
driver.findElement(By.id("id")).
 sendKeys()
 clear()
 getText()
 click()
 Browser events (to use this we have to use driver.navigate().to("<url>"))
 driver.navigate().back();
 driver.navigate().forward();
 driver.navigate().refresh();
SELENIUM WEBDRIVER WITH JAVA – BASIC COMMANDS
 Closing the browser
 driver.close();
 Close all the browser instances (windows) associated with the driver
 driver.quit();
 Other commands
 Actions
 Switches
 getWindowHandles()/getWindowHandle()
 Handling alerts
SELENIUM WEBDRIVER WITH JAVA – WAIT COMMANDS
 Implicit wait
 Applied for the driver instance
 Wait before it throws a "No Such Element Exception".
driver.manage().timeouts().implicitlyWait(<Time to wait>, TimeUnit.SECONDS); // Can be seconds, milliseconds,
minutes etc.
 Explicit Wait
 Wait for certain conditions (Expected Conditions) to be ;
 True within the given time
 False when the given time exceeds
 Applied for specific element
WebDriverWait wait = new WebDriverWait(<Webdriver variable name> ,<Time to wait in seconds>);
WebElement elementName = wait.Until(ExpectedCondition.visibilityOfElementLocated(By.xpath("<xpath
location>")));
SELENIUM WEBDRIVER WITH JAVA – WAIT COMMANDS
 Fluent Wait
 Wait for a condition, as well as the frequency with which we want to check the condition before throwing an
exception
Wait wait = new FluentWait(WebDriver reference)
.withTimeout(timeout, SECONDS)
.pollingEvery(timeout, SECONDS)
.ignoring(Exception.class);
 Thread.sleep(<time in ms>)
 Helps to sleep / suspend the test execution for the given time. This is not recommended for code publishing.
Can be used for debugging.
SELENIUM WEBDRIVER WITH JAVA – ASSERT AND VERIFY
 Both Assert and Verify commands are used to find whether a given input is present or not on the
webpage.
 When an “assert” command fails, the test execution will be aborted. So when the Assertion fails, all the
test steps after that line of code are skipped.
 When a “verify” command fails, the test will continue executing and logging the failure.
SELENIUM WEBDRIVER WITH JAVA – ASSERT AND VERIFY
//ASSERTION
Assert.assertEquals(ExpectedTitle, CurrentTitle);
System.out.println("Step after assert") ; //Will not be executed if the above assert fails
//To convert an assertion to verification,
try{
Assert.assertEquals(ExpectedTitle, CurrentTitle);
System.out.println("Verification passed");
}catch (Exception e){
System.out.println("Verification failed");
}
System.out.println("Step after assert") ; //Will be executed if the above assert fails
SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE
 Open Chrome browser
 Navigate to https://www.google.com
 Verify the Title
 Close the browser
SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AS {
public static void main(String[] args) {
// The Path to your chrome driver
System.setProperty("webdriver.chrome.driver", "G:chromedriver.exe");
// Creating the driver object
WebDriver driver = new ChromeDriver();
String baseUrl = "http://www.google.com";
String expectedTitle = "Google";
String actualTitle = "";
SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE
// Navigate to the url using chrome
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)) {
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
// close Chrome
driver.close();
}
}

More Related Content

What's hot (20)

PPTX
Selenium test automation
Srikanth Vuriti
 
PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PPT
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
PPT
Test Automation Framework Designs
Sauce Labs
 
PPTX
Hybrid automation framework
doai tran
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PPTX
Automation - web testing with selenium
Tzirla Rozental
 
DOCX
Selenium WebDriver FAQ's
Praveen Gorantla
 
PPTX
Selenium ppt
Aneesh Rangarajan
 
PPTX
Test automation
Xavier Yin
 
ODP
Selenium ppt
Anirudh Raja
 
PPTX
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Edureka!
 
PDF
Test Automation
nikos batsios
 
PDF
Software Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Edureka!
 
PPTX
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
PPTX
Test Automation Using Selenium
Nikhil Kapoor
 
PPTX
Writing Test Cases 20110808
slovejoy
 
PPT
Selenium ppt
Pavan Kumar
 
PPT
Selenium
Kalyan ch
 
PDF
Test Automation
rockoder
 
Selenium test automation
Srikanth Vuriti
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Test Automation Framework Designs
Sauce Labs
 
Hybrid automation framework
doai tran
 
Selenium Automation Framework
Mindfire Solutions
 
Automation - web testing with selenium
Tzirla Rozental
 
Selenium WebDriver FAQ's
Praveen Gorantla
 
Selenium ppt
Aneesh Rangarajan
 
Test automation
Xavier Yin
 
Selenium ppt
Anirudh Raja
 
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Edureka!
 
Test Automation
nikos batsios
 
Software Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Edureka!
 
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
Test Automation Using Selenium
Nikhil Kapoor
 
Writing Test Cases 20110808
slovejoy
 
Selenium ppt
Pavan Kumar
 
Selenium
Kalyan ch
 
Test Automation
rockoder
 

Similar to Selenium with java (20)

PPTX
Selenium Automation
Pratyush Majumdar
 
PPTX
Selenium introduction
Pankaj Dubey
 
PPTX
Selenium web driver
Roman Savitskiy
 
PDF
Mobile Test Automation using one API and one infrastructure
Michael Palotas
 
PPTX
Selenium web driver
Sun Technlogies
 
PPTX
Selenium using Java
F K
 
PPTX
Automation With Selenium
kgrammer
 
PPTX
Selenium
Rakshitha Raviprakash
 
PPTX
Selenium
Batch2016
 
PPTX
Selenium
Batch2016
 
PPTX
Selenium
Batch2016
 
PPT
Selenium (1) (1)
Vishwan Aranha
 
PPTX
Selenium
Ivan Aranha
 
PPTX
Step by step - Selenium 3 web-driver - From Scratch
Haitham Refaat
 
PPTX
Basics of selenium containing features of selenium
Madhuri Lonikar
 
PPTX
Learn SELENIUM at ASIT
ASIT
 
PPTX
Best java automation training institute in Bangalore - Selenium Labs
Selenium Labs
 
PDF
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
PDF
Lesson_06_Software_and_Automation_Testing_Frameworks.pdf
Minh Quân Đoàn
 
Selenium Automation
Pratyush Majumdar
 
Selenium introduction
Pankaj Dubey
 
Selenium web driver
Roman Savitskiy
 
Mobile Test Automation using one API and one infrastructure
Michael Palotas
 
Selenium web driver
Sun Technlogies
 
Selenium using Java
F K
 
Automation With Selenium
kgrammer
 
Selenium
Batch2016
 
Selenium
Batch2016
 
Selenium
Batch2016
 
Selenium (1) (1)
Vishwan Aranha
 
Selenium
Ivan Aranha
 
Step by step - Selenium 3 web-driver - From Scratch
Haitham Refaat
 
Basics of selenium containing features of selenium
Madhuri Lonikar
 
Learn SELENIUM at ASIT
ASIT
 
Best java automation training institute in Bangalore - Selenium Labs
Selenium Labs
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Lesson_06_Software_and_Automation_Testing_Frameworks.pdf
Minh Quân Đoàn
 
Ad

Recently uploaded (20)

PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Executive Business Intelligence Dashboards
vandeslie24
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Ad

Selenium with java

  • 2. WHY DO YOU NEED AUTOMATION?  Automation helps to ease the repetitive tasks of Manual testers. Automation can cover many scenarios within a little time  However automation does not replace manual testing.  In fact, you have to test software manually before you run automated testing.  Even though manual testing requires much effort, without it you cannot be sure that automation is possible.
  • 3. WHAT IS SELENIUM?  Selenium is an open source automation test suite of different tools focused to automate web application.  Selenium consists of the following tools  Selenium Integrated Development Environment (Selenium IDE)  Selenium Remote Control (Selenium RC)  Selenium WebDriver  Selenium Grid
  • 4. WHY WAS SELENIUM INTRODUCED? Repetitive testing JavaScriptExecutor As this is pure JS, requires to be placed within the application Selenium RC Allow the JavaScriptExecutor to be used by different applications Selenium IDE Firefox extension that can automate through a record-and- playback feature Selenium WebDriver Cross platform(not limited to JS) and control browser from OS level Selenium 2 Selenium 3 Improvements Selenium Grid Sending selenium commands to multiple machines
  • 5. SELENIUM WEBDRIVER  Unlike other selenium tools, WebDriver does not rely on JavaScript for Automation. It communicates directly to the browser  Selenium WebDriver supports Java. C#, Ruby, Python, JS  Like selenium , WebDriver can only support web based applications. Also, it cannot readily support new browsers
  • 6. SELENIUM WEBDRIVER WITH JAVA - INSTALLATION 1. Install Java 2. Install Eclipse IDE 3. Download selenium client jar file from https://selenium.dev/downloads/ 4. Create a Java project 5. Import the downloaded jar files to your library
  • 7. SELENIUM WEBDRIVER WITH JAVA - BASIC COMMANDS  Getting a web page  driver.get("www.javatpoint.com")  driver.Navigate().to("https://javatpoint.com/selenium-tutorial"); <html> <head> </head> <body> <form method="post" action=""> <input type="text" id="Input1" name="Input tag 1" class="MyClass" value="This is the first input"/> </body> </html>  Locating elements (Some of them are listed below)  driver.findElement(By.id("id")) //Input1  driver.findElement(By.name("id")) //Input tag 1  driver.findElement(By.xpath("id")) // //input  driver.findElement(By.cssSelector("id")) //input#Input1  driver.findElement(By.tagName("id")) // input  driver.findElement(By.className("id")) // MyClass
  • 8. SELENIUM WEBDRIVER WITH JAVA – BASIC COMMANDS  Basic Input field commands driver.findElement(By.id("id")).  sendKeys()  clear()  getText()  click()  Browser events (to use this we have to use driver.navigate().to("<url>"))  driver.navigate().back();  driver.navigate().forward();  driver.navigate().refresh();
  • 9. SELENIUM WEBDRIVER WITH JAVA – BASIC COMMANDS  Closing the browser  driver.close();  Close all the browser instances (windows) associated with the driver  driver.quit();  Other commands  Actions  Switches  getWindowHandles()/getWindowHandle()  Handling alerts
  • 10. SELENIUM WEBDRIVER WITH JAVA – WAIT COMMANDS  Implicit wait  Applied for the driver instance  Wait before it throws a "No Such Element Exception". driver.manage().timeouts().implicitlyWait(<Time to wait>, TimeUnit.SECONDS); // Can be seconds, milliseconds, minutes etc.  Explicit Wait  Wait for certain conditions (Expected Conditions) to be ;  True within the given time  False when the given time exceeds  Applied for specific element WebDriverWait wait = new WebDriverWait(<Webdriver variable name> ,<Time to wait in seconds>); WebElement elementName = wait.Until(ExpectedCondition.visibilityOfElementLocated(By.xpath("<xpath location>")));
  • 11. SELENIUM WEBDRIVER WITH JAVA – WAIT COMMANDS  Fluent Wait  Wait for a condition, as well as the frequency with which we want to check the condition before throwing an exception Wait wait = new FluentWait(WebDriver reference) .withTimeout(timeout, SECONDS) .pollingEvery(timeout, SECONDS) .ignoring(Exception.class);  Thread.sleep(<time in ms>)  Helps to sleep / suspend the test execution for the given time. This is not recommended for code publishing. Can be used for debugging.
  • 12. SELENIUM WEBDRIVER WITH JAVA – ASSERT AND VERIFY  Both Assert and Verify commands are used to find whether a given input is present or not on the webpage.  When an “assert” command fails, the test execution will be aborted. So when the Assertion fails, all the test steps after that line of code are skipped.  When a “verify” command fails, the test will continue executing and logging the failure.
  • 13. SELENIUM WEBDRIVER WITH JAVA – ASSERT AND VERIFY //ASSERTION Assert.assertEquals(ExpectedTitle, CurrentTitle); System.out.println("Step after assert") ; //Will not be executed if the above assert fails //To convert an assertion to verification, try{ Assert.assertEquals(ExpectedTitle, CurrentTitle); System.out.println("Verification passed"); }catch (Exception e){ System.out.println("Verification failed"); } System.out.println("Step after assert") ; //Will be executed if the above assert fails
  • 14. SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE  Open Chrome browser  Navigate to https://www.google.com  Verify the Title  Close the browser
  • 15. SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class AS { public static void main(String[] args) { // The Path to your chrome driver System.setProperty("webdriver.chrome.driver", "G:chromedriver.exe"); // Creating the driver object WebDriver driver = new ChromeDriver(); String baseUrl = "http://www.google.com"; String expectedTitle = "Google"; String actualTitle = "";
  • 16. SELENIUM WITH JAVA : SIMPLE CODE EXAMPLE // Navigate to the url using chrome driver.get(baseUrl); // get the actual value of the title actualTitle = driver.getTitle(); if (actualTitle.contentEquals(expectedTitle)) { System.out.println("Test Passed!"); } else { System.out.println("Test Failed"); } // close Chrome driver.close(); } }