Skip to content

Commit

Permalink
Add test for new count and boundingBox snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
agg23 committed Jan 9, 2025
1 parent 0ac3a8b commit 3b0a2ce
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/playwright-test/playwright.trace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,3 +1271,49 @@ test('should record trace after fixture teardown timeout', {
// Check console events to make sure that library trace is recorded.
expect(trace.events).toContainEqual(expect.objectContaining({ type: 'console', text: 'from the page' }));
});

test('should record trace snapshot for more obscure commands', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('test 1', async ({ browser }) => {
const page = await browser.newPage();
await page.setContent('<div>Content</div>');
expect(await page.locator('div').count()).toBe(1);
await page.locator('div').boundingBox();
});
`,
}, { trace: 'on' });

expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);

const tracePath = test.info().outputPath('test-results', 'a-test-1', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.actionTree).toEqual([
'Before Hooks',
' fixture: browser',
' browserType.launch',
'browser.newPage',
'page.setContent',
'locator.count',
'expect.toBe',
'locator.boundingBox',
'After Hooks',
]);

const snapshots = trace.traceModel.storage();
const snapshotFrameOrPageId = snapshots.snapshotsForTest()[0];

const countAction = trace.actions.find(a => a.apiName === 'locator.count');
expect(countAction.beforeSnapshot).toBeTruthy();
expect(countAction.afterSnapshot).toBeTruthy();
expect(snapshots.snapshotByName(snapshotFrameOrPageId, countAction.beforeSnapshot)).toBeTruthy();
expect(snapshots.snapshotByName(snapshotFrameOrPageId, countAction.afterSnapshot)).toBeTruthy();

const boundingBoxAction = trace.actions.find(a => a.apiName === 'locator.boundingBox');
expect(boundingBoxAction.beforeSnapshot).toBeTruthy();
expect(boundingBoxAction.afterSnapshot).toBeTruthy();
expect(snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.beforeSnapshot)).toBeTruthy();
expect(snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.afterSnapshot)).toBeTruthy();
});

0 comments on commit 3b0a2ce

Please sign in to comment.