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: Qual...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
AGENDA / Topic INDEX
--> Wait Commands
1. Implicit Wait
2. Expli...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
--> Wait Commands
1. Implicit Wait
2. Explicit Wait
Implicit Wai...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to handle Alerts
----------------------------
// Wait For Al...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to switch to Window
---------------------------------
// Sto...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to scroll to element
---------------------------------------...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to retrieve Text of all the links
--------------------------...
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to read PDF contents
---------------------------------------...
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
ht...
Selenium Web Driver Best Practices
Upcoming SlideShare
Loading in...5
×

Selenium Web Driver Best Practices

1,041

Published on

WebDriver is the most efficient way for automating applications using selenium. This presentation focuses on the best practices on WebDriver.

Published in: Software, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,041
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
96
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Selenium Web Driver Best Practices"

  1. 1. Selenium WebDriver Best Practices Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Date: 25/06/2014
  2. 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. 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. 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. 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. 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. 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. 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. 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. 10. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Question and Answer
  11. 11. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Thank you
  12. 12. www.mindfiresolutions.com https://www.facebook.com/MindfireSolutions http://www.linkedin.com/company/mindfire-solutions http://twitter.com/mindfires

×