testing - 咖啡厅 : Unhandled Promise rejection in First test makes second test pass even when It has to be failed by throwing Unhandled Promise Rejection

标签 testing automated-tests e2e-testing testcafe resemblejs

我正在使用 Test Cafe 中使用 Resemble.JS 库的函数来比较实际屏幕截图和基本屏幕截图。在我的夹具中,我有两个测试,由于屏幕截图不匹配,两个测试都应该在报告中失败,但唯一的第一个测试显示为失败,而第二个测试在报告中通过

请帮助我如何处理这种情况并将两个测试标记为失败。

比较截图功能:

const peformVisualRegression = async (testFixture, testName) => {
  // take actual screenshot
  await t.takeScreenshot(path.join('actual', testFixture, `${testName}.png`));

  const actualScreenshotAbsolutePath = getAbsolutePathForScreenshot(
    'actual',
    testFixture,
    testName
  );
  const isActualScreenshotTaken = fs.existsSync(actualScreenshotAbsolutePath);

  const baseScreenshotAbsolutePath = getAbsolutePathForScreenshot(
    'base',
    testFixture,
    testName
  );
  const isBaseScreenshotTaken = fs.existsSync(baseScreenshotAbsolutePath);

  if (isActualScreenshotTaken && isBaseScreenshotTaken) {
    await resemble(baseScreenshotAbsolutePath)
      .compareTo(actualScreenshotAbsolutePath)
      .scaleToSameSize()
      .outputSettings({
        errorColor: {
          blue: 255,
          green: 0,
          red: 255
        },
        errorType: 'movement',
        largeImageThreshold: 1200,
        outputDiff: true,
        transparency: 0.3,
        useCrossOrigin: false
      })
      .onComplete(async data => {
        if (data.rawMisMatchPercentage > 0) {
          logger.error(
            `Mismatch percentage for ${testFixture}/${testName} between actual and base screenshot is ${
              data.rawMisMatchPercentage
            }`
          );
          // write a diff image
          fs.writeFileSync(
            path.join(
              path.dirname(actualScreenshotAbsolutePath),
              `${path.basename(
                actualScreenshotAbsolutePath,
                path.extname(actualScreenshotAbsolutePath)
              )}-diff.png`
            ),
            data.getBuffer()
          );

          // fail test
          throw new Error(
            `Visual mismatch detected in test: ${testFixture}/${testName}. Please investigate.`
          );
        }
      });
  }

夹具:

fixture('Test Duckduckgo search fixture 1').page('https://duckduckgo.com');

test('Testcafe case 1 | @TestrailID:1094986', async t => {
  await t.expect(samplePage.searchInputField.exists).ok();
  await samplePage.enterText('dog');
  const location = await getWindowLocation();
  await t.expect(location.href).contains('q=dog');
  await peformVisualRegression(
    'Test Duckduckgo search fixture 1',
    'Testcafe case 1'
  );
});

test('Testcafe case 2 | @TestrailID:1094987', async t => {
  await t.expect(samplePage.searchInputField.exists).ok();
  await peformVisualRegression(
    'Test Duckduckgo search fixture 1',
    'Testcafe case 2'
  );
});

最佳答案

我能够重现这个问题,所以我创建了一个单独的 bug report在 TestCafe 存储库中详细研究问题。

关于testing - 咖啡厅 : Unhandled Promise rejection in First test makes second test pass even when It has to be failed by throwing Unhandled Promise Rejection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56079100/

相关文章:

angular - 找不到模块 '@angular/cdk/testing'

unit-testing - 单元测试?集成测试?回归测试?验收测试?

testing - 登录后重定向逻辑不适用于 TestCafe 角色

android-studio - 尝试使用 appium FindsByClassName 设置 android studio 时出现重复错误

testing - 当页面对象中声明的断言在 TestCafe 中的同一测试中被调用两次时出现 DOM 快照警告

java - 从android中的应用程序外部调用 Activity

javascript - 页面模型导入

android - 停止 Robotium 测试执行

selenium - 如何使用 Selenium Docker 镜像连接到 localhost 站点?

safari - 在 Safari 中可编辑内容上按 Enter 键