Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(){} } 
like image 839
Mohamed El Mahallawy Avatar asked Feb 03 '15 21:02

Mohamed El Mahallawy


People also ask

How do I run a single test file on Nightwatch?

A new parameter --testcase has been added to run a specified testcase. Show activity on this post. Test 2 and Test 3 will be executed. Separate each test function is mandatory because Nightwatch handled with filematcher each file.

How do you run a test on Nightwatch?

Running A Demo TestStep 1: Go to the folder “node_modules/nightwatch/examples/tests/”. Step 2: Under the 'tests' folder, you can find some sample tests. Step 3: Let us run the first sample test “ecosia.

How do you run multiple test cases on Nightwatch?

To execute tests in multiple browsers, you need to add the desired capabilities of the browsers and Test_worker configurations in nightwatch. json file. For example if you want to execute tests in three browsers parallely - Chrome, Firefox and Opera, your nightwatch. json should something like this.


2 Answers

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

like image 126
Nicolas Pennec Avatar answered Sep 21 '22 13:09

Nicolas Pennec


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

like image 40
albertoiNET Avatar answered Sep 22 '22 13:09

albertoiNET