Selenium WebDriver : Example to set and invoke different browsers through WebDriver


/*
* Example to set and invoke different browser in Selenium WebDriver
* Programming Language : JAVA
*/
import java.util.Scanner;

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 SettingDifferentBrowserinSelenium {

static WebDriver wd = null;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter browser which you want to invoke : ");
String browserName = sc.next();
openBrowser(browserName);

}


public static void openBrowser(String browserName){

if(browserName.equalsIgnoreCase("Mozilla")){
wd = new FirefoxDriver();
System.out.println("Browser invoked : " +browserName);

}else if(browserName.equalsIgnoreCase("Chrome")){

//for chrome browser you have to set the path
System.setProperty("webdriver.chrome.driver", "/path_to_chormedriver/chromedriver.exe"); // D:/setup/chromedriver.exe
wd = new ChromeDriver();
System.out.println("Browser invoked : " +browserName);

}else if(browserName.equalsIgnoreCase("Chrome")){

//for ie browser you have to set the path , use the IEDriverServer.exe based on your OS architecture x64bit or x86bit
System.setProperty("webdriver.ie.driver", "/path_to_iedriver/IEDriverServer.exe"); // D:/setup/IEDriverServer.exe
wd = new InternetExplorerDriver();
System.out.println("Browser invoked : " +browserName);

}else{

System.out.println("You can either invoke the default browser or display"
+ " a message to provide valid broswer name ");
}

}

}

No comments:

Post a Comment

Android : How to connect your Android device over Wifi using ADB command for App debugging

How to connect your Android device over Wi-Fi using ADB command Sometimes it requires to connect your Android dev...