Skip to content

Commit

Permalink
Merge pull request #514 from gemini-testing/HERMIONE-1211.html_report
Browse files Browse the repository at this point in the history
feat: add pwt toMatchScreenshot diff bubbles support
  • Loading branch information
KuznetsovRoman authored Oct 17, 2023
2 parents bd58a40 + 77fc722 commit 4c1fb93
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {ErrorName} from '../errors';
import {ImagesInfoFormatter} from '../image-handler';
import {AssertViewResult, ErrorDetails, ImageData, ImageInfoFull, ImageSize, TestError} from '../types';
import * as utils from '../server-utils';
import type {CoordBounds} from 'looks-same';

export type PlaywrightAttachment = PlaywrightTestResult['attachments'][number];

export type PwtImageDiffError = TestError & {meta?: {type: string, snapshotName: string, diffClusters: CoordBounds[]}};

export enum PwtTestStatus {
PASSED = 'passed',
FAILED = 'failed',
Expand Down Expand Up @@ -118,7 +121,8 @@ export class PlaywrightTestAdapter implements ReporterTestResult {
stateName: state,
refImg,
diffImg,
currImg
currImg,
diffClusters: this.getDiffClusters(state)
};
} else if (this.error?.name === ErrorName.NO_REF_IMAGE && currImg) {
return {
Expand Down Expand Up @@ -252,6 +256,16 @@ export class PlaywrightTestAdapter implements ReporterTestResult {
return '';
}

private getDiffClusters(state: string): CoordBounds[] {
const snapshotName = state + '.png';
const errors = this._testResult.errors as PwtImageDiffError[];
const snapshotImageDiffError = errors.find(err => {
return err.meta?.type === 'ImageDiffError' && err.meta.snapshotName === snapshotName;
});

return snapshotImageDiffError?.meta?.diffClusters || [];
}

private get _attachmentsByState(): Record<string, PlaywrightAttachment[]> {
// Filtering out only images. Page screenshots on reject are named "screenshot", we don't want them in state either.
const imageAttachments = this._testResult.attachments.filter(
Expand Down
19 changes: 18 additions & 1 deletion test/unit/lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sinon from 'sinon';
import _ from 'lodash';
import proxyquire from 'proxyquire';
import {TestCase, TestResult} from '@playwright/test/reporter';
import {ImageTitleEnding, PlaywrightAttachment, PlaywrightTestAdapterOptions, PwtTestStatus} from 'lib/test-adapter/playwright';
import {ImageTitleEnding, PlaywrightAttachment, PlaywrightTestAdapterOptions, PwtImageDiffError, PwtTestStatus} from 'lib/test-adapter/playwright';
import {ErrorName, ImageDiffError, NoRefImageError} from 'lib/errors';
import {TestStatus} from 'lib/constants';

Expand Down Expand Up @@ -88,6 +88,23 @@ describe('PlaywrightTestAdapter', () => {
assert.strictEqual(results[0].stateName, 'state1');
assert.strictEqual(results[0].currImg?.path, 'state1' + ImageTitleEnding.Actual);
});

it('should have diff clusters', () => {
const testCaseStub = mkTestCase();
const testResultStub = mkTestResult({
errors: [{message: 'Screenshot comparison failed', meta: {
type: 'ImageDiffError',
snapshotName: 'state1.png',
diffClusters: [{left: 0, top: 0, right: 1, bottom: 1}]
}} as PwtImageDiffError]
});

const adapter = new PlaywrightTestAdapter(testCaseStub, testResultStub, mkAdapterOptions());

const results = adapter.assertViewResults as ImageDiffError[];

assert.deepEqual(results[0].diffClusters, [{left: 0, top: 0, right: 1, bottom: 1}]);
});
});

describe('attempt', () => {
Expand Down

0 comments on commit 4c1fb93

Please sign in to comment.