使用Nightwatch和Selenium测试localhost时无法在Firefox上加载页面

时间:2017-04-21 23:51:06

标签: firefox selenium-webdriver nightwatch.js geckodriver

我正在使用Nightwatch构建一套自动化集成测试,SampleFileHere是Selenium WebDriver API的Node包装器。我能够让它适用于Chrome,但不适用于Firefox(或Safari,就此而言)。

我认为问题与GeckoDriver vs. Firefox Driver有关。我已将Nightwatch配置为在nightwatch.json中使用GeckoDriver。但Selenium似乎正在寻找基于nightwatch -e firefox --verbose的终端输出的Firefox驱动程序。见下文:

INFO Request: POST /wd/hub/session/2c156cf4-10cb-44b2-8b1f-c12312b4633f/url 
 - data:  {"url":"localhost:9000"} 
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":24}
ERROR Response 500 POST /wd/hub/session/2c156cf4-10cb-44b2-8b1f-c12312b4633f/url (1218ms) { state: 'unknown error',
  sessionId: '2c156cf4-10cb-44b2-8b1f-c12312b4633f',
  hCode: 1111219279,
  value: 
   { additionalInformation: '\nDriver info: org.openqa.selenium.firefox.FirefoxDriver\nCapabilities ...

这是我的Nightwatch配置文件:

{
  "src_folders": ["./nightwatch/tests"],
  "output_folder": "./nightwatch/reports",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "./nightwatch/tests/pages",
  "globals_path": "",

  "selenium": {
    "start_process": true,
    "server_path": "./nightwatch/selenium-server-standalone-3.4.0.jar",
    "log_path": false,
    "cli_args": {
      "webdriver.chrome.driver": "./nightwatch/drivers/chromedriver",
      "webdriver.gecko.driver": "./nightwatch/drivers/geckodriver"
    }
  },

  "test_settings": {
    "default": {
      "desiredCapabilities": {
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    },

    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }
    }
  }
}

为了更好的衡量,以下是我在测试中尝试访问的nightwatch/pages/index.js文件:

module.exports = {
  url: 'localhost:9000',
  elements: {
    // stuff
  }
}

1 个答案:

答案 0 :(得分:0)

为了它的价值,目前我们决定坚持使用当前的ESR版Firefox,它与Selenium开箱即用。

我们尝试使用这个新版本的Firefox和新驱动程序,但它不够稳定,无法继续。

我的建议是安装ESR版本的Firefox,看看你是否能以这种方式工作。如果是,则转到下一步(即,针对最新版本进行测试)。