1

I am using a function using Resemble.JS library in Test Cafe to compare the actual and base screenshots. In my fixture, I have two tests and both tests should have been failed in a report due to a mismatch in screenshot but the only first test is shown as failed while the second one is passed in the report

Please help me how can I handle such situation and mark both tests as failed.

Function for comparing screenshots:

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:

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'
  );
});
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Jn Neer
  • 245
  • 1
  • 14

1 Answers1

1

I was able to reproduce the issue, so I created a separate bug report in the TestCafe repository to research the issue in detail.

Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29