Skip to content

Commit

Permalink
cherry-pick(#21935): chore: fix trace viewer backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Mar 23, 2023
1 parent a0b4bd1 commit 6b2858f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/trace-viewer/public/watch.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"display": "browser",
"start_url": "watch.html",
"name": "Playwright Test",
"short_name": "Trace Viewer",
"short_name": "Playwright Test",
"icons": [
{
"src": "icon-192x192.png",
Expand Down
1 change: 1 addition & 0 deletions packages/trace-viewer/src/snapshotRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class SnapshotRenderer {
const prefix = snapshot.doctype ? `<!DOCTYPE ${snapshot.doctype}>` : '';
html = prefix + [
'<style>*,*::before,*::after { visibility: hidden }</style>',
`<style>*[__playwright_target__="${this.snapshotName}"] { outline: 2px solid #006ab1 !important; background-color: #6fa8dc7f !important; }</style>`,
`<style>*[__playwright_target__="${this._callId}"] { outline: 2px solid #006ab1 !important; background-color: #6fa8dc7f !important; }</style>`,
`<script>${snapshotScript()}</script>`
].join('') + html;
Expand Down
7 changes: 4 additions & 3 deletions packages/trace-viewer/src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ async function loadTrace(traceUrl: string, traceFileName: string | null, clientI
} catch (error: any) {
if (error?.message?.includes('Cannot find .trace file') && await traceModel.hasEntry('index.html'))
throw new Error('Could not load trace. Did you upload a Playwright HTML report instead? Make sure to extract the archive first and then double-click the index.html file or put it on a web server.');
else if (traceFileName)
// eslint-disable-next-line no-console
console.error(error);
if (traceFileName)
throw new Error(`Could not load trace from ${traceFileName}. Make sure to upload a valid Playwright trace.`);
else
throw new Error(`Could not load trace from ${traceUrl}. Make sure a valid Playwright Trace is accessible over this url.`);
throw new Error(`Could not load trace from ${traceUrl}. Make sure a valid Playwright Trace is accessible over this url.`);
}
const snapshotServer = new SnapshotServer(traceModel.storage());
loadedTraces.set(traceUrl, { traceModel, snapshotServer });
Expand Down
6 changes: 3 additions & 3 deletions packages/trace-viewer/src/traceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ export class TraceModel {
params: metadata.params,
wallTime: metadata.wallTime || Date.now(),
log: metadata.log,
beforeSnapshot: metadata.snapshots.find(s => s.snapshotName === 'before')?.snapshotName,
inputSnapshot: metadata.snapshots.find(s => s.snapshotName === 'input')?.snapshotName,
afterSnapshot: metadata.snapshots.find(s => s.snapshotName === 'after')?.snapshotName,
beforeSnapshot: metadata.snapshots.find(s => s.title === 'before')?.snapshotName,
inputSnapshot: metadata.snapshots.find(s => s.title === 'input')?.snapshotName,
afterSnapshot: metadata.snapshots.find(s => s.title === 'after')?.snapshotName,
error: metadata.error?.error,
result: metadata.result,
point: metadata.point,
Expand Down
Binary file added tests/assets/trace-1.31.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/library/snapshotter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ it.describe('snapshots', () => {
await snapshotter.reset();
const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');
const html2 = snapshot2.render().html;
expect(html2.replace(`"call@2"`, `"call@1"`)).toEqual(html1);
expect(html2.replace(/call@2/g, `call@1`)).toEqual(html1);
});

it('should capture resources', async ({ page, toImpl, server, snapshotter }) => {
Expand Down
6 changes: 6 additions & 0 deletions tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,9 @@ test('should update highlight when typing', async ({ page, runAndTrace, server }
await traceViewer.page.keyboard.type('button');
await expect(snapshot.locator('x-pw-glass')).toBeVisible();
});

test('should open trace-1.31', async ({ showTraceViewer }) => {
const traceViewer = await showTraceViewer([path.join(__dirname, '../assets/trace-1.31.zip')]);
const snapshot = await traceViewer.snapshotFrame('locator.click');
await expect(snapshot.locator('[__playwright_target__]')).toHaveText(['Submit']);
});

0 comments on commit 6b2858f

Please sign in to comment.