我正在使用 selenium webdriver 进行测试,并希望有机会选择在哪个浏览器中运行每组测试。我使用工厂来实现这一点,但由于某种原因,我似乎无法让它工作。这是我所拥有的
class WebDriverFactory {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
private WebDriverFactory() {
}
public static void setChromePath() {
// Set file path here
}
public static void setIEPath() {
// Set file path here
}
public static WebDriver getWebDriver(String type) {
System.out.println("choose a browser:");
Scanner scan = new Scanner(System.in);
scan.next();
if (type.equalsIgnoreCase("chrome")) {
return createChrome();
} else if (type.equalsIgnoreCase("firefox")) {
return createFirefox();
} else if (type.equalsIgnoreCase("IE")) {
return createInternetExplorer();
} else {
return null;
}
}
private static WebDriver createChrome() {
System.setProperty("webdriver.chrome.driver", "C:/Program Files
(x86)/Google/Chrome/Application/chromedriver_win32_2.1/chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions chromeOptions = new ChromeOptions();
capabilities.setCapability("chrome.binary",
"C:/AppData/Local/Google/Chrome/Application/chrome.exe");
WebDriver driver = new ChromeDriver(capabilities);
return driver;
}
private static WebDriver createFirefox() {
WebDriver driver = new FirefoxDriver();
return driver;
}
private static WebDriver createInternetExplorer() {
File file = new File("C:/Utils/IEDriverServer_Win32_2.33.0/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
return driver;
}
}
在测试课上我有:
String type = null;
WebDriverFactory.getWebDriver(type);
当我输入一个字符串时,扫描仪似乎没有做任何事情并且浏览器没有打开?谁能帮帮我?
我现在在测试类中有这个:
System.out.println("choose a browser:");
Scanner scan = new Scanner(System.in);
String type = scan.next();
WebDriverFactory.getWebDriver(type);