Posts

Showing posts from 2014

How to perform right click using Selenium WebDriver?

package pkg_selenium; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions;       public class DoubleClick { public static WebDriver driver;  public static void main(String args[]) throws Exception{        // Initialize WebDriver driver = new FirefoxDriver(); // Wait For Page To Load        driver.manage().timeouts().pageLoadTimeout(60,TimeUnit.SECONDS);            // Go to google Page            driver.get("http://www.google.co.in/");            // Maximize Window      driver.manage().window().maximize();     ...

How to generate XSLT Report using testNG and ANT ?

Image
Why should we go for TestNg? Answer :- TestNg annotations are very useful to control the test cases to be executed. TestNg generates a very flashy report called as XSLT report with the help of ANT. XSLT Report :- Setting Up TestNG-XSLT Report generator and ANT for Selenium Projects [Adding TestNG-XSLT report generator package to the Project] 1. Download TestNG-XSLT package from  TestNG-XSLT Package 2. Extract the package and copy the JAR files in LIB folder to the Lib Folder of your Project. [Setting up ANT] 1. Download ANT from http://ant.apache.org/bindownload.cgi 2. Extract the ZIP 3. System Properties -> Advanced System Settings -> Enviroment Variables 4. Create a New System Varable Variable Name :'ANT_HOME' and Value: ANT Path (The Location where you've extracted the contents of .ZIP) 5. Find the variable named  "Path" under System Variables and edit its value as follows.         append ";" at t...

Database Connection using Selenium WebDriver?

Test Automation using Sikuli

Image
Why Sikuli is used in Selenium automation? Sikuli automates anything you see on screen using the image recognition method to identify GUI elements. Sikuli script allows users to automate GUI interaction by using screenshots. Procedures to integrate Silkuli with Selenium:- Download  sikuli-java.jar from  https://launchpad.net/sikuli/+download Double click on  sikuli-java.jar . One popup window will appear  Click on 'OK' button.Now you can see one command prompt file named by  runSetup.cmd Double click on  runSetup.cmd. The command prompt file will be executed and one popup window will appear. Click on 'OK' button. Another popup window will appear. select 4th and 6th check boxes and click on ' Setup Now ' button.One popup window will appear. Click on 'Yes' button. It will create  sikuli-java.jar.  You have to add this  sikuli-java.jar to 'Referenced Libraries' of the Project. Steps to Create Sikuli...

How to click on each and Every Link Present on a web page and How to get the link Text?

package pkg_selenium; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class VerifyLinks { public static WebDriver driver; public static void main(String[] args) { // TODO Auto-generated method stub // Initialize WebDriver       driver = new InternetExplorerDriver(); // Wait For Page To Load driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); // Go to URL driver.get("http://newtours.demoaut.com/"); // Maximize Window driver.manage().window().maximize(); // Verify Links List<WebElement> listOfLinks = driver.findElements(By.tagName("a")); String linkText[] = new String[listOfLinks.size()]; int ...

How to scroll to a particular element in Selenium WebDriver?

package pkg_selenium; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.interactions.internal.Coordinates; import org.openqa.selenium.internal.Locatable; public class ScrollToElement { public static WebDriver driver; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub // Initialize WebDriver driver = new InternetExplorerDriver(); // Wait For Page To Load driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); // Go to URL driver.get("http://erail.in/"); // Maximize Window driver.manage().window().maximize(); // Enter Station From Code driver.findElement(By.id("txtStationFrom")).sendKeys("MS...

How to read PDF File Contents using Selenium WebDriver?

package pkg_selenium; import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.util.PDFTextStripper; import org.openqa.selenium.WebDriver; public class PDFReader { public static WebDriver driver; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub PDDocument 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)); } } Note :- Two JAR Files are required. pdfbox-1.8.5.jar fontbox-1.8.5.jar The above tow JAR files must be added to the referenced libraries.

How to upload a file using Robot Class?

package pkg_selenium; import java.awt.AWTException; import java.awt.Robot; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class UploadFile { public static WebDriver driver; public static void main(String[] args) throws InterruptedException, AWTException { // TODO Auto-generated method stub // Initialize WebDriver driver = new FirefoxDriver(); // Wait For Page To Load driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); // Go to URL driver.get("http://sandbox.checklist.com/login"); // Maximize Window driver.manage().window().maximize(); // Enter UserName driver.findElement(By.name("j_username")).clear(); driver.findElement(By.name("j_username")).sendKeys("r...

How to take Screenshot using Selenium WebDriver?

package pkg_selenium; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class TakeScreenShot { public static WebDriver driver; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub // Initialize WebDriver driver = new FirefoxDriver(); // Wait For Page To Load driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // Go to URL driver.get("https://developer.paypal.com/"); // Maximize Window driver.manage().window().maximize(); // Take ScreenShot File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("D:\\selenium\\screenshot1.png"), tru...

How to Perform Mouse Over action using Selenium WebDriver?

package pkg_selenium; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; public class MouseOverAction { public static WebDriver driver; public static void main(String[] args)throws Exception{ // TODO Auto-generated method stub // Initialize WebDriver driver = new FirefoxDriver(); // Wait For Page To Load driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); // Go to URL driver.get("http://www.flipkart.com/"); // Maximize Window driver.manage().window().maximize(); // Mouse Over On 'Men' link Actions builder = new Actions(driver); builder.moveToElement(driver.findElement(By.xpath("//div[@class='top-menu unit']//a/span[contains(text(),'Men')]"))).perform(); Thread.sleep(5000L); // Wait For Page To Load ...

How to Handle Alert using Selenium WebDriver?

package pkg_selenium; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class HandleAlert { public static WebDriver driver; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub // Initialize WebDriver driver = new FirefoxDriver(); // Wait For Page To Load driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); // Go to URL driver.get("http://testwisely.com/demo/popups"); // Maximize Window driver.manage().window().maximize(); // Click on 'Buy Now' Button driver.findElement(By.xpath("//input[@value=' Buy Now ' and @type='button']")).click(); // Wait For Ale...