如何设置nightwatch.json跨平台
How to set up nightwatch.json to be cross platform
目前在我的 nightwatch.json
我的 mac:
上 运行ning 设置良好
{
"src_folders" : ["specs"],
"output_folder" : "tests/e2e/reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "bin/selenium-server-standalone-2.48.2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "bin/chromedriver 2",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "someurl",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
但是 chrome 的驱动程序将需要 运行 chromedriver.exe
。解决此问题的最佳实践方法是什么?我需要2个配置文件吗?我宁愿不要这个,因为我需要对此进行额外检查。
解决方法是使用nightwatch.conf.js文件,即:
module.exports = (function (settings) {
//Setting chromedriver path at runtime to run on different architectures
if (process.platform === "darwin") {
settings.selenium.cli_args["webdriver.chrome.driver"] = "bin/chromedriver 2";
}
else if (process.platform === "win32" || process.platform === "win64") {
settings.selenium.cli_args["webdriver.chrome.driver"] = "bin/chromedriver.exe";
}
return settings;
})(require('./nightwatch.json'));
目前在我的 nightwatch.json
我的 mac:
{
"src_folders" : ["specs"],
"output_folder" : "tests/e2e/reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "bin/selenium-server-standalone-2.48.2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "bin/chromedriver 2",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "someurl",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
但是 chrome 的驱动程序将需要 运行 chromedriver.exe
。解决此问题的最佳实践方法是什么?我需要2个配置文件吗?我宁愿不要这个,因为我需要对此进行额外检查。
解决方法是使用nightwatch.conf.js文件,即:
module.exports = (function (settings) {
//Setting chromedriver path at runtime to run on different architectures
if (process.platform === "darwin") {
settings.selenium.cli_args["webdriver.chrome.driver"] = "bin/chromedriver 2";
}
else if (process.platform === "win32" || process.platform === "win64") {
settings.selenium.cli_args["webdriver.chrome.driver"] = "bin/chromedriver.exe";
}
return settings;
})(require('./nightwatch.json'));