3

我試圖在我的Windows 8機器上設置Nightwatch.js驅動程序可執行文件的路徑必須由web driver.gecko.driver系統屬性設置; Nightwatch

我安裝了nodejs,nightwatch和selenium-standalone-sever 3.0.0-beta1.jar。 當我嘗試運行我的sample.js測試時,出現以下錯誤。

Error retrieving a new session from the selenium server 

Connection refused! Is selenium server started? 
{ state: 'unhandled error', 
    sessionId: null, 
    hCode: 847580505, 
    value: 
    { localizedMessage: 'The path to the driver executable must be set by the web 
driver.gecko.driver system property; for more information, see https://github.co 
m/mozilla/geckodriver. The latest version can be downloaded from https://github. 
com/mozilla/geckodriver/releases', 
    cause: null, 
    suppressed: [], 
    message: 'The path to the driver executable must be set by the webdriver.ge 
cko.driver system property; for more information, see https://github.com/mozilla 
/geckodriver. The latest version can be downloaded from https://github.com/mozil 
la/geckodriver/releases', 
    hCode: 294316877, 
    class: 'java.lang.IllegalStateException', 
    screen: null }, 
    class: 'org.openqa.selenium.remote.Response', 
    status: 13 } 

我的配置文件是:

{ 
    "src_folders" : ["tests"], 
    "output_folder" : "reports", 
    "custom_commands_path" :"", 
    "custom_assertions_path" :"", 
    "page_objects_path" :"", 
    "globals_path":"", 
    "selenium": { 
    "start_process" : false, 
    "server_path" : "", 
    "log_path" : "", 
    "host" : "127.0.0.1", 
    "port" : 4444, 
    "cli_args" : { 
     "webdriver.chrome.driver" : "", 
     "webdriver.ie.driver" : "" 
    } 
    }, 
    "test_settings" : { 
    "default" : { 
     "launch_url" : "http://localhost", 
     "selenium_port" : 4444, 
     "selenium_host" : "localhost", 
     "silent": true, 
     "screenshots" : { 
     "enabled" : false, 
     "path" : "" 
     }, 
     "desiredCapabilities": { 
     "browserName": "firefox", 
     "javascriptEnabled": true, 
     "acceptSslCerts": true 
     } 
    }, 
    "chrome" : { 
     "desiredCapabilities": { 
     "browserName": "chrome", 
     "javascriptEnabled": true, 
     "acceptSslCerts": true 
     } 
    } 
    } 
} 

和我sample.js文件是:

module.exports = { 
    'Demo test Google' : function (browser) { 
    browser 
     .windowMaximize() 
     .url('http://www.google.com') 
     .waitForElementVisible('body', 1000) 
     .setValue('input[type=text]', 'nightwatch') 
     .waitForElementVisible('button[name=btnG]', 1000) 
     .click('button[name=btnG]') 
     .pause(1000) 
     .assert.containsText('#main', 'Night Watch') 
     .end(); 
    } 
}; 

回答

1

所需的能力應該有如下,但我不知道守夜js支持webdriver 3.0或沒有

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

而cli_arguments應該有geckodriver的路徑。

"cli_args" : { 
    "webdriver.gecko.driver": "<path-to-geckodriver>" 
} 

你可以從這裏下載geckodriver:https://github.com/mozilla/geckodriver/releases

有關詳細信息:https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

0

你還沒有開始的硒服務器。你可以這樣做手工或nightwatch能爲你做的

"selenium": { "start_process" : true, // let nigthwatch to start selenium server "server_path" : "./selenium-server-standalone.jar", // provide path to selenium server jar "log_path" : "", "host" : "127.0.0.1", "port" : 4444, "cli_args" : { "webdriver.chrome.driver" : "", "webdriver.ie.driver" : "" } }

0
brew install geckodriver 

那麼你通過

"desiredCapabilities": { 
     "browserName": "firefox", 
     "javascriptEnabled": true, 
     "acceptSslCerts": true 
} 
更改驅動程序到Firefox