Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: unify trace parsing utilities (#38660)
Dmitry Gozman585e8ef6eae6
diff --git a/packages/playwright-core/src/server/trace/test/DEPS.list b/packages/playwright-core/src/server/trace/test/DEPS.listdeleted file mode 100644index 665f63400d..0000000000--- a/packages/playwright-core/src/server/trace/test/DEPS.list+++ /dev/null@@ -1,2 +0,0 @@-[*]-***diff --git a/packages/playwright-core/src/server/trace/viewer/traceParser.ts b/packages/playwright-core/src/server/trace/viewer/traceParser.tsnew file mode 100644index 0000000000..d3cc2bab8a--- /dev/null+++ b/packages/playwright-core/src/server/trace/viewer/traceParser.ts@@ -0,0 +1,62 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import url from 'url';+import { ZipFile } from '../../utils/zipFile';+import type { TraceLoaderBackend } from '@isomorphic/trace/traceLoader';++export class ZipTraceLoaderBackend implements TraceLoaderBackend {+ private _zipFile: ZipFile;+ private _traceFile: string;++ constructor(traceFile: string) {+ this._traceFile = traceFile;+ this._zipFile = new ZipFile(traceFile);+ }++ isLive() {+ return false;+ }++ traceURL() {+ return url.pathToFileURL(this._traceFile).toString();+ }++ async entryNames(): Promise<string[]> {+ return await this._zipFile.entries();+ }++ async hasEntry(entryName: string): Promise<boolean> {+ const entries = await this.entryNames();+ return entries.includes(entryName);+ }++ async readText(entryName: string): Promise<string | undefined> {+ try {+ const buffer = await this._zipFile.read(entryName);+ return buffer.toString('utf-8');+ } catch {+ }+ }++ async readBlob(entryName: string): Promise<Blob | undefined> {+ try {+ const buffer = await this._zipFile.read(entryName);+ return new Blob([new Uint8Array(buffer)]);+ } catch {+ }+ }+}diff --git a/packages/playwright-core/src/utils/isomorphic/trace/traceModel.ts b/packages/playwright-core/src/utils/isomorphic/trace/traceModel.tsindex 2b0594705a..8358018715 100644--- a/packages/playwright-core/src/utils/isomorphic/trace/traceModel.ts+++ b/packages/playwright-core/src/utils/isomorphic/trace/traceModel.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { getActionGroup } from '@isomorphic/protocolFormatter';+import { getActionGroup, renderTitleForCall } from '@isomorphic/protocolFormatter';import type { Language } from '@isomorphic/locatorGenerators';import type { ResourceSnapshot } from '@trace/snapshot';@@ -50,7 +50,7 @@ export type ActionTreeItem = {id: string;children: ActionTreeItem[];parent: ActionTreeItem | undefined;- action?: ActionTraceEventInContext;+ action: ActionTraceEventInContext;};export type ErrorDescription = {@@ -146,6 +146,20 @@ export class TraceModel {return this.actions.filter(action => !action.group || filter.has(action.group));}+ renderActionTree(filter?: ActionGroup[]) {+ const actions = this.filteredActions(filter ?? []);+ const { rootItem } = buildActionTree(actions);+ const actionTree: string[] = [];+ const visit = (actionItem: ActionTreeItem, indent: string) => {+ const title = renderTitleForCall({ ...actionItem.action, type: actionItem.action.class });+ actionTree.push(`${indent}${title || actionItem.id}`);+ for (const child of actionItem.children)+ visit(child, indent + ' ');+ };+ rootItem.children.forEach(a => visit(a, ''));+ return actionTree;+ }+private _errorDescriptorsFromActions(): ErrorDescription[] {const errors: ErrorDescription[] = [];for (const action of this.actions || []) {@@ -333,9 +347,11 @@ export function buildActionTree(actions: ActionTraceEventInContext[]): { rootIte});}- const rootItem: ActionTreeItem = { id: '', parent: undefined, children: [] };+ const rootItem: ActionTreeItem = { action: { ...kFakeRootAction }, id: '', parent: undefined, children: [] };for (const item of itemMap.values()) {- const parent = item.action!.parentId ? itemMap.get(item.action!.parentId) || rootItem : rootItem;+ rootItem.action.startTime = Math.min(rootItem.action.startTime, item.action.startTime);+ rootItem.action.endTime = Math.max(rootItem.action.endTime, item.action.endTime);+ const parent = item.action.parentId ? itemMap.get(item.action.parentId) || rootItem : rootItem;parent.children.push(item);item.parent = parent;}@@ -411,3 +427,30 @@ function collectSources(actions: trace.ActionTraceEvent[], errorDescriptors: Err}return result;}++const kFakeRootAction: ActionTraceEventInContext = {+ type: 'action',+ callId: '',+ startTime: 0,+ endTime: 0,+ class: '',+ method: '',+ params: {},+ log: [],+ context: {+ origin: 'library',+ startTime: 0,+ endTime: 0,+ browserName: '',+ wallTime: 0,+ options: {},+ pages: [],+ resources: [],+ actions: [],+ events: [],+ stdio: [],+ errors: [],+ hasSource: false,+ contextId: '',+ },+};diff --git a/packages/trace-viewer/src/ui/actionList.tsx b/packages/trace-viewer/src/ui/actionList.tsxindex 16e4e71613..879397d9ef 100644--- a/packages/trace-viewer/src/ui/actionList.tsx+++ b/packages/trace-viewer/src/ui/actionList.tsx@@ -68,24 +68,24 @@ export const ActionList: React.FC<ActionListProps> = ({}, [itemMap, selectedAction]);const isError = React.useCallback((item: ActionTreeItem) => {- return !!item.action?.error?.message;+ return !!item.action.error?.message;}, []);const onAccepted = React.useCallback((item: ActionTreeItem) => {- return setSelectedTime({ minimum: item.action!.startTime, maximum: item.action!.endTime });+ return setSelectedTime({ minimum: item.action.startTime, maximum: item.action.endTime });}, [setSelectedTime]);const render = React.useCallback((item: ActionTreeItem) => {- const showAttachments = !!revealActionAttachment && !!item.action?.attachments?.length;- return renderAction(item.action!, { sdkLanguage, revealConsole, revealActionAttachment: () => revealActionAttachment?.(item.action!.callId), isLive, showDuration: true, showBadges: true, showAttachments });+ const showAttachments = !!revealActionAttachment && !!item.action.attachments?.length;+ return renderAction(item.action, { sdkLanguage, revealConsole, revealActionAttachment: () => revealActionAttachment?.(item.action.callId), isLive, showDuration: true, showBadges: true, showAttachments });}, [isLive, revealConsole, revealActionAttachment, sdkLanguage]);const isVisible = React.useCallback((item: ActionTreeItem) => {- return !selectedTime || !item.action || (item.action!.startTime <= selectedTime.maximum && item.action!.endTime >= selectedTime.minimum);+ return !selectedTime || !item.action || (item.action.startTime <= selectedTime.maximum && item.action.endTime >= selectedTime.minimum);}, [selectedTime]);const onSelectedAction = React.useCallback((item: ActionTreeItem) => {- onSelected?.(item.action!);+ onSelected?.(item.action);}, [onSelected]);const onHighlightedAction = React.useCallback((item: ActionTreeItem | undefined) => {diff --git a/tests/config/utils.ts b/tests/config/utils.tsindex b1ae53f67f..b712f9ef81 100644--- a/tests/config/utils.ts+++ b/tests/config/utils.ts@@ -16,14 +16,14 @@import type { Locator, Frame, Page } from 'playwright-core';import { ZipFile } from '../../packages/playwright-core/lib/server/utils/zipFile';-import type { TraceLoaderBackend } from '../../packages/playwright-core/src/utils/isomorphic/trace/traceLoader';import type { StackFrame } from '../../packages/protocol/src/channels';import { parseClientSideCallMetadata } from '../../packages/playwright-core/lib/utils/isomorphic/traceUtils';import { TraceLoader } from '../../packages/playwright-core/src/utils/isomorphic/trace/traceLoader';-import type { ActionTreeItem } from '../../packages/playwright-core/src/utils/isomorphic/trace/traceModel';-import { buildActionTree, TraceModel } from '../../packages/playwright-core/src/utils/isomorphic/trace/traceModel';-import type { ActionTraceEvent, ConsoleMessageTraceEvent, EventTraceEvent, TraceEvent } from '@trace/trace';+import { TraceModel } from '../../packages/playwright-core/src/utils/isomorphic/trace/traceModel';+import type { ActionTraceEvent, TraceEvent } from '@trace/trace';import { renderTitleForCall } from '../../packages/playwright-core/lib/utils/isomorphic/protocolFormatter';+import { ZipTraceLoaderBackend } from '../../packages/playwright-core/lib/server/trace/viewer/traceParser';+import type { SnapshotStorage } from '../../packages/playwright-core/src/utils/isomorphic/trace/snapshotStorage';export type BoundingBox = Awaited<ReturnType<Locator['boundingBox']>>;@@ -165,31 +165,11 @@ export async function parseTraceRaw(file: string): Promise<{ events: any[], reso};}-export async function parseTrace(file: string): Promise<{ resources: Map<string, Buffer>, events: (EventTraceEvent | ConsoleMessageTraceEvent)[], actions: ActionTraceEvent[], titles: string[], loader: TraceLoader, model: TraceModel, actionTree: string[], errors: string[] }> {- const backend = new TraceBackend(file);+export async function parseTrace(file: string): Promise<{ snapshots: SnapshotStorage, model: TraceModel }> {+ const backend = new ZipTraceLoaderBackend(file);const loader = new TraceLoader();await loader.load(backend, () => {});- const model = new TraceModel(file, loader.contextEntries);- const actions = model.filteredActions([]);- const { rootItem } = buildActionTree(actions);- const actionTree: string[] = [];- const visit = (actionItem: ActionTreeItem, indent: string) => {- const title = renderTitleForCall({ ...actionItem.action, type: actionItem.action.class });- actionTree.push(`${indent}${title || actionItem.id}`);- for (const child of actionItem.children)- visit(child, indent + ' ');- };- rootItem.children.forEach(a => visit(a, ''));- return {- titles: actions.map(a => renderTitleForCall({ ...a, type: a.class })),- resources: backend.entries,- actions,- events: model.events,- errors: model.errors.map(e => e.message),- model,- loader,- actionTree,- };+ return { model: new TraceModel(file, loader.contextEntries), snapshots: loader.storage() };}export async function parseHar(file: string): Promise<Map<string, Buffer>> {@@ -247,53 +227,3 @@ const ansiRegex = new RegExp('[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(export function stripAnsi(str: string): string {return str.replace(ansiRegex, '');}-class TraceBackend implements TraceLoaderBackend {- private _fileName: string;- private _entriesPromise: Promise<Map<string, Buffer>>;- readonly entries = new Map<string, Buffer>();-- constructor(fileName: string) {- this._fileName = fileName;- this._entriesPromise = this._readEntries();- }-- private async _readEntries(): Promise<Map<string, Buffer>> {- const zipFS = new ZipFile(this._fileName);- for (const entry of await zipFS.entries())- this.entries.set(entry, await zipFS.read(entry));- zipFS.close();- return this.entries;- }-- isLive() {- return false;- }-- traceURL() {- return 'file://' + this._fileName;- }-- async entryNames(): Promise<string[]> {- const entries = await this._entriesPromise;- return [...entries.keys()];- }-- async hasEntry(entryName: string): Promise<boolean> {- const entries = await this._entriesPromise;- return entries.has(entryName);- }-- async readText(entryName: string): Promise<string | undefined> {- const entries = await this._entriesPromise;- const entry = entries.get(entryName);- if (!entry)- return;- return entry.toString();- }-- async readBlob(entryName: string) {- const entries = await this._entriesPromise;- const entry = entries.get(entryName);- return entry as any;- }-}diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.tsindex 55fc1876a2..2b756d1a36 100644--- a/tests/library/browsertype-connect.spec.ts+++ b/tests/library/browsertype-connect.spec.ts@@ -22,7 +22,7 @@ import * as path from 'path';import { getUserAgent, getPlaywrightVersion } from '../../packages/playwright-core/lib/server/utils/userAgent';import WebSocket from 'ws';import { expect, playwrightTest } from '../config/browserTest';-import { parseTrace, suppressCertificateWarning, rafraf } from '../config/utils';+import { parseTraceRaw, suppressCertificateWarning, rafraf } from '../config/utils';import formidable from 'formidable';import type { Browser, ConnectOptions } from 'playwright-core';import { createHttpServer } from '../../packages/playwright-core/lib/server/utils/network';@@ -658,7 +658,7 @@ for (const kind of ['launchServer', 'run-server'] as const) {await context.close();await browser.close();- const { resources } = await parseTrace(testInfo.outputPath('trace1.zip'));+ const { resources } = await parseTraceRaw(testInfo.outputPath('trace1.zip'));const sourceNames = Array.from(resources.keys()).filter(k => k.endsWith('.txt'));expect(sourceNames.length).toBe(1);const sourceFile = resources.get(sourceNames[0]);diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.tsindex 84d1d745bb..0dee62a814 100644--- a/tests/library/trace-viewer.spec.ts+++ b/tests/library/trace-viewer.spec.ts@@ -733,10 +733,9 @@ test('empty adopted style sheets should not prevent node refs', async ({ page })await page.context().tracing.stop({ path: traceFile });const trace = await parseTrace(traceFile);- const snapshots = trace.loader.storage();- const secondEvaluate = trace.actions.findLast(a => a.method === 'evaluateExpression');+ const secondEvaluate = trace.model.actions.findLast(a => a.method === 'evaluateExpression');expect(secondEvaluate.beforeSnapshot).toBeTruthy();- const snapshot = snapshots.snapshotByName(snapshots.snapshotsForTest()[0], secondEvaluate.beforeSnapshot);+ const snapshot = trace.snapshots.snapshotByName(trace.snapshots.snapshotsForTest()[0], secondEvaluate.beforeSnapshot);// Second snapshot should be just a copy of the first one.expect(snapshot.snapshot().html).toEqual([[1, 9]]);});diff --git a/tests/playwright-test/playwright.connect.spec.ts b/tests/playwright-test/playwright.connect.spec.tsindex 0584bd88c4..94664a3ae6 100644--- a/tests/playwright-test/playwright.connect.spec.ts+++ b/tests/playwright-test/playwright.connect.spec.ts@@ -213,18 +213,18 @@ test('should record trace', async ({ runInlineTest }) => {expect(fs.existsSync(test.info().outputPath('test-results', 'a-pass', 'trace.zip'))).toBe(false);const trace = await parseTrace(test.info().outputPath('test-results', 'a-fail', 'trace.zip'));- expect(trace.titles).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',- 'Fixture "context"',- 'Create context',- 'Fixture "page"',- 'Create page',+ ' Fixture "context"',+ ' Create context',+ ' Fixture "page"',+ ' Create page','Expect "toBe"','After Hooks',- 'Fixture "page"',- 'Fixture "context"',- 'Close context',+ ' Fixture "page"',+ ' Fixture "context"',+ ' Close context','Worker Cleanup',- 'Fixture "browser"',+ ' Fixture "browser"',]);});diff --git a/tests/playwright-test/playwright.reuse.spec.ts b/tests/playwright-test/playwright.reuse.spec.tsindex 1e3c1d797c..cba587545f 100644--- a/tests/playwright-test/playwright.reuse.spec.ts+++ b/tests/playwright-test/playwright.reuse.spec.ts@@ -125,7 +125,7 @@ test('should reuse context with trace if mode=when-possible', async ({ runInlineexpect(result.output).toContain('fromAfterAll');const trace1 = await parseTrace(testInfo.outputPath('test-results', 'reuse-one', 'trace.zip'));- expect(trace1.actionTree).toEqual([+ expect(trace1.model.renderActionTree()).toEqual(['Before Hooks',' beforeAll hook',' Fixture "browser"',@@ -139,11 +139,11 @@ test('should reuse context with trace if mode=when-possible', async ({ runInline' Fixture "page"',' Fixture "context"',]);- expect(trace1.loader.storage().snapshotsForTest().length).toBeGreaterThan(0);+ expect(trace1.snapshots.snapshotsForTest().length).toBeGreaterThan(0);expect(fs.existsSync(testInfo.outputPath('test-results', 'reuse-one', 'trace-1.zip'))).toBe(false);const trace2 = await parseTrace(testInfo.outputPath('test-results', 'reuse-two', 'trace.zip'));- expect(trace2.actionTree).toEqual([+ expect(trace2.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "context"',' Fixture "page"',@@ -156,7 +156,7 @@ test('should reuse context with trace if mode=when-possible', async ({ runInline' Fixture "context"',' afterAll hook',]);- expect(trace2.loader.storage().snapshotsForTest().length).toBeGreaterThan(0);+ expect(trace2.snapshots.snapshotsForTest().length).toBeGreaterThan(0);});test('should work with manually closed pages', async ({ runInlineTest }) => {@@ -478,19 +478,19 @@ test('should reset tracing', async ({ runInlineTest }, testInfo) => {expect(result.passed).toBe(2);const trace1 = await parseTrace(traceFile1);- expect(trace1.titles).toEqual([+ expect(trace1.model.renderActionTree()).toEqual(['Set content','Click',]);- expect(trace1.loader.storage().snapshotsForTest().length).toBeGreaterThan(0);+ expect(trace1.snapshots.snapshotsForTest().length).toBeGreaterThan(0);const trace2 = await parseTrace(traceFile2);- expect(trace2.titles).toEqual([+ expect(trace2.model.renderActionTree()).toEqual(['Set content','Fill "value"','Click',]);- expect(trace1.loader.storage().snapshotsForTest().length).toBeGreaterThan(0);+ expect(trace1.snapshots.snapshotsForTest().length).toBeGreaterThan(0);});test('should not delete others contexts', async ({ runInlineTest }) => {diff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.tsindex acaed54aef..17a0bc609f 100644--- a/tests/playwright-test/playwright.trace.spec.ts+++ b/tests/playwright-test/playwright.trace.spec.ts@@ -87,7 +87,7 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {expect(result.failed).toBe(1);// One trace file for request context and one for each APIRequestContextconst trace1 = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));- expect(trace1.actionTree).toEqual([+ expect(trace1.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "request"',' Create request context',@@ -106,14 +106,14 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {' Fixture "request"',]);const trace2 = await parseTrace(testInfo.outputPath('test-results', 'a-api-pass', 'trace.zip'));- expect(trace2.actionTree).toEqual([+ expect(trace2.model.renderActionTree()).toEqual(['Before Hooks','Create request context','GET "/empty.html"','After Hooks',]);const trace3 = await parseTrace(testInfo.outputPath('test-results', 'a-fail', 'trace.zip'));- expect(trace3.actionTree).toEqual([+ expect(trace3.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "request"',' Create request context',@@ -224,7 +224,7 @@ test('should save sources when requested', async ({ runInlineTest }, testInfo) =`,}, { workers: 1 });expect(result.exitCode).toEqual(0);- const { resources } = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));+ const { resources } = await parseTraceRaw(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));expect([...resources.keys()].filter(name => name.startsWith('resources/src@'))).toHaveLength(1);});@@ -248,7 +248,7 @@ test('should not save sources when not requested', async ({ runInlineTest }, tes`,}, { workers: 1 });expect(result.exitCode).toEqual(0);- const { resources } = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));+ const { resources } = await parseTraceRaw(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));expect([...resources.keys()].filter(name => name.startsWith('resources/src@'))).toHaveLength(0);});@@ -315,7 +315,7 @@ test('should not override trace file in afterAll', async ({ runInlineTest, serveexpect(result.failed).toBe(1);const trace1 = await parseTrace(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'));- expect(trace1.actionTree).toEqual([+ expect(trace1.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -336,7 +336,7 @@ test('should not override trace file in afterAll', async ({ runInlineTest, serve'Worker Cleanup',' Fixture "browser"',]);- expect(trace1.errors).toEqual([`'oh no!'`]);+ expect(trace1.model.errors.map(e => e.message)).toEqual([`'oh no!'`]);const error = await parseTrace(testInfo.outputPath('test-results', 'a-test-2', 'trace.zip')).catch(e => e);expect(error).toBeTruthy();@@ -449,7 +449,7 @@ test(`trace:retain-on-failure should create trace if context is closed before fa}, { trace: 'retain-on-failure' });const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('Navigate to "about:blank"');+ expect(trace.model.renderActionTree()).toContain('Navigate to "about:blank"');expect(result.failed).toBe(1);});@@ -471,7 +471,7 @@ test(`trace:retain-on-failure should create trace if context is closed before fa}, { trace: 'retain-on-failure' });const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('Navigate to "about:blank"');+ expect(trace.model.renderActionTree()).toContain(' Navigate to "about:blank"');expect(result.failed).toBe(1);});@@ -491,7 +491,7 @@ test(`trace:retain-on-failure should create trace if request context is disposed}, { trace: 'retain-on-failure' });const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('GET "/empty.html"');+ expect(trace.model.renderActionTree()).toContain('GET "/empty.html"');expect(result.failed).toBe(1);});@@ -511,18 +511,20 @@ test('should include attachments by default', async ({ runInlineTest, server },expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);- const trace = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));- expect(trace.titles).toEqual([+ const tracePath = testInfo.outputPath('test-results', 'a-pass', 'trace.zip');+ const trace = await parseTrace(tracePath);+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks','Attach "foo"','After Hooks',]);- expect(trace.actions[1].attachments).toEqual([{+ expect(trace.model.actions[1].attachments).toEqual([{name: 'foo',contentType: 'text/plain',sha1: expect.any(String),}]);- expect([...trace.resources.keys()]).toContain(`resources/${trace.actions[1].attachments[0].sha1}`);+ const { resources } = await parseTraceRaw(tracePath);+ expect([...resources.keys()]).toContain(`resources/${trace.model.actions[1].attachments[0].sha1}`);});test('should opt out of attachments', async ({ runInlineTest, server }, testInfo) => {@@ -541,14 +543,16 @@ test('should opt out of attachments', async ({ runInlineTest, server }, testInfoexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);- const trace = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));- expect(trace.titles).toEqual([+ const tracePath = testInfo.outputPath('test-results', 'a-pass', 'trace.zip');+ const trace = await parseTrace(tracePath);+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',`Attach "foo"`,'After Hooks',]);- expect(trace.actions[1].attachments).toEqual(undefined);- expect([...trace.resources.keys()].filter(f => f.startsWith('resources/') && !f.startsWith('resources/src@'))).toHaveLength(0);+ expect(trace.model.actions[1].attachments).toEqual(undefined);+ const { resources } = await parseTraceRaw(tracePath);+ expect([...resources.keys()].filter(f => f.startsWith('resources/') && !f.startsWith('resources/src@'))).toHaveLength(0);});test('should record with custom page fixture', async ({ runInlineTest }, testInfo) => {@@ -600,7 +604,7 @@ test('should expand expect.toPass', async ({ runInlineTest }, testInfo) => {expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-pass', 'trace.zip'));- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -640,7 +644,7 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfoexpect(result.exitCode).toBe(1);expect(result.failed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-fail', 'trace.zip'));- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -656,7 +660,7 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfo'Worker Cleanup',' Fixture "browser"',]);- expect(trace.errors).toEqual(['ReferenceError: undefinedVariable1 is not defined']);+ expect(trace.model.errors.map(e => e.message)).toEqual(['ReferenceError: undefinedVariable1 is not defined']);});test('should show error from beforeAll in trace', async ({ runInlineTest }, testInfo) => {@@ -677,7 +681,7 @@ test('should show error from beforeAll in trace', async ({ runInlineTest }, testexpect(result.exitCode).toBe(1);expect(result.failed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-fail', 'trace.zip'));- expect(trace.errors).toEqual(['Error: Oh my!']);+ expect(trace.model.errors.map(e => e.message)).toEqual(['Error: Oh my!']);});test('should throw when trace fixture is a function', async ({ runInlineTest }, testInfo) => {@@ -715,7 +719,7 @@ test('should not throw when attachment is missing', async ({ runInlineTest }, teexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-passes', 'trace.zip'));- expect(trace.titles).toContain('Attach "screenshot"');+ expect(trace.model.renderActionTree()).toContain('Attach "screenshot"');});test('should not throw when screenshot on failure fails', async ({ runInlineTest, server }, testInfo) => {@@ -745,7 +749,7 @@ test('should not throw when screenshot on failure fails', async ({ runInlineTestexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-has-download-page', 'trace.zip'));- const attachedScreenshots = trace.actions.filter(a => a.attachments).flatMap(a => a.attachments);+ const attachedScreenshots = trace.model.actions.filter(a => a.attachments).flatMap(a => a.attachments);// One screenshot for the page, no screenshot for the download page since it should have failed.expect(attachedScreenshots.length).toBe(1);});@@ -769,7 +773,7 @@ test('should use custom expect message in trace', async ({ runInlineTest }, testexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-fail', 'trace.zip'));- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -920,7 +924,7 @@ test('should record nested steps, even after timeout', async ({ runInlineTest },expect(result.exitCode).toBe(1);expect(result.failed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-example', 'trace.zip'));- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' beforeAll hook',' Fixture "browser"',@@ -1010,7 +1014,7 @@ test('should not produce an action entry for calling a binding', async ({ runInlexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const trace = await parseTrace(testInfo.outputPath('test-results', 'a-passes', 'trace.zip'));- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -1058,14 +1062,14 @@ test('should attribute worker fixture teardown to the right test', async ({ runIexpect(result.passed).toBe(1);expect(result.failed).toBe(1);const trace1 = await parseTrace(testInfo.outputPath('test-results', 'a-one', 'trace.zip'));- expect(trace1.actionTree).toEqual([+ expect(trace1.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "foo"',' step in foo setup','After Hooks',]);const trace2 = await parseTrace(testInfo.outputPath('test-results', 'a-two', 'trace.zip'));- expect(trace2.actionTree).toEqual([+ expect(trace2.model.renderActionTree()).toEqual(['Before Hooks','After Hooks','Worker Cleanup',@@ -1091,7 +1095,7 @@ test('trace:retain-on-first-failure should create trace but only on first failurconst tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('Navigate to "about:blank"');+ expect(trace.model.renderActionTree()).toContain('Navigate to "about:blank"');expect(result.failed).toBe(1);});@@ -1108,7 +1112,7 @@ test('trace:retain-on-first-failure should create trace if context is closed bef}, { trace: 'retain-on-first-failure' });const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('Navigate to "about:blank"');+ expect(trace.model.renderActionTree()).toContain('Navigate to "about:blank"');expect(result.failed).toBe(1);});@@ -1127,7 +1131,7 @@ test('trace:retain-on-first-failure should create trace if context is closed bef}, { trace: 'retain-on-first-failure' });const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('Navigate to "about:blank"');+ expect(trace.model.renderActionTree()).toContain(' Navigate to "about:blank"');expect(result.failed).toBe(1);});@@ -1144,7 +1148,7 @@ test('trace:retain-on-first-failure should create trace if request context is di}, { trace: 'retain-on-first-failure' });const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.titles).toContain('GET "/empty.html"');+ expect(trace.model.renderActionTree()).toContain('GET "/empty.html"');expect(result.failed).toBe(1);});@@ -1169,7 +1173,7 @@ test('should not corrupt actions when no library trace is present', async ({ runconst tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "foo"',' Expect "toBe"',@@ -1199,7 +1203,7 @@ test('should record trace for manually created context in a failed test', asyncconst tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -1211,7 +1215,7 @@ test('should record trace for manually created context in a failed test', async' Fixture "browser"',]);// Check console events to make sure that library trace is recorded.- expect(trace.events).toContainEqual(expect.objectContaining({ type: 'console', text: 'from the page' }));+ expect(trace.model.events).toContainEqual(expect.objectContaining({ type: 'console', text: 'from the page' }));});test('should not nest top level expect into unfinished api calls ', {@@ -1241,7 +1245,7 @@ test('should not nest top level expect into unfinished api calls ', {const tracePath = test.info().outputPath('test-results', 'a-pass', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -1282,7 +1286,7 @@ test('should record trace after fixture teardown timeout', {const tracePath = test.info().outputPath('test-results', 'a-fails', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -1298,7 +1302,7 @@ test('should record trace after fixture teardown timeout', {' Fixture "browser"',]);// Check console events to make sure that library trace is recorded.- expect(trace.events).toContainEqual(expect.objectContaining({ type: 'console', text: 'from the page' }));+ expect(trace.model.events).toContainEqual(expect.objectContaining({ type: 'console', text: 'from the page' }));});test('should record trace snapshot for more obscure commands', async ({ runInlineTest }) => {@@ -1319,7 +1323,7 @@ test('should record trace snapshot for more obscure commands', async ({ runInlinconst tracePath = test.info().outputPath('test-results', 'a-test-1', 'trace.zip');const trace = await parseTrace(tracePath);- expect(trace.actionTree).toEqual([+ expect(trace.model.renderActionTree()).toEqual(['Before Hooks',' Fixture "browser"',' Launch browser',@@ -1331,18 +1335,17 @@ test('should record trace snapshot for more obscure commands', async ({ runInlin'After Hooks',]);- const snapshots = trace.loader.storage();- const snapshotFrameOrPageId = snapshots.snapshotsForTest()[0];+ const snapshotFrameOrPageId = trace.snapshots.snapshotsForTest()[0];- const countAction = trace.actions.find(a => a.method === 'queryCount');+ const countAction = trace.model.actions.find(a => a.method === 'queryCount');expect(countAction.beforeSnapshot).toBeTruthy();expect(countAction.afterSnapshot).toBeTruthy();- expect(snapshots.snapshotByName(snapshotFrameOrPageId, countAction.beforeSnapshot)).toBeTruthy();- expect(snapshots.snapshotByName(snapshotFrameOrPageId, countAction.afterSnapshot)).toBeTruthy();+ expect(trace.snapshots.snapshotByName(snapshotFrameOrPageId, countAction.beforeSnapshot)).toBeTruthy();+ expect(trace.snapshots.snapshotByName(snapshotFrameOrPageId, countAction.afterSnapshot)).toBeTruthy();- const boundingBoxAction = trace.actions.find(a => a.title === 'Bounding box');+ const boundingBoxAction = trace.model.actions.find(a => a.title === 'Bounding box');expect(boundingBoxAction.beforeSnapshot).toBeTruthy();expect(boundingBoxAction.afterSnapshot).toBeTruthy();- expect(snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.beforeSnapshot)).toBeTruthy();- expect(snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.afterSnapshot)).toBeTruthy();+ expect(trace.snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.beforeSnapshot)).toBeTruthy();+ expect(trace.snapshots.snapshotByName(snapshotFrameOrPageId, boundingBoxAction.afterSnapshot)).toBeTruthy();});