我无法将BrowserFactory连接到Selenium Grid。有什么想法为什么以下代码不起作用?
public static WebDriver getDriver() throws Exception {
try {
// Load the driver selected by user
Properties p = new Properties();
FileInputStream fi = new FileInputStream(Constant.CONFIG_PROPERTIES_DIRECTORY);
p.load(fi);
if(p.getProperty("use_grid").equalsIgnoreCase("true")) {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.getBrowserName();
desiredCapabilities.setPlatform(Platform.WINDOWS);
return new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), desiredCapabilities);
}
String browserName = p.getProperty("browser");
switch (browserName) {
case "firefox":
if (null == webdriver) {
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
webdriver = new FirefoxDriver();
}
break;
感谢。
答案 0 :(得分:0)
使用selenium网格时,您似乎没有设置浏览器。尝试更改此行:
desiredCapabilities.getBrowserName();
到此:
desiredCapabilities.setBrowserName("firefox");
或者如果你的属性格式正确并且代码工作正常,那么这就是
desiredCapabilities.setBrowserName(p.getProperty("browser"));