aakash garg
aakash garg

Reputation: 21

How to run TestCafe runner class with Docker

I am new to TestCafe and want to run my testcases with runner class in Docker container.

I am able to run single testcase through Docker. But when i want to run with runner class, i am not able to do that. I have followed this thread https://github.com/DevExpress/testcafe/issues/2761 but i don't know how to define "Environment initialization steps from the TestCafe Docker script in your runner."

my runner file

const testCafe = require('testcafe');
const fs       = require('fs');

function runTest(tcOptions) {
  testCafe('localhost', 8080, 8081)
    .then(function(tc) {

      let runner = tc.createRunner();

      return runner
        .src(['./apps/tests/*.test.js'])
        .browsers(['firefox'])
        .concurrency(4)
        .reporter([
          'list',
          {
            name: 'html',
            output: './dist/testcafe/testCafe-report.html'
          }
        ])
        .screenshots('./dist/testcafe/testcafe-screenshots', true)
       .run(tcOptions)
        .catch(function(error) {
          console.log(error);
        });
    })
    .then(failedCount => {
      if (failedCount > 0) console.log('Error Tests failed: ' + failedCount);
      else console.log('All Desktop Tests Passed');
      process.exit(0);
    })

}

const tcOptions = {
  debugMode: false
};

runTest(tcOptions);

and running this Docker command

docker run -v `pwd`/:/tests -e "NODE_PATH=/tests/node_modules" -it --entrypoint node testcafe/testcafe /tests/apps/testcafe//testcafe-desktop-run.js
{ Error: No tests to run. Either the test files contain no tests or the filter function is too restrictive.
    at Bootstrapper._getTests (/tests/node_modules/testcafe/src/runner/bootstrapper.js:92:19) code: 'E1009', data: [] }

Upvotes: 2

Views: 1126

Answers (1)

Dmitry Ostashev
Dmitry Ostashev

Reputation: 2348

You need to define the full path to your test files or change your working directory to the /tests directory in the container.

Besides, this step is intended to run the in-memory display server. You may skip it if you are going to run tests in a headless browser.

Here is a command that works on my side with the Runner class:

docker run -v //c/Users/User/test-docker:/tests -w=/tests -it --entrypoint node testcafe/testcafe /tests/test-run.js

Upvotes: 2

Related Questions