我该如何仅运行以下测试中的Test 3
?
module.exports = {
'Test 1':function(){},
'Test 2':function(){}
'Test 3':function(){}
}
我该如何仅运行以下测试中的Test 3
?
module.exports = {
'Test 1':function(){},
'Test 2':function(){}
'Test 3':function(){}
}
新增了一个参数--testcase,用于运行指定的测试用例。
nightwatch.js --test tests\demo.js --testcase "Test 1"
自v0.6.0版本以来,这是一个新功能。
https://github.com/beatfactor/nightwatch/releases/tag/v0.6.0
在执行命令时,您需要在测试目录下使用特定标签来定义函数,并把不同的函数放在各自的文件中。然后使用--tag参数调用命令。请参考Nightwatch标签页面以及以下示例:
// --- file1.js ---
module.exports = {
tags: ['login'],
'Test 1':function(){
//TODO test 1
}
};
// --- file2.js ---
module.exports = {
tags: ['special', 'createUser'],
'Test 2':function(){
//TODO test 2
},
};
// --- file3.js ---
module.exports = {
tags: ['logoff', 'special'],
'Test 3':function(){
//TODO test 3
},
}
nightwatch.js --tag login
只运行测试1,但如果你运行:
nightwatch.js --tag special
测试2和测试3将被执行。
您可以指定多个标签。
nightwatch.js --tag tag1 --tag tag2
每个测试函数都必须分开,因为Nightwatch会处理每个文件的filematcher。 请参见Github代码。
PD:如果文件存在语法错误,则可能导致测试无法运行或找不到测试。
nightwatch.runner
的节点脚本。 - Jeremynpm run test -- tests/01_login.js --testcase "Should login into Dashboard"
npm run <script> -- <test suite path> --testcase "<test case>"
我的 package.json 文件中的脚本:
"test": "env-cmd -f ./.env nightwatch --retries 2 --env selenium.chrome",
在 Nightwatch 版本 1.3.4 中
你也可以使用标签:
npm run <script> -- <enviroment> <tag>
npm run test -- --env chrome --tag login
只需将其添加到您的测试用例中:
module.exports = {
'@tags': ['login', 'sanity', 'zero1'],
...
}
另一个可能的方法是,在您想要省略的每个测试用例上使用以下内容:
'@disabled': true,
如果您希望进行测试,可以将其设置为false或删除它。
你可以这样做:
node nightwatch.js -e chrome --test tests/login_test --testcase tc_001