How to run a single test in nightwatch

后端 未结 6 1449
野的像风
野的像风 2021-02-01 02:13

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

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


        
6条回答
  •  遇见更好的自我
    2021-02-01 02:45

    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

提交回复
热议问题