Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Saturday, April 22, 2017

Open Application Using Selenium WebDriver

package com.wd.basics;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class DriverFactory {

 public static void main(String[] args) {

  WebDriver driver = DriverFactory.getDriver("chrome", "http://google.com");
  
 }

 //write a method to open application using browser name and url parameters
 public static WebDriver getDriver(String brName, String appUrl) {
  // initialize driver
  WebDriver driver = null;

  // update driver with specific browser reference
  switch (brName) {
  case "chrome":
   System.setProperty("webdriver.chrome.driver",
     "F:/SeleniumSoftware/BrowserDrivers/chromedriver.exe");
   driver = new ChromeDriver();
   break;
  case "firefox":
   System.setProperty("webdriver.gecko.driver",
     "F:/SeleniumSoftware/BrowserDrivers/geckodriver.exe");
   driver = new FirefoxDriver();
   break;
  case "ie":
   System.setProperty("webdriver.ie.driver",
     "F:/SeleniumSoftware/BrowserDrivers/IEDriverServer64.exe");
   driver = new InternetExplorerDriver();
   break;
  default:
   // if no valid browser name found exit execution
   System.out.println("browser name not found");
   System.exit(1);
  }

  // open application
  driver.get(appUrl);

  return driver;

 }
}

No comments :

Post a Comment