Search code examples
node.jstestingautomated-testse2e-testingtestcafe

How to run testcafe via node


I have theses two commands I use when testing with testcafe

set SELENIUM_SERVER=http://xxx:4447/wd/hub
testcafe selenium:"internet explorer" Test.js

How can i rewrite this to run it via node and test runner? I.e. I would like to write something like this:

set SELENIUM_SERVER=http://xxx:4447/wd/hub
node tRunner.js selenium:"internet explorer"

Cannot figure out what the correct order is when using node.


Solution

  • You can create a TestCafe nodejs application and use TestCafe's API to execute your tests.

    For instance, your application may look as follows:  

    const createTestCafe = require('testcafe');
    let testcafe         = null;
    
    createTestCafe('localhost', 1337, 1338)
        .then(tc => {
            testcafe     = tc;
            const runner = testcafe.createRunner();
    
            return runner
                .src('Test.js')
                .browsers('selenium:"internet explorer"')
                .run();
        })
        .then(failedCount => {
            console.log('Tests failed: ' + failedCount);
            testcafe.close();
        });
    

      Learn more about TestCafe API in its documentation: Programming Interface.