【问题标题】:Multiple runners in one file only yield results of the first一个文件中的多个跑步者只产生第一个的结果
【发布时间】:2019-05-08 23:54:32
【问题描述】:

我正在尝试使用 TestCafe 来自动化我的项目的初始设置。在设置过程中,必须发出一个需要很长时间的 POST 请求才能继续设置。这是我的runner.js,它在节点 10 中运行:

const longRunningPostRequest = require('./setup/seed-database');
const createTestCafe = require('testcafe');

const RUN_OPTIONS = {pageLoadTimeout: 120000, selectorTimeout: 15000};

const setupLicense = async () => {
  const testcafe = await createTestCafe('localhost', 1337, 1338, undefined, true);
  const runner = testcafe.createRunner();
  const failedCount = await runner
    .src(['fixtures/setup-license.js'])
    .browsers(['chrome -incognito'])
    .run(RUN_OPTIONS);
  await testcafe.close();
};

const setupData = async () => {
  const testcafe = await createTestCafe('localhost', 1337, 1338, undefined, true)
  const runner = testcafe.createRunner();
  await runner
    .src(['fixtures/setup-wizard.js'])
    .browsers(['chrome -incognito'])
    .run(RUN_OPTIONS);
  await testcafe.close();
};

// running them all in sequence
setupLicense()
  .then(() => longRunningPostRequest()) // long-running POST request. Typically takes around 100 seconds to complete
  .then(() => setupData())
  .catch(err => console.log('Error occured:', err));

当我运行应用程序node runner.js 时,它们正在工作。然而,只有setup-license.js 中的装置的结果被显示,而来自第二位跑步者fixtures/setup-wizard.js 的装置没有显示任何输出(但它们正在运行并且正在工作),但使用起来非常烦人,因为如果它失败了,错误消息也被吞没了。我所做的解决方法是注释掉 setupLicense 夹具的内容,以便出现 setupData 的输出。

我该如何解决这个问题?

【问题讨论】:

  • 您可以尝试安装和使用testcafe@0.23.3-alpha.2吗?我们最近修复了一个可能导致此类问题的错误 - TestCafe 在未指定显式报告器时关闭了stdout 输出流。这可以防止在从一个脚本文件开始的第二个和连续测试会话中显示任何测试结果。作为一种解决方法,您可以通过将.reporter('spec') 调用添加到您的设置代码来显式启用spec 报告器,如下所示:gist.github.com/AndreyBelym/c9afd908d4b2891a62a4ba87623ec064

标签: node.js automated-tests e2e-testing testcafe runner


【解决方案1】:

尝试使用最新的 testcafe@0.23.3 版本。该团队最近修复了一个可能导致此类问题的错误 - TestCafe 在未指定显式报告器时关闭了stdout 输出流。这可以防止在从一个脚本文件开始的第二个和连续测试会话中显示任何测试结果。

作为一种解决方法,您可以通过将.reporter('spec') call 添加到您的设置代码中来显式启用spec reporter,如下例所示:

gist.github.com/AndreyBelym/c9afd908d4b2891a62a4ba87623ec064

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2012-06-23
    相关资源
    最近更新 更多