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
fix(ui-mode): ensure page exists before fetching snapshot (#37130)
Adam Gastineau018f2afbec07
diff --git a/packages/trace-viewer/src/ui/snapshotTab.tsx b/packages/trace-viewer/src/ui/snapshotTab.tsxindex 858abfa9a9..c9c20513e5 100644--- a/packages/trace-viewer/src/ui/snapshotTab.tsx+++ b/packages/trace-viewer/src/ui/snapshotTab.tsx@@ -307,10 +307,35 @@ function createRecorders(recorders: { recorder: Recorder, frameSelector: stringexport type Snapshot = {action: ActionTraceEvent;snapshotName: string;+ pageId: string;point?: { x: number, y: number };hasInputTarget?: boolean;};+const createSnapshot = (action: ActionTraceEvent, snapshotNameKey: 'beforeSnapshot' | 'afterSnapshot' | 'inputSnapshot', hasInputTarget: boolean = false): Snapshot | undefined => {+ if (!action)+ return undefined;++ const snapshotName = action[snapshotNameKey];++ if (!snapshotName)+ return undefined;++ if (!action.pageId) {+ // eslint-disable-next-line no-console+ console.error('snapshot action must have a pageId');+ return undefined;+ }++ return {+ action,+ snapshotName,+ pageId: action.pageId,+ point: action.point,+ hasInputTarget,+ };+};+export type SnapshotInfo = {url: string;viewport: { width: number, height: number };@@ -334,18 +359,18 @@ export function collectSnapshots(action: ActionTraceEvent | undefined): Snapshotif (!action)return {};- let beforeSnapshot: Snapshot | undefined = action.beforeSnapshot ? { action, snapshotName: action.beforeSnapshot } : undefined;+ let beforeSnapshot = createSnapshot(action, 'beforeSnapshot');if (!beforeSnapshot) {// If the action has no beforeSnapshot, use the last available afterSnapshot.for (let a = previousActionByEndTime(action); a; a = previousActionByEndTime(a)) {if (a.endTime <= action.startTime && a.afterSnapshot) {- beforeSnapshot = { action: a, snapshotName: a.afterSnapshot };+ beforeSnapshot = createSnapshot(a, 'afterSnapshot');break;}}}- let afterSnapshot: Snapshot | undefined = action.afterSnapshot ? { action, snapshotName: action.afterSnapshot } : undefined;+ let afterSnapshot = createSnapshot(action, 'afterSnapshot');if (!afterSnapshot) {let last: ActionTraceEvent | undefined;// - For test.step, we want to use the snapshot of the last nested action.@@ -363,12 +388,12 @@ export function collectSnapshots(action: ActionTraceEvent | undefined): Snapshotlast = a;}if (last)- afterSnapshot = { action: last, snapshotName: last.afterSnapshot! };+ afterSnapshot = createSnapshot(last, 'afterSnapshot');elseafterSnapshot = beforeSnapshot;}- const actionSnapshot: Snapshot | undefined = action.inputSnapshot ? { action, snapshotName: action.inputSnapshot, hasInputTarget: true } : afterSnapshot;+ const actionSnapshot = createSnapshot(action, 'inputSnapshot', true) ?? afterSnapshot;if (actionSnapshot)actionSnapshot.point = action.point;return { action: actionSnapshot, before: beforeSnapshot, after: afterSnapshot };@@ -392,8 +417,8 @@ export function extendSnapshot(snapshot: Snapshot, shouldPopulateCanvasFromScreeif (shouldPopulateCanvasFromScreenshot)params.set('shouldPopulateCanvasFromScreenshot', '1');- const snapshotUrl = new URL(`snapshot/${snapshot.action.pageId}?${params.toString()}`, window.location.href).toString();- const snapshotInfoUrl = new URL(`snapshotInfo/${snapshot.action.pageId}?${params.toString()}`, window.location.href).toString();+ const snapshotUrl = new URL(`snapshot/${snapshot.pageId}?${params.toString()}`, window.location.href).toString();+ const snapshotInfoUrl = new URL(`snapshotInfo/${snapshot.pageId}?${params.toString()}`, window.location.href).toString();const popoutParams = new URLSearchParams();popoutParams.set('r', snapshotUrl);