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
Automation - web testing with selenium
Tzirla Rozental
 
PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PDF
Selenium IDE LOCATORS
Mindfire Solutions
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PDF
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
PPTX
Selenium test automation
Srikanth Vuriti
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PDF
SELENIUM PPT.pdf
RebelSnowball
 
PPT
Selenium ppt
Pavan Kumar
 
PDF
Test Automation
rockoder
 
PPT
Automation testing
Biswajit Pratihari
 
PPTX
Selenium- A Software Testing Tool
Zeba Tahseen
 
PDF
Cucumber ppt
Qwinix Technologies
 
PDF
Cypress, Playwright, Selenium, or WebdriverIO? Let the Engineers Speak!
Applitools
 
PPT
Selenium ppt
Naga Dinesh
 
PPT
Test Automation Framework Designs
Sauce Labs
 
PDF
Introduction to Robot Framework – Exove
Exove
 
PPT
Test automation using selenium
shreyas JC
 
PPTX
Introduction to Automation Testing
Archana Krushnan
 
PDF
Functional Tests Automation with Robot Framework
laurent bristiel
 
Automation - web testing with selenium
Tzirla Rozental
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Selenium IDE LOCATORS
Mindfire Solutions
 
Test Automation and Selenium
Karapet Sarkisyan
 
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
Selenium test automation
Srikanth Vuriti
 
Selenium Automation Framework
Mindfire Solutions
 
SELENIUM PPT.pdf
RebelSnowball
 
Selenium ppt
Pavan Kumar
 
Test Automation
rockoder
 
Automation testing
Biswajit Pratihari
 
Selenium- A Software Testing Tool
Zeba Tahseen
 
Cucumber ppt
Qwinix Technologies
 
Cypress, Playwright, Selenium, or WebdriverIO? Let the Engineers Speak!
Applitools
 
Selenium ppt
Naga Dinesh
 
Test Automation Framework Designs
Sauce Labs
 
Introduction to Robot Framework – Exove
Exove
 
Test automation using selenium
shreyas JC
 
Introduction to Automation Testing
Archana Krushnan
 
Functional Tests Automation with Robot Framework
laurent bristiel
 

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)

PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Tally software_Introduction_Presentation
AditiBansal54083
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
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(); } }