SlideShare uma empresa Scribd logo
1 de 13
Selenium WebDriver Best
Practices
Presenter: Rajendra Narayan Mahapatra, Mindfire
Solutions
Date: 25/06/2014
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
About Me :
Total Experience:- 3.3 years
Previous Companies: Qualitree Solutions Pvt. Ltd.
PointCross.com Pvt. Ltd.
Certification:- Vskills(VS-1083) Selenium Certification
Skills :- Selenium RC, Selenium WebDriver, QTP, Manual
Testing,SQL
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
AGENDA / Topic INDEX
--> Wait Commands
1. Implicit Wait
2. Explicit Wait
--> How to handle alerts
--> How to switch to window
--> How to retrieve Text of all the links
--> How to do Mouse Over action
--> How to do Drag & Drop action
--> How to scroll to Element
--> How to take snapshot
--> How to read pdf contents
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
--> Wait Commands
1. Implicit Wait
2. Explicit Wait
Implicit Wait
------------------
Implicit Wait will wait for whole DOM (Document Object
Model) to be loaded for the specified time. If not then it
wil thoroe timeout exception.
e.g.
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SE
CONDS)
Explicit Wait
------------------
Explicit Wait will wait for certain condition to occur.
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to handle Alerts
----------------------------
// Wait For Alert To Come
WebDriverWait wait = new
WebDriverWait(driver,30);
Alert alert =
wait.until(ExpectedConditions.alertIsPresent());
// Get the Text From the Alert
String alertText = alert.getText();
System.out.println("Alert Text :"+alertText);
alert.accept();
Or
alert.dismiss();
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to switch to Window
---------------------------------
// Store the CurrentWindow for future reference
String currentWindow = driver.getWindowHandle();
String popupWindowHandle = null;
// Switch To Popup Window
for(String handle : driver.getWindowHandles()){
if(!handle.equals(currentWindow)){
popupWindowHandle = handle;
}
}
driver.switchTo().window(popupWindowHandle);
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to scroll to element
-----------------------------------------
// Assign Object for Last Train
WebElement lastTrain =
driver.findElement(By.xpath("//*[@id='divTrainsListTrainsObj']/table[1]/tbody/tr[27]/td[2
]/a"));
// Scroll to Last Train
Coordinates coordinate = ((Locatable) lastTrain).getCoordinates();
coordinate.inViewPort();
How to take snapshot
------------------------------
// Take ScreenShot
File scrFile = ((TakesScreenshot)
driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:seleniumscreenshot.png"),
true);
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to retrieve Text of all the links
-----------------------------------------
// Verify Links
List<WebElement> listOfLinks = driver.findElements(By.tagName("a"));
String linkText[] = new String[listOfLinks.size()];
int i=0;
for(WebElement l1: listOfLinks){
// Get Link Text
linkText[i] = l1.getText();
System.out.println(linkText[i]);
i++;
}
// Click on Links
for(String t : linkText){
driver.findElement(By.linkText(t)).click();
if(driver.getTitle().contains("Under Construction")){
System.out.println(t+" : Link is under construction");
}
driver.navigate().back();
}
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to read PDF contents
-----------------------------------------
// Required JAR files
1. fontbox-1.8.5.jar
2. pdfbox-1.8.5.jar
// Read PDF Contents
PDDocument pd;
pd = PDDocument.load(new File("D:seleniumVS-1083_Certified
Selenium Professional_Reading_Material.pdf"));
System.out.println("Total Number Of pages :"+pd.getNumberOfPages());
PDFTextStripper pdf = new PDFTextStripper();
System.out.println(pdf.getText(pd));
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
Question and
Answer
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
Thank you
www.mindfiresolutions.com
https://www.facebook.com/MindfireSolutions
http://www.linkedin.com/company/mindfire-solutions
http://twitter.com/mindfires

Mais conteúdo relacionado

Destaque

Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
Nick Belhomme
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automation
RIA RUI Society
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
Impetus Technologies
 

Destaque (15)

SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver Tutorial
 
Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Digital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent AutomationDigital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent Automation
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automation
 
Building a Test Automation Strategy for Success
Building a Test Automation Strategy for SuccessBuilding a Test Automation Strategy for Success
Building a Test Automation Strategy for Success
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Test Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comTest Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.com
 
Selenium Tips & Tricks
Selenium Tips & TricksSelenium Tips & Tricks
Selenium Tips & Tricks
 

Mais de Mindfire Solutions

Mais de Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Último

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Último (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Selenium Web Driver Best Practices

  • 1. Selenium WebDriver Best Practices Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Date: 25/06/2014
  • 2. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions About Me : Total Experience:- 3.3 years Previous Companies: Qualitree Solutions Pvt. Ltd. PointCross.com Pvt. Ltd. Certification:- Vskills(VS-1083) Selenium Certification Skills :- Selenium RC, Selenium WebDriver, QTP, Manual Testing,SQL
  • 3. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions AGENDA / Topic INDEX --> Wait Commands 1. Implicit Wait 2. Explicit Wait --> How to handle alerts --> How to switch to window --> How to retrieve Text of all the links --> How to do Mouse Over action --> How to do Drag & Drop action --> How to scroll to Element --> How to take snapshot --> How to read pdf contents
  • 4. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions --> Wait Commands 1. Implicit Wait 2. Explicit Wait Implicit Wait ------------------ Implicit Wait will wait for whole DOM (Document Object Model) to be loaded for the specified time. If not then it wil thoroe timeout exception. e.g. driver.manage().timeouts().implicitlyWait(60,TimeUnit.SE CONDS) Explicit Wait ------------------ Explicit Wait will wait for certain condition to occur.
  • 5. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions How to handle Alerts ---------------------------- // Wait For Alert To Come WebDriverWait wait = new WebDriverWait(driver,30); Alert alert = wait.until(ExpectedConditions.alertIsPresent()); // Get the Text From the Alert String alertText = alert.getText(); System.out.println("Alert Text :"+alertText); alert.accept(); Or alert.dismiss();
  • 6. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions How to switch to Window --------------------------------- // Store the CurrentWindow for future reference String currentWindow = driver.getWindowHandle(); String popupWindowHandle = null; // Switch To Popup Window for(String handle : driver.getWindowHandles()){ if(!handle.equals(currentWindow)){ popupWindowHandle = handle; } } driver.switchTo().window(popupWindowHandle);
  • 7. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions How to scroll to element ----------------------------------------- // Assign Object for Last Train WebElement lastTrain = driver.findElement(By.xpath("//*[@id='divTrainsListTrainsObj']/table[1]/tbody/tr[27]/td[2 ]/a")); // Scroll to Last Train Coordinates coordinate = ((Locatable) lastTrain).getCoordinates(); coordinate.inViewPort(); How to take snapshot ------------------------------ // Take ScreenShot File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("D:seleniumscreenshot.png"), true);
  • 8. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions How to retrieve Text of all the links ----------------------------------------- // Verify Links List<WebElement> listOfLinks = driver.findElements(By.tagName("a")); String linkText[] = new String[listOfLinks.size()]; int i=0; for(WebElement l1: listOfLinks){ // Get Link Text linkText[i] = l1.getText(); System.out.println(linkText[i]); i++; } // Click on Links for(String t : linkText){ driver.findElement(By.linkText(t)).click(); if(driver.getTitle().contains("Under Construction")){ System.out.println(t+" : Link is under construction"); } driver.navigate().back(); }
  • 9. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions How to read PDF contents ----------------------------------------- // Required JAR files 1. fontbox-1.8.5.jar 2. pdfbox-1.8.5.jar // Read PDF Contents PDDocument pd; pd = PDDocument.load(new File("D:seleniumVS-1083_Certified Selenium Professional_Reading_Material.pdf")); System.out.println("Total Number Of pages :"+pd.getNumberOfPages()); PDFTextStripper pdf = new PDFTextStripper(); System.out.println(pdf.getText(pd));
  • 10. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Question and Answer
  • 11.
  • 12. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Thank you