【问题标题】:TestCafe docker- unable to run tests using runner classTestCafe docker-无法使用运行器类运行测试
【发布时间】:2020-03-04 12:27:58
【问题描述】:

我的所有测试都在 docker 容器中运行,并且运行良好。由于我有一些需要并发测试的测试文件和一个不需要并发测试的文件,这就是我需要创建一个测试运行器来运行我的测试的原因。这是我的测试运行程序类的样子:

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);
  });

当我使用命令运行它时:

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

我收到此错误:

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)

我也尝试了firefoxchromium --no-sandbox,但没有任何效果。就我而言,我使用的是来自 TestCafe 的现有可用浏览器图像。请提出建议,因为我的所有测试现在都卡住了。

【问题讨论】:

    标签: docker testing automated-tests e2e-testing testcafe


    【解决方案1】:

    尝试使用无头浏览器。如果您需要使用浏览器 UI 运行测试,请在运行器中执行此 step 以初始化内存显示服务器。

    【讨论】:

    • 测试应该默认在无头模式下运行。 FirefoxChromium 是 TestCafe 图片附带的无头浏览器
    • 使用chromium:headless 选项对我有用,但使用chromium 选项时我会遇到与您相同的错误。
    • 谢谢,它对我有用。还有一个问题,如果我添加runner.screenshots({ takeOnFails: true });,那么我会收到错误TypeError: input.replace is not a function,但如果我只使用runner.screenshots() 而不使用任何参数,那么它不会引发任何错误。我不确定takeOnFails: true 的论点有什么问题?
    • 我在这里创建了一个问题:github.com/DevExpress/testcafe/issues/4475。如果它对你有用,那么请告诉我如何?
    • 感谢您提供的信息。我们将审查您的情况。请继续关注此线程中的更新:github.com/DevExpress/testcafe/issues/4475。
    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2020-04-22
    • 2019-02-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多