How to run a single test in nightwatch

心不动则不痛 提交于 2019-12-03 04:43:56

问题


How do I run only Test 3 from the following tests?

module.exports = {
  'Test 1':function(){},
  'Test 2':function(){}
  'Test 3':function(){}
}

回答1:


A new parameter --testcase has been added to run a specified testcase.

nightwatch.js --test tests\demo.js --testcase "Test 1"

It's a new feature since the v0.6.0

https://github.com/beatfactor/nightwatch/releases/tag/v0.6.0




回答2:


You must use specific tags before function and separate all functions in diferent files under tests directory, and then call command with --tag argument. See wiki nightwatch tags page and watch this example:

// --- 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
    },
}

If you run:

nightwatch.js --tag login

only runs Test 1, however if you run:

nightwatch.js --tag special

Test 2 and Test 3 will be executed.

You can specific more than one tag

nightwatch.js --tag tag1 --tag tag2

Separate each test function is mandatory because Nightwatch handled with filematcher each file. See Github code.

PD: If file has syntax errors, is possible that test don't run or test hasn't been found




回答3:


The --testcase flag can since version 0.6 be used to run a single test from the commandline, e.g.

nightwatch.js --test tests\demo.js --testcase "Test 1"

This could be done using either test groups or test tags. You can also execute a single test with the --test flag, e.g.

nightwatch.js --test tests\demo.js



回答4:


you can do somthing like:

node nightwatch.js -e chrome --test tests/login_test --testcase tc_001



回答5:


Another possible way of doing so, would be to use the following on each test case that you want to omit:

'@disabled': true,

This can simply be set to false or removed if you wish to test it.



来源:https://stackoverflow.com/questions/28308990/how-to-run-a-single-test-in-nightwatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!