2016-03-08 42 views
2

這是目前我nightwatch.json文件:有沒有辦法在Nightwatch.json文件中對Selenium Server Path進行硬編碼?

nighwatch.json file

我的問題:是否有引用的server_path .jar文件,以避免硒服務器standalone-硬編碼值的手段方式2.51.0.jar?我想知道,因爲我們公司希望每次更新我們的package.json文件時都會更新硒版本。一旦硒版本發生變化,我們的測試會因爲這個硬編碼值而中斷。我曾嘗試:

1)

"../node_modules/selenium-server-standalone-jar/jar///*.jar" 

這失敗的錯誤消息「無法訪問罐子file'.There只有一個可用的.jar文件以供選擇。

2)通過npm引用包含所需版本的selenium-server-standalone包的package.json文件。

任何幫助或建議將不勝感激。

回答

0

只是試圖自己設置Nightwatch,具有相同的要求。

因此,這裏是我所做的:

1)在nightwatch.json,我離開了文件名:

... 
"selenium" : { 
    "start_process" : true, 
    "server_path" : "node_modules/selenium-standalone/drivers/selenium-server/", 
... 

2)從這裏:http://nightwatchjs.org/guide#settings-file 你可以看到,你可以使用javascript來更改配置。我使用的是selenium-standalone npm package的硒服務器。 在package.jsonscripts.postinstall我:selenium-standalone install --basePath %cd%/node_modules/selenium-standalone/drivers

所以我知道安裝驅動程序在哪裏,並且可以使用node fs包,找出當前安裝的硒文件的名稱:

const fs = require("fs"); 

module.exports = (function(settings){ 
    var seleniumFileName = 
    fs.readdirSync("node_modules/selenium-standalone/drivers/selenium-server/")[0]; 
    settings.selenium.server_path += seleniumFileName; 
    return settings; 
})(require("./nightwatch.json")); 

運行像魅力。

0

你可以試試這個方法:

nightwatch.json硒屬性應該是這樣的:

... 
"selenium": { 
    "start_process": true, 
    "server_path": "node_modules/selenium-standalone/.selenium/selenium-server/", 
    "log_path": "./reports", 
    "host": "127.0.0.1", 
    "port": 4444, 
    "cli_args": { 
     "webdriver.chrome.driver": "" 
    } 
    } 
... 

nightwatch.conf.js應該是這樣的:

require('babel-core/register'); 
const fs = require("fs"); 

module.exports = ((settings) => { 
    var seleniumFileName = 
    fs.readdirSync("node_modules/selenium-standalone/.selenium/selenium-server/"); 
    settings.selenium.server_path += seleniumFileName; 
    return settings; 
})(require("./nightwatch.json")); 
相關問題