/*
* 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 ");
}
}
}
Explore the Latest in Tech & Automation: Android, iOS, Mobile Testing with Appium, Web Automation using Selenium, Python & Java Programming, Robot Framework, Shell & PowerShell Scripting, QA Tools, Spring Boot Development, Agentic AI Innovations, Free Software Resources, and Expert Tips on Designing Scalable Automation Frameworks.
Sunday, June 7, 2015
Selenium WebDriver : Example to set and invoke different browsers through WebDriver
Subscribe to:
Post Comments (Atom)
Robot Framework : Sample code to verify if Robot Framework is installed properly ? - part2
Sample code to verify if Robot Framework is installed properly ? 1. Create a file name test.robot and save it. *** Test Cases *** Sample ...
-
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...
-
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