【问题标题】:Can't connect my 'BrowserFactory' to 'Selenium Grid'无法将我的“BrowserFactory”连接到“Selenium Grid”
【发布时间】:2017-06-20 22:59:48
【问题描述】:

我无法将 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;
  1. 我已成功启动并运行节点和网格。

谢谢。

【问题讨论】:

  • desiredCapabilities.getBrowserName(); 看起来只是在询问浏览器名称是什么...您之前设置过浏览器吗?您可能需要像 desiredCapabilities.setBrowserName("firefox"); 这样的行
  • 其他几个问题。当您说您的代码不起作用时,您是什么意思?这是否意味着它在本地运行?还是抛出错误?如果有错误,那是什么?

标签: java selenium selenium-webdriver webdriver selenium-grid


【解决方案1】:

看起来您在使用 selenium 网格时没有设置浏览器。尝试更改此行:

desiredCapabilities.getBrowserName();

到这里:

desiredCapabilities.setBrowserName("firefox");

或者,如果您的属性格式正确且代码工作正常,则为:

desiredCapabilities.setBrowserName(p.getProperty("browser"));

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多