无法创建新服务:GeckoDriverService

时间:2018-02-14 14:05:22

标签: node.js windows selenium nightwatch.js

我是Web Automation的初学者。我试图从This YouTube Tutorial运行Nightwatch教程。

我在Windows 10上安装了以下工具:

  • 的node.js
  • 硒 - 服务器 - 独立-3.9.1
  • nightwatch.js 0.9.19

执行命令时

node nightwatch.js -t tests/google.js

我收到错误

'{ value: { message: 'Unable to create new service: GeckoDriverService\nBuild info: version: \'3.9.1\', revision: \'63f7b50\', time: \'2018-02-07T22:42:28.403Z\'\nSystem info: host: \'DESKTOP-I986AE6\', ip: \'172.29.218.145\', os.name: \'Windows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'9.0.4\'\nDriver info: driver.version: unknown',
 error: 'session not created' },status: 33 }

我见过This Post。然后我下载了驱动程序(geckodriver和chromedriver)并将驱动程序放在与我的json文件相同的目录中。然后我在json文件中插入驱动程序的路径,但我仍然得到相同的错误。我该如何解决这个问题?

我的nightwatch.json文件:

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "page_objects_path" : "",
  "custom_assertions_path" : "",
  "globals_path" : "",
  "live_output" : false,
  "parallel_process_delay" : 10,
  "disable_colors": false,
  "test_workers" : false,

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4445,
    "cli_args" : {
      "webdriver.chrome.driver" : "chromedriver.exe",
      "webdriver.gecko.driver" : "geckodriver.exe",
      "webdriver.firefox.profile" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_host" : "127.0.0.1",
      "selenium_port" : 4444,
      "silent" : true,
      "disable_colors": false,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities" : {
        "browserName" : "firefox",
        "javascriptEnabled" : true,
        "acceptSslCerts" : true
      }
    },

    "saucelabs" : {
      "selenium_host" : "ondemand.saucelabs.com",
      "selenium_port" : 80,
      "username" : "${SAUCE_USERNAME}",
      "access_key" : "${SAUCE_ACCESS_KEY}",
      "use_ssl" : false,
      "silent" : true,
      "output" : true,
      "screenshots" : {
        "enabled" : false,
        "on_failure" : true,
        "path" : ""
      },
      "desiredCapabilities": {
        "name" : "test-example",
        "browserName": "firefox"
      },
      "globals" : {
        "myGlobal" : "some_sauce_global"
      },
      "selenium" : {
        "start_process" : false
      }
    },

    "phantomjs" : {
      "desiredCapabilities" : {
        "browserName" : "phantomjs",
        "javascriptEnabled" : true,
        "acceptSslCerts" : true,
        "phantomjs.binary.path" : "/path/to/phantomjs"
      }
    },

    "browserstack" : {
      "selenium" : {
        "start_process" : false
      },
      "selenium_host" : "hub.browserstack.com",
      "selenium_port" : 80,
      "silent" : true,
      "desiredCapabilities": {
        "name" : "test-example",
        "browserName": "firefox",
        "browserstack.user" : "...",
        "browserstack.key" : "..."
      }
    },

    "testingbot" : {
      "selenium_host" : "hub.testingbot.com",
      "selenium_port" : 80,
      "apiKey" : "${TB_KEY}",
      "apiSecret" : "${TB_SECRET}",
      "silent" : true,
      "output" : true,
      "screenshots" : {
        "enabled" : false,
        "on_failure" : true,
        "path" : ""
      },
      "desiredCapabilities": {
        "name" : "test-example",
        "browserName": "firefox"
      },
      "selenium" : {
        "start_process" : false
      }
    }
  }
}

2 个答案:

答案 0 :(得分:1)

我通过将驱动程序(chromedriver和/或geckodriver)放到Selenium所在的同一文件夹并将json文件更改为

来解决它
"webdriver.chrome.driver" : "C:/Projects/selenium/chromedriver.exe",
"webdriver.gecko.driver" : "C:/Projects/selenium/geckodriver.exe",

只要路径可以到达,您就可以将路径放在任何位置。

答案 1 :(得分:0)

不,这不是强制性的。驱动程序可以在任何地方,只要它可以访问。 在第一个示例中,尝试将./放在可执行文件之前,以明确指出它们与您的JSON位于同一目录中,如下所示:

 "cli_args" : {
  "webdriver.chrome.driver" : "./chromedriver.exe",
  "webdriver.gecko.driver" : "./geckodriver.exe",
  "webdriver.firefox.profile" : ""
}