Skip to content

Commit

Permalink
Merge pull request #524 from gemini-testing/HERMIONE-1270.TMS_save_ht…
Browse files Browse the repository at this point in the history
…ml_reporter

fix(playwright): display provided image on screenshot match
  • Loading branch information
KuznetsovRoman authored Nov 30, 2023
2 parents f91cf2c + 336511c commit ba202d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const extractImageError = (result: PlaywrightTestResult, {state, expectedAttachm
const snapshotName = state + '.png';

if (expectedAttachment && diffAttachment && actualAttachment) {
const errors = result.errors as PwtImageDiffError[];
const errors = (result.errors || []) as PwtImageDiffError[];
const imageDiffError = errors.find(err => {
return err.meta?.type === ErrorName.IMAGE_DIFF && err.meta.snapshotName === snapshotName;
});
Expand All @@ -97,7 +97,7 @@ const extractImageError = (result: PlaywrightTestResult, {state, expectedAttachm
}

// only supports toMatchScreenshot
const errors = result.errors as PwtNoRefImageError[];
const errors = (result.errors || []) as PwtNoRefImageError[];
const noRefImageError = errors.find(err => {
return err.meta?.type === ErrorName.NO_REF_IMAGE && err.meta.snapshotName === snapshotName;
});
Expand Down Expand Up @@ -169,6 +169,11 @@ export class PlaywrightTestAdapter implements ReporterTestResult {
stateName: state,
currImg
};
} else if (!error && refImg) {
return {
stateName: state,
refImg
};
}

return null;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ describe('PlaywrightTestAdapter', () => {
assert.deepEqual(results[0].name, 'ImageDiffError');
assert.deepEqual(results[1].name, 'NoRefImageError');
});

it('should return refImg, if provided', () => {
const testCaseStub = mkTestCase();
const testResultStub = {
status: 'success',
attachments: [createAttachment('state1' + ImageTitleEnding.Expected)],
steps: []
} as unknown as TestResult;
const adapter = new PlaywrightTestAdapter(testCaseStub, testResultStub, mkAdapterOptions());

const results = adapter.assertViewResults as ImageDiffError[];

assert.lengthOf(results, 1);
assert.isUndefined(results[0].name);
assert.strictEqual(results[0].stateName, 'state1');
assert.strictEqual(results[0].refImg?.path, 'state1' + ImageTitleEnding.Expected);
});
});

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

0 comments on commit ba202d7

Please sign in to comment.