/*
* 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 ");
}
}
}
A blog about new technology, Android, iOS, Mobile Automation, Appium, Web Automation, Selenium, JAVA, Shell Scipting, Powershell, Testing Tools, QA, Spring Boot, Free Software, How to design best frameworks etc..
Selenium WebDriver : Example to set and invoke different browsers through WebDriver
Subscribe to:
Post Comments (Atom)
πAnnouncement : Visit the new website/blog π
πππ Announcement : Visit the new website/blog πππ Dear readers, Thank you for reading my blog. If you could have used the little info...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
To setup Appium for mobile automation, you will need below items to be configured in your test environment. 1. Appium server : 1.1 D...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...
No comments:
Post a Comment