2

I have written about 70 tests in nightwatch and many of them depend on each other, therefore they will have to be executed in a certain order, order that I will define. Each test is in a different file and it looks like this:

module.exports = {
  'Test name example': function (browser) {
    browser

    // test

    }
  };

I want to know what is the best way to run these tests in an order that I like? Is there a way to create a "mother-file", where you import/require all the written tests and then execute them in the order of your liking? From what I searched online, one solution is: "to prefix each test file with a number indicating the order you want them to be run in" from How can I run Nightwatch tests in a specific order?, or to use "--testcase" as shown in How to run a single test in nightwatch, but I want to know if these are all the posibilities out there.

Emy eminescu
  • 103
  • 1
  • 7

1 Answers1

0

I don't know if this is what you're looking for, but you can definitely use "require" and then set the order of your test case.

Let's say you have these test cases:

  • testcase1.js
  • testcase2.js
  • testcase3.js
  • and so on.

And the inside of testcase1.js for example:

module.exports = {
  'NameofTheTest' : function (client) {
   //your test here
  }
};

Then you can create, as you said, a "mother-file" for example mastertest.js and you can write something like this inside it:

var testcase1 = require('../../Tests/BC/testcase1.js');
var testcase2 = require('../../Tests/BC/testcase2.js');
var testcase3 = require('../../Tests/BC/testcase3.js');
module.exports = {
  'Test 1' : testcase1.NameofTheTest,
  'Test 2' : testcase2.NameofTheTest,
  'Test 3' : testcase3.NameofTheTest
};

You can set the order of the Tests inside of mastertest.js anyway you like.

user2018
  • 310
  • 2
  • 7
  • 21