Nightwatch Selenium Geckodriver-浏览器无法打开

时间:2018-09-19 11:36:08

标签: selenium nightwatch.js geckodriver

我正在尝试在firefox中运行守夜测试。我的配置文件是这样设置的:

module.exports = {
  "page_objects_path": "./page_objects",
  "selenium": { 
    "start_process": true, 
    "server_path": "../bin/selenium.jar",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.gecko.driver" : "../bin/geckodriver",
      "webdriver.chrome.driver" : "../bin/chromedriver",
      "webdriver.ie.driver" : "../bin/IEDriver"
    }
  },
  "test_settings": {
    // default settings will run with chrome headless
    "headless": {
      "screenshots": {
        "enabled": true, 
        "on_failure": true,
        //"on_error": false,
        "path": HEADLESS_SCREENSHOT_PATH 
      },
      "globals": {
        "waitForConditionTimeout": 15000 
      },
      "desiredCapabilities": { 
        "browserName": "chrome",
        "javascriptEnabled": true,
        "chromeOptions" : {
            "args" : ['--headless', '--disable-gpu', '--window-size=1920x1080'],
        }    
      }
    },

    "firefox": {
      "screenshots": {
        "enabled": true, 
        "on_failure": true,
        //"on_error": false,
        "path": FIREFOX_SCREENSHOT_PATH 
      },
      "globals": {
        "waitForConditionTimeout": 15000 
      },
        "desiredCapabilities": {
          "browserName": "firefox",
          "javascriptEnabled": true,
          "acceptSslCerts": true,
          "marionette": true
        }
      },

      "ie": {
        "screenshots": {
          "enabled": true, 
          "on_failure": true,
          //"on_error": false,
          "path": IE_SCREENSHOT_PATH 
        },
        "globals": {
          "waitForConditionTimeout": 15000 
        },
          "desiredCapabilities": {
            "browserName": "internet explorer",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
          }
        },

    "chrome": {
      "screenshots": {
        "enabled": true, 
        "on_failure": true,
        //"on_error": false,
        "path": CHROME_SCREENSHOT_PATH 
      },
      "globals": {
        "waitForConditionTimeout": 15000 
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "chromeOptions" : {
            "args" : ['--start-maximized', '--incognito'],
        }   
       }
      },
    }
}

Chrome,无头chrome和IE都可以正常工作,但Firefox不能。 Selenium似乎启动了,但是浏览器没有打开。这是一个错误的示例,该错误在尝试在没有打开浏览器的情况下运行测试时反复发生:

   { message: 'Connection refused! Is selenium server started?\n',
     data: { value: [Object], status: 33 } } }
Error: Creating screenshot was not successful. Response was:
{ status: -1,
  value:
   { error: 'invalid session id',
     message: 'No active session with ID null',
     stacktrace: '' },
  errorStatus: 6,
  error: '' }

我曾尝试将硒,geckodriver和firefox升级/降级为每个版本的几个不同版本。目前有硒3.14.0,firefox 62,geckodriver 0.22.0,但是已经尝试了每种硒的几种版本来尝试不同的组合。使用JDK 8。

作为参考,当我第一次尝试在Internet Explorer上运行它时,我也确实犯了同样的错误,但是通过按照https://github.com/nightwatchjs/nightwatch/wiki/Internet-Explorer-Setup上的“其他设置”部分更改了IE设置来解决此问题。似乎没有任何类似的说明可以在Firefox中设置要求。

其他人有没有类似的解决方案?非常感谢

1 个答案:

答案 0 :(得分:0)

尝试在webdriver.gecko.driver中添加.exe

 "webdriver.gecko.driver" : "../bin/geckodriver.exe",

由于某些原因,当selenium start_process设置为true时,指向geckodriver的路径应包含.exe