Search code examples
dockertestingautomated-testse2e-testingtestcafe

TestCafe docker- unable to run tests using runner class


I have all my tests running in a docker container and it works fine. Since I have a few test files which need concurrent tests and a file which doesn't need a concurrent test that is the reason I need to create a test runner to run my tests. Here is what my test runner class looks like:

const createTestCafe = require('testcafe');

let testcafe = null;

createTestCafe('localhost', 1337, 1338)
  .then((tc) => {
    testcafe = tc;
    const runner1 = testcafe.createRunner();
    const runner2 = testcafe.createRunner();

    const promise1 = runner1
      .src(['/tests/uitests/**/conctests/accounttest.js', '/tests/uitests/**/conctests/dashtest.js'])
      .browsers('chromium')
      .screenshots({ takeOnFails: true })
      .reporter(['spec', {
        name: 'html',
        output: 'resultsrunner1.html' }, {
        name: 'xunit',
        output: 'res1.xml',
      }])
      .concurrency(3)
      .run({
        skipJsErrors: true,
        quarantineMode: true,
      });

    const promise2 = runner2
      .src('/tests/uitests/**/conctests/roletest.js')
      .browsers('chromium')
      .screenshots({ takeOnFails: true })
      .reporter(['spec', {
        name: 'html',
        output: 'resultsrunner2.html' }, {
        name: 'xunit',
        output: 'res2.xml',
      }])
      .run({
        skipJsErrors: true,
        quarantineMode: true,
      });

    return Promise.all([promise1, promise2]);
  })
  .then(() => {
    testcafe.close();
    process.exit();
  })
  .catch((err) => {
    console.log(err);
    testcafe.close();
    process.exit(1);
  });

when I run it using the command:

docker run --net=host -v `pwd`:/tests -it --entrypoint node testcafe /tests/testrunner.js

I get this error:

Error: Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.
at /tests/node_modules/testcafe/src/runner/browser-set.js:84:30
at Generator.next (<anonymous>)
at step (/tests/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /tests/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at new Promise (<anonymous>)
at new F (/tests/node_modules/core-js/library/modules/_export.js:36:28)
at /tests/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
at BrowserSet._waitConnectionsOpened (/tests/node_modules/testcafe/src/runner/browser-set.js:77:37)
at _waitConnectionsOpened (/tests/node_modules/testcafe/src/runner/browser-set.js:107:35)
at invokeCallback (/tests/node_modules/pinkie/index.js:60:12)
at Array.forEach (<anonymous>)
at publish (/tests/node_modules/pinkie/index.js:147:32)
at Array.publishFulfillment (/tests/node_modules/pinkie/index.js:152:2)
at Immediate.asyncFlush (/tests/node_modules/pinkie/index.js:17:19)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)

I tried firefox and chromium --no-sandbox as well but nothing worked for me. In my case, I'm using the existing available browser image from the TestCafe. Please suggest as all my tests are stuck right now.


Solution

  • Try to use a headless browser. If you need to run tests with the browser UI, perform this step in your runner to initialize the in-memory display server.