Skip to main content

SELENIUM - Launching IE, Chrome, Firefox Browsers

Launching IE, Chrome, Firefox Browsers

  • Launching IE, Chrome, Firefox Browsers with Selenium WebDriver

public class LaunchingBrowsers{

 public static String str = "Chrome"; //change to IE and Firefox

 public static void main(String args[]) throws InterruptedException
 {

  System.setProperty("webdriver.chrome.driver" , "C:\\Selenium_Projects\\Geo_Driver\\chromedriver.exe");
  System.setProperty("webdriver.ie.driver","C:\\Selenium_Projects\\Geo_Driver\\IEDriverServer.exe");
  System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"C:\\Selenium_Projects\\Geo_Driver\\geckodriver.exe");

  WebDriver driver=null;

  if(str.equals("Chrome"))
  {
   //System.out.println("uma");
    driver= new ChromeDriver();
  }
  else if (str.equals("IE"))
  {
   driver = new InternetExplorerDriver();
  }
  else if (str.equals("FireFox"))
  {
      DesiredCapabilities capabilities = DesiredCapabilities.firefox();
      //capabilities.setCapability("firefox_binary","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
      capabilities.setCapability("platform", "WIN10");
      capabilities.setCapability("version", "53.0");
      capabilities.setCapability("marionette", true);
      capabilities.setCapability("acceptSslCerts", true);
      driver = new FirefoxDriver(capabilities);
  }
  driver.get("http://www.guru99.com");
  driver.close();

 }
}

Comments

Popular posts from this blog

SELENIUM GRID -Launching IE, Chrome, Firefox Browsers

SELENIUM GRID  Launching IE, Chrome, Firefox Browsers with selenium Grid public class Grid_TestCase { @Test public void mailTest() throws MalformedURLException{ DesiredCapabilities dr=null; String browserType ="Firefox"; WebDriver driver; if(browserType.equals("Firefox")){ System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"C:\\Selenium_Projects\\Geo_Driver\\geckodriver.exe"); dr = DesiredCapabilities.firefox(); dr.setBrowserName("firefox"); dr.setPlatform(Platform.VISTA); dr.setCapability("platform", "WIN7");  dr.setCapability("version", "53.0");  dr.setCapability("marionette", true);  dr.setCapability("acceptSslCerts", true);      driver=new RemoteWebDriver(new URL("http://10.76.174.34:5566/wd/hub"), dr);    driver.get("http://guru99.com");  String aName = driver.getTitle(); if(aName.cont...

SELENIUM-TestNG - Prioritizing the tests

Managing Priorities in TestNG  Prioritizing the tests using TestNG and Enabling, Disabling the Testcases & adding Time. package packTwo; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class DependenyAnnot{ @Test public void OpeningBrowser() { System.out.println("Executing Opening Browser");   } @Test(dependsOnMethods={" OpeningBrowser" }, alwaysRun=true) // If Flight Booking Method depends on Opening Browser Method. Even if OpeningBrowse testcase fails but you still want to execute FlightBooking testcase then use command alwaysRun =True public void FlightBooking() { System.out.println("Executing Flight Booking"); } @Test(timeOut=5000) // If a TestCase is required to complete in some time, here if complete execution does not happen in 5000 millisecond script wi...

SELENIUM -Screen Shot

SELENIUM - Screen Shot public class Guru99TakeScreenshot  { @Test public void testGuru99TakeScreenShot() throws Exception { WebDriver driver; System.setProperty ("webdriver.chrome.driver","C:\\Selenium_Projects\\Geo_Driver\\chromedriver.exe" ); driver = new ChromeDriver(); //goto url driver.get("http://demo.guru99.com/V4/");  //Call take screenshot function  takeSnapShot(driver,"c://Selenium_Projects//test.png") ;      }     /**      * This function will take screenshot      * @param webdriver      * @param fileWithPath      * @throws Exception      */ public static void takeSnapShot(WebDriver webdriver,String fileWithPath) throws Exception { //Convert web driver object to TakeScreenshot TakesScreenshot scrShot =((TakesScreenshot)webdriver); //Call getScreenshotAs method to create image file File SrcFile=scrShot.getScreenshot...