Add test for new count and boundingBox snapshots
This commit is contained in:
parent
0ac3a8b80b
commit
3b0a2ce8f8
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue