Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13852

How to run a single test in nightwatch

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

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

Upvotes: 44

Views: 35584

Answers (6)

Daniel M.
Daniel M.

Reputation: 89

For me, it only works with:

npm run test -- tests/01_login.js --testcase "Should login into Dashboard"

npm run <script> -- <test suite path> --testcase "<test case>"

my script in package.json:

"test": "env-cmd -f ./.env nightwatch --retries 2 --env selenium.chrome",

at nightwatch version 1.3.4

You can also use tags:

npm run <script> -- <enviroment> <tag>
npm run test -- --env chrome --tag login

just add it to your test case:

module.exports = {
  '@tags': ['login', 'sanity', 'zero1'],
...
}

Upvotes: 1

DoN_Dan
DoN_Dan

Reputation: 69

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.

Upvotes: 0

Daniel W&#228;rn&#229;
Daniel W&#228;rn&#229;

Reputation: 788

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

Upvotes: 8

Kai
Kai

Reputation: 165

you can do somthing like:

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

Upvotes: 0

Nicolas Pennec
Nicolas Pennec

Reputation: 7631

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

Upvotes: 79

albertoiNET
albertoiNET

Reputation: 1348

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

Upvotes: 9

Related Questions