SlideShare a Scribd company logo
1 of 16
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

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#srivinayak
 
Selenium- A Software Testing Tool
Selenium- A Software Testing ToolSelenium- A Software Testing Tool
Selenium- A Software Testing ToolZeba Tahseen
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Edureka!
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with SeleniumKerry Buckley
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using SeleniumWeifeng Zhang
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methodsPankaj Dubey
 
Web Test Automation with Selenium
Web Test Automation with SeleniumWeb Test Automation with Selenium
Web Test Automation with Seleniumvivek_prahlad
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 

What's hot (20)

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Selenium-Locators
Selenium-LocatorsSelenium-Locators
Selenium-Locators
 
Selenium- A Software Testing Tool
Selenium- A Software Testing ToolSelenium- A Software Testing Tool
Selenium- A Software Testing Tool
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Selenium
SeleniumSelenium
Selenium
 
SELENIUM PPT.pdf
SELENIUM PPT.pdfSELENIUM PPT.pdf
SELENIUM PPT.pdf
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using Selenium
 
QSpiders - Selenium Webdriver
QSpiders - Selenium WebdriverQSpiders - Selenium Webdriver
QSpiders - Selenium Webdriver
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methods
 
Selenium presentation
Selenium presentationSelenium presentation
Selenium presentation
 
Web Test Automation with Selenium
Web Test Automation with SeleniumWeb Test Automation with Selenium
Web Test Automation with Selenium
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 

Similar to Selenium with java

Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Puneet Kala
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudCarlos Sanchez
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Edureka!
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using JavaF K
 
Learn SELENIUM at ASIT
Learn SELENIUM at ASITLearn SELENIUM at ASIT
Learn SELENIUM at ASITASIT
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsQuontra Solutions
 
Testing Ajax Web Applications
Testing Ajax Web ApplicationsTesting Ajax Web Applications
Testing Ajax Web ApplicationsTed Husted
 
Selenium Testing with TestingBot.com
Selenium Testing with TestingBot.comSelenium Testing with TestingBot.com
Selenium Testing with TestingBot.comtestingbot
 
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...Edureka!
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch Haitham Refaat
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersAjit Jadhav
 

Similar to Selenium with java (20)

Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using Java
 
Learn SELENIUM at ASIT
Learn SELENIUM at ASITLearn SELENIUM at ASIT
Learn SELENIUM at ASIT
 
Selenium (1) (1)
Selenium (1) (1)Selenium (1) (1)
Selenium (1) (1)
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Sel
SelSel
Sel
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
 
Selenium
SeleniumSelenium
Selenium
 
Testing Ajax Web Applications
Testing Ajax Web ApplicationsTesting Ajax Web Applications
Testing Ajax Web Applications
 
Selenium
SeleniumSelenium
Selenium
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Selenium Testing with TestingBot.com
Selenium Testing with TestingBot.comSelenium Testing with TestingBot.com
Selenium Testing with TestingBot.com
 
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Test automation
Test  automationTest  automation
Test automation
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

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(); } }