Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-TestNG framework
Selenium Web Driver Best Practices
-
Upload
mindfire-solutions -
Category
Software
-
view
278 -
download
0
description
Transcript of Selenium Web Driver Best Practices
Selenium WebDriver Best Practices
Presenter: Rajendra Narayan Mahapatra, Mindfire SolutionsDate: 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.SECONDS)
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 ComeWebDriverWait wait = new
WebDriverWait(driver,30);Alert alert =
wait.until(ExpectedConditions.alertIsPresent());
// Get the Text From the AlertString 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 TrainWebElement 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:\\selenium\\screenshot.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 TextlinkText[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.jar2. pdfbox-1.8.5.jar
// Read PDF ContentsPDDocument pd;pd = PDDocument.load(new File("D:\\selenium\\VS-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