Sim*_*mon 6 javascript config node.js nightwatch.js
Noob节点警告:如何以编程方式设置运行测试时要使用的配置对象?
一直在努力寻找明确的答案.
建立:
/e2e-tests
|-globals.js
|-product.page.notify.stock.js
|-nightwatch.json
|-nightwatch
Run Code Online (Sandbox Code Playgroud)
#!/usr/bin/env node require('nightwatch/bin/runner.js');var SITE_URL = 'http://dev.local/', //this needs to be set somehow production||dev
AJAX_URL = 'ajaxproc/getrandomoutofstock', //relative so this doesn't need to change
select = '#mysize',
emailError = '.error-message',
outOfStockItem = {
id: false,
url: false
};
module.exports = {
'Get backorder stock url': function(browser) {
browser.url(SITEURL + AJAX_URL)
// ommitted for brevity
},
'Check notify stock on product page': function(client) {
client.url(SITE_URL + outOfStockItem.url);
// ommitted for brevity
},
// remaining test stuff - not needed
};Run Code Online (Sandbox Code Playgroud)
我在这里看到了MateuszJeziorski的这种方法,但省略了获取过程参数的方法.提供夜视仪的示例也没有回答这个问题.我认为命令的最终结果看起来像这样:
nightwatch -somekindofparametertosetenvironment -t e2e-tests/product.page.notify.stock
听起来您可以在nightwatch.json文件中获得多个环境所需的内容.
您可以在nightwatch.json中使用类似的设置测试环境:
"test_settings" : {
"default" : {
"launch_url" : "some_url",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"globals" : {
"site_url" : "some_site"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"other_environment" : {
"globals" : {
"site_url" : "some_other_site"
}
},
"one_more_environment" : {
"globals" : {
"site_url" : "one_other_site",
"other_var" : "this env needs a different variable"
}
}
}
Run Code Online (Sandbox Code Playgroud)
Nightwatch会让你通过--env环境.每个环境都可以有唯一的全局变量.
除非特别重写,否则"默认"属性将在每个环境中使用.
使用类似命令运行特定环境nightwatch --env "other_environment".环境将使用nightwatch.json中列出的全局变量启动.