1

I have several runners which are using promise.race to complete the testcase at a particular time Say I have runner1.js, runner2.js runner3.js, how do I create a master runner so that I can run all these runners together?

const createTestCafe = require('testcafe');
let testcafe = null;

// createTestCafe('localhost', 1337, 1338)
createTestCafe()
    .then(tc => {
        testcafe     = tc;
         //create test runner for configuring and launching test tasks
        const runner = testcafe.createRunner();



    return runner
        //run test from specified folders/files
        .src(['*the path to all runner.js*'])
        //configure the test runner to run tests in the specified browsers
        .browsers('chrome')
        .reporter('html-testrail')
        .run({skipJsErrors:true})             




    })


           .catch(failedCount => {
               console.log('Tests failed: ' + failedCount);
                testcafe.close();
            })

it's not working this way, any suggestions?
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
TS0306
  • 177
  • 12

1 Answers1

3

TestCafe allows running multiple test runners at the same time. Check the following code:

const createTestCafe = require('testcafe');

(async () => {
    const testCafe = await createTestCafe();

    const runner1 = testCafe
        .createRunner()
        .src('test1.js')
        .reporter([{ name: 'spec', output: 'report1.txt' }])
        .browsers('chrome');

    const runner2 = testCafe
        .createRunner()
        .src('test2.js')
        .reporter([{ name: 'spec', output: 'report2.txt' }])
        .browsers('firefox');

    await Promise.all([runner1, runner2].map(runner => runner.run()));

    await testCafe.close();
})();
Andrey Belym
  • 2,893
  • 8
  • 19
  • @Belym thank you! I understood the concept but when I am trying the code you said its not working , can you point me to any documentation in testcafe that has this , all any idea why are you using map? we can also use Promise.all().then? – TS0306 Oct 08 '19 at 15:25
  • @TS0306 I checked the Andrey's code and it works as expected. We do not have such a case in our documentation, but I confirm that it's allowed to use multiple runners at the same time. It is not required to use the `map` method here. You can use the following code: `await Promise.all([runner1.run(), runner2.run() ])`. The main idea is that the `runner.run` method returns a promise, so you can easily use it in the `Promise.all()` method. – Alex Kamaev Oct 09 '19 at 11:19