Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat: split "show all actions" into 3 groups (#37043)

Dmitry Gozman4a95d9ac5a26
diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts
index de2a0597e3..5e8e7e6226 100644
--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts
+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts
@@ -20,7 +20,6 @@ import path from 'path';
import { Snapshotter } from './snapshotter';
import { methodMetainfo } from '../../../utils/isomorphic/protocolMetainfo';
-import { getActionGroup } from '../../../utils/isomorphic/protocolFormatter';
import { assert } from '../../../utils/isomorphic/assert';
import { monotonicTime } from '../../../utils/isomorphic/time';
import { eventsHelper } from '../../utils/eventsHelper';
@@ -669,7 +668,6 @@ function createBeforeActionTraceEvent(metadata: CallMetadata, parentId?: string)
params: metadata.params,
stepId: metadata.stepId,
pageId: metadata.pageId,
- visibility: getActionGroup(metadata) ? 'hidden' : undefined,
};
if (parentId)
event.parentId = parentId;
diff --git a/packages/playwright-core/src/utils/isomorphic/protocolFormatter.ts b/packages/playwright-core/src/utils/isomorphic/protocolFormatter.ts
index 584a1f9517..9f8547d705 100644
--- a/packages/playwright-core/src/utils/isomorphic/protocolFormatter.ts
+++ b/packages/playwright-core/src/utils/isomorphic/protocolFormatter.ts
@@ -65,6 +65,8 @@ export function renderTitleForCall(metadata: { title?: string, type: string, met
});
}
+export type ActionGroup = 'configuration' | 'route' | 'getter';
+
export function getActionGroup(metadata: { type: string, method: string }) {
- return methodMetainfo.get(metadata.type + '.' + metadata.method)?.group as undefined | 'configuration' | 'route' | 'getter';
+ return methodMetainfo.get(metadata.type + '.' + metadata.method)?.group as undefined | ActionGroup;
}
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index 26a5bf8f3a..9277f03632 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -279,7 +279,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
title: renderTitle(channel.type, channel.method, channel.params, data.title),
apiName: data.apiName,
params: channel.params,
- visibility: getActionGroup({ type: channel.type, method: channel.method }) ? 'hidden' : undefined,
+ group: getActionGroup({ type: channel.type, method: channel.method }),
}, tracingGroupSteps[tracingGroupSteps.length - 1]);
data.userData = step;
data.stepId = step.stepId;
diff --git a/packages/playwright/src/worker/fixtureRunner.ts b/packages/playwright/src/worker/fixtureRunner.ts
index 818f1a9ba4..6e236b4486 100644
--- a/packages/playwright/src/worker/fixtureRunner.ts
+++ b/packages/playwright/src/worker/fixtureRunner.ts
@@ -19,7 +19,7 @@ import { escapeWithQuotes, ManualPromise } from 'playwright-core/lib/utils';
import { fixtureParameterNames } from '../common/fixtures';
import { filterStackFile, formatLocation } from '../util';
-import type { TestInfoImpl, TestStepVisibility } from './testInfo';
+import type { TestInfoImpl } from './testInfo';
import type { FixtureDescription, RunnableDescription } from './timeoutManager';
import type { WorkerInfo } from '../../types/test';
import type { Location } from '../../types/testReporter';
@@ -35,7 +35,7 @@ class Fixture {
private _selfTeardownComplete: Promise<void> | undefined;
private _setupDescription: FixtureDescription;
private _teardownDescription: FixtureDescription;
- private _stepInfo: { title: string, category: 'fixture', location?: Location, visibility?: TestStepVisibility };
+ private _stepInfo: { title: string, category: 'fixture', location?: Location, group?: string };
_deps = new Set<Fixture>();
_usages = new Set<Fixture>();
@@ -48,7 +48,7 @@ class Fixture {
const location = isUserFixture ? this.registration.location : undefined;
this._stepInfo = { title: `Fixture ${escapeWithQuotes(title, '"')}`, category: 'fixture', location };
if (this.registration.box)
- this._stepInfo.visibility = isUserFixture ? 'hidden' : 'internal';
+ this._stepInfo.group = isUserFixture ? 'configuration' : 'internal';
this._setupDescription = {
title,
phase: 'setup',
diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts
index 344c50a64b..4e7a0d4e2b 100644
--- a/packages/playwright/src/worker/testInfo.ts
+++ b/packages/playwright/src/worker/testInfo.ts
@@ -34,7 +34,6 @@ import type { TestCase } from '../common/test';
import type { StackFrame } from '@protocol/channels';
import type { RecoverFromStepErrorResult } from '@testIsomorphic/testServerInterface';
-export type TestStepVisibility = 'internal' | 'hidden';
export type TestStepCategory = 'expect' | 'fixture' | 'hook' | 'pw:api' | 'test.step' | 'test.attach';
interface TestStepData {
@@ -45,7 +44,9 @@ interface TestStepData {
params?: Record<string, any>;
infectParentStepsWithError?: boolean;
box?: boolean;
- visibility?: TestStepVisibility;
+ // steps with any defined group are hidden from the report
+ // 'internal' steps are hidden from the trace
+ group?: string;
}
export interface TestStepInternal extends TestStepData {
@@ -293,13 +294,11 @@ export class TestInfoImpl implements TestInfo {
location = location || boxedStack[0];
}
location = location || filteredStack[0];
- const visibility = (parentStep?.visibility === 'internal' || data.visibility === 'internal') ? 'internal' :
- (parentStep?.visibility === 'hidden' || data.visibility === 'hidden' ? 'hidden' : undefined);
const step: TestStepInternal = {
...data,
stepId,
- visibility,
+ group: parentStep?.group ?? data.group,
boxedStack,
location,
steps: [],
@@ -348,7 +347,7 @@ export class TestInfoImpl implements TestInfo {
}
}
- if (!step.visibility) {
+ if (!step.group) {
const payload: StepEndPayload = {
testId: this.testId,
stepId,
@@ -359,7 +358,7 @@ export class TestInfoImpl implements TestInfo {
};
this._onStepEnd(payload);
}
- if (step.visibility !== 'internal') {
+ if (step.group !== 'internal') {
const errorForTrace = step.error ? { name: '', message: step.error.message || '', stack: step.error.stack } : undefined;
const attachments = step.attachmentIndices.map(i => this.attachments[i]);
this._tracing.appendAfterActionForStep(stepId, errorForTrace, attachments, step.info.annotations);
@@ -370,7 +369,7 @@ export class TestInfoImpl implements TestInfo {
parentStepList.push(step);
this._stepMap.set(stepId, step);
- if (!step.visibility) {
+ if (!step.group) {
const payload: StepBeginPayload = {
testId: this.testId,
stepId,
@@ -382,7 +381,7 @@ export class TestInfoImpl implements TestInfo {
};
this._onStepBegin(payload);
}
- if (step.visibility !== 'internal') {
+ if (step.group !== 'internal') {
this._tracing.appendBeforeActionForStep({
stepId,
parentId: parentStep?.stepId,
@@ -390,7 +389,7 @@ export class TestInfoImpl implements TestInfo {
category: step.category,
params: step.params,
stack: step.location ? [step.location] : [],
- visibility: step.visibility,
+ group: step.group,
});
}
@@ -423,7 +422,7 @@ export class TestInfoImpl implements TestInfo {
this._tracing.appendForError(serialized);
}
- async _runAsStep(stepInfo: { title: string, category: 'hook' | 'fixture', location?: Location, visibility?: TestStepVisibility }, cb: () => Promise<any>) {
+ async _runAsStep(stepInfo: { title: string, category: 'hook' | 'fixture', location?: Location, group?: string }, cb: () => Promise<any>) {
const step = this._addStep(stepInfo);
try {
await cb();
diff --git a/packages/playwright/src/worker/testTracing.ts b/packages/playwright/src/worker/testTracing.ts
index 3866932103..6707bd8384 100644
--- a/packages/playwright/src/worker/testTracing.ts
+++ b/packages/playwright/src/worker/testTracing.ts
@@ -263,7 +263,7 @@ export class TestTracing {
});
}
- appendBeforeActionForStep(options: { stepId: string, parentId?: string, title: string, category: TestStepCategory, params?: Record<string, any>, stack: StackFrame[], visibility?: 'hidden' }) {
+ appendBeforeActionForStep(options: { stepId: string, parentId?: string, title: string, category: TestStepCategory, params?: Record<string, any>, stack: StackFrame[], group?: string }) {
this._appendTraceEvent({
type: 'before',
callId: options.stepId,
@@ -275,7 +275,7 @@ export class TestTracing {
title: options.title,
params: Object.fromEntries(Object.entries(options.params || {}).map(([name, value]) => [name, generatePreview(value)])),
stack: options.stack,
- visibility: options.visibility,
+ group: options.group,
});
}
diff --git a/packages/trace-viewer/src/ui/defaultSettingsView.tsx b/packages/trace-viewer/src/ui/defaultSettingsView.tsx
index 13f5393c7f..03e1a018f0 100644
--- a/packages/trace-viewer/src/ui/defaultSettingsView.tsx
+++ b/packages/trace-viewer/src/ui/defaultSettingsView.tsx
@@ -18,6 +18,7 @@ import * as React from 'react';
import { SettingsView } from './settingsView';
import { useDarkModeSetting } from '@web/theme';
import { useSetting } from '@web/uiUtils';
+import type { ActionGroup } from '@isomorphic/protocolFormatter';
/**
* A view of the collection of standard settings used between various applications
@@ -27,7 +28,7 @@ export const DefaultSettingsView: React.FC<{}> = () => {
shouldPopulateCanvasFromScreenshot,
setShouldPopulateCanvasFromScreenshot,
] = useSetting('shouldPopulateCanvasFromScreenshot', false);
- const [showAllActions, setShowAllActions] = useSetting('showAllActions', false);
+ const [actionsFilter, setActionsFilter] = useSetting<ActionGroup[]>('actionsFilter', []);
const [darkMode, setDarkMode] = useDarkModeSetting();
return (
@@ -41,10 +42,19 @@ export const DefaultSettingsView: React.FC<{}> = () => {
title: 'Attempt to display the captured canvas appearance in the snapshot preview. May not be accurate.',
},
{
- value: showAllActions,
- set: setShowAllActions,
- name: 'Show all actions',
- title: 'Show all actions including routes, getters, boxed fixtures, etc.',
+ value: actionsFilter.includes('getter'),
+ set: value => setActionsFilter(value ? [...actionsFilter, 'getter'] : actionsFilter.filter(a => a !== 'getter')),
+ name: 'Show getter actions',
+ },
+ {
+ value: actionsFilter.includes('route'),
+ set: value => setActionsFilter(value ? [...actionsFilter, 'route'] : actionsFilter.filter(a => a !== 'route')),
+ name: 'Show route actions',
+ },
+ {
+ value: actionsFilter.includes('configuration'),
+ set: value => setActionsFilter(value ? [...actionsFilter, 'configuration'] : actionsFilter.filter(a => a !== 'configuration')),
+ name: 'Show configuration actions',
},
]}
/>
diff --git a/packages/trace-viewer/src/ui/modelUtil.ts b/packages/trace-viewer/src/ui/modelUtil.ts
index a66dda6ba9..cd5ed0a168 100644
--- a/packages/trace-viewer/src/ui/modelUtil.ts
+++ b/packages/trace-viewer/src/ui/modelUtil.ts
@@ -14,12 +14,15 @@
* limitations under the License.
*/
+import { getActionGroup } from '@isomorphic/protocolFormatter';
+
import type { Language } from '@isomorphic/locatorGenerators';
import type { ResourceSnapshot } from '@trace/snapshot';
import type * as trace from '@trace/trace';
import type { ActionTraceEvent } from '@trace/trace';
import type { ActionEntry, ContextEntry, PageEntry } from '../types/entries';
import type { StackFrame } from '@protocol/channels';
+import type { ActionGroup } from '@isomorphic/protocolFormatter';
const contextSymbol = Symbol('context');
const nextInContextSymbol = Symbol('nextInContext');
@@ -120,8 +123,12 @@ export class MultiTraceModel {
return this.actions.findLast(a => a.error);
}
- filteredActions(showAllActions: boolean) {
- return showAllActions ? this.actions : this.actions.filter(a => a.visibility !== 'hidden');
+ filteredActions(actionsFilter: ActionGroup[]) {
+ const filter = new Set<string>(actionsFilter);
+ return this.actions.filter(action => {
+ const group = action.group ?? getActionGroup({ type: action.class, method: action.method });
+ return !group || filter.has(group);
+ });
}
private _errorDescriptorsFromActions(): ErrorDescription[] {
@@ -272,8 +279,8 @@ function mergeActionsAndUpdateTimingSameTrace(contexts: ContextEntry[]): ActionT
existing.annotations = action.annotations;
if (action.parentId)
existing.parentId = nonPrimaryIdToPrimaryId.get(action.parentId) ?? action.parentId;
- if (action.visibility === 'hidden')
- existing.visibility = 'hidden';
+ if (action.group)
+ existing.group = action.group;
// For the events that are present in the test runner context, always take
// their time from the test runner context to preserve client side order.
existing.startTime = action.startTime;
@@ -421,28 +428,3 @@ function collectSources(actions: trace.ActionTraceEvent[], errorDescriptors: Err
}
return result;
}
-
-const kRouteMethods = new Set([
- 'page.route',
- 'page.routefromhar',
- 'page.unroute',
- 'page.unrouteall',
- 'browsercontext.route',
- 'browsercontext.routefromhar',
- 'browsercontext.unroute',
- 'browsercontext.unrouteall',
-]);
-
-{
- // .NET adds async suffix.
- for (const method of [...kRouteMethods])
- kRouteMethods.add(method + 'async');
- // Python methods which contain underscores.
- for (const method of [
- 'page.route_from_har',
- 'page.unroute_all',
- 'context.route_from_har',
- 'context.unroute_all',
- ])
- kRouteMethods.add(method);
-}
diff --git a/packages/trace-viewer/src/ui/timeline.tsx b/packages/trace-viewer/src/ui/timeline.tsx
index d4ce588985..e4010f972c 100644
--- a/packages/trace-viewer/src/ui/timeline.tsx
+++ b/packages/trace-viewer/src/ui/timeline.tsx
@@ -25,6 +25,7 @@ import './timeline.css';
import type { Language } from '@isomorphic/locatorGenerators';
import type { Entry } from '@trace/har';
import type { ConsoleEntry } from './consoleTab';
+import type { ActionGroup } from '@isomorphic/protocolFormatter';
type TimelineBar = {
action?: ActionTraceEventInContext;
@@ -53,7 +54,7 @@ export const Timeline: React.FunctionComponent<{
const [measure, ref] = useMeasure<HTMLDivElement>();
const [dragWindow, setDragWindow] = React.useState<{ startX: number, endX: number, pivot?: number, type: 'resize' | 'move' } | undefined>();
const [previewPoint, setPreviewPoint] = React.useState<FilmStripPreviewPoint | undefined>();
- const [showAllActions] = useSetting('showAllActions', false);
+ const [actionsFilter] = useSetting<ActionGroup[]>('actionsFilter', []);
const { offsets, curtainLeft, curtainRight } = React.useMemo(() => {
let activeWindow = selectedTime || boundaries;
@@ -68,7 +69,7 @@ export const Timeline: React.FunctionComponent<{
return { offsets: calculateDividerOffsets(measure.width, boundaries), curtainLeft, curtainRight };
}, [selectedTime, boundaries, dragWindow, measure]);
- const actions = React.useMemo(() => model?.filteredActions(showAllActions), [model, showAllActions]);
+ const actions = React.useMemo(() => model?.filteredActions(actionsFilter), [model, actionsFilter]);
const bars = React.useMemo(() => {
const bars: TimelineBar[] = [];
diff --git a/packages/trace-viewer/src/ui/workbench.tsx b/packages/trace-viewer/src/ui/workbench.tsx
index 9df0452109..9c0a3fccc3 100644
--- a/packages/trace-viewer/src/ui/workbench.tsx
+++ b/packages/trace-viewer/src/ui/workbench.tsx
@@ -44,6 +44,7 @@ import type { AfterActionTraceEventAttachment } from '@trace/trace';
import type { HighlightedElement } from './snapshotTab';
import type { TestAnnotation } from '@playwright/test';
import { MetadataWithCommitInfo } from '@testIsomorphic/types';
+import type { ActionGroup } from '@isomorphic/protocolFormatter';
export const Workbench: React.FunctionComponent<{
model?: modelUtil.MultiTraceModel,
@@ -71,14 +72,14 @@ export const Workbench: React.FunctionComponent<{
const [highlightedElement, setHighlightedElement] = React.useState<HighlightedElement>({ lastEdited: 'none' });
const [selectedTime, setSelectedTime] = React.useState<Boundaries | undefined>();
const [sidebarLocation, setSidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');
- const [showAllActions] = useSetting('showAllActions', false);
+ const [actionsFilter] = useSetting<ActionGroup[]>('actionsFilter', []);
const setSelectedAction = React.useCallback((action: modelUtil.ActionTraceEventInContext | undefined) => {
setSelectedCallId(action?.callId);
setRevealedError(undefined);
}, []);
- const actions = React.useMemo(() => model?.filteredActions(showAllActions), [model, showAllActions]);
+ const actions = React.useMemo(() => model?.filteredActions(actionsFilter), [model, actionsFilter]);
const highlightedAction = React.useMemo(() => {
return actions?.find(a => a.callId === highlightedCallId);
diff --git a/packages/trace/src/trace.ts b/packages/trace/src/trace.ts
index 47cc5d734b..e8ce55602a 100644
--- a/packages/trace/src/trace.ts
+++ b/packages/trace/src/trace.ts
@@ -70,7 +70,7 @@ export type BeforeActionTraceEvent = {
stack?: StackFrame[];
pageId?: string;
parentId?: string;
- visibility?: 'hidden';
+ group?: string;
};
export type InputActionTraceEvent = {
diff --git a/tests/config/traceViewerFixtures.ts b/tests/config/traceViewerFixtures.ts
index 9c68c07dc4..6d839675ba 100644
--- a/tests/config/traceViewerFixtures.ts
+++ b/tests/config/traceViewerFixtures.ts
@@ -51,7 +51,6 @@ class TraceViewerPage {
settingsDialog: Locator;
darkModeSetting: Locator;
displayCanvasContentSetting: Locator;
- showAllActionsSetting: Locator;
constructor(public page: Page) {
this.actionTitles = page.locator('.action-title');
@@ -70,7 +69,15 @@ class TraceViewerPage {
this.settingsDialog = page.getByTestId('settings-toolbar-dialog');
this.darkModeSetting = page.locator('.setting').getByText('Dark mode');
this.displayCanvasContentSetting = page.locator('.setting').getByText('Display canvas content');
- this.showAllActionsSetting = page.locator('.setting').getByText('Show all actions');
+ }
+
+ @step
+ async showAllActions() {
+ await this.page.getByRole('button', { name: 'Settings' }).click();
+ await this.page.locator('.setting').getByText('Show route actions').click();
+ await this.page.locator('.setting').getByText('Show getter actions').click();
+ await this.page.locator('.setting').getByText('Show configuration actions').click();
+ await this.page.getByRole('button', { name: 'Settings' }).click();
}
stackFrames(options: { selected?: boolean } = {}) {
diff --git a/tests/config/utils.ts b/tests/config/utils.ts
index bab9d21aff..be598b5f7a 100644
--- a/tests/config/utils.ts
+++ b/tests/config/utils.ts
@@ -163,7 +163,7 @@ export async function parseTrace(file: string): Promise<{ resources: Map<string,
const traceModel = new TraceModel();
await traceModel.load(backend, () => {});
const model = new MultiTraceModel(traceModel.contextEntries);
- const actions = model.filteredActions(false);
+ const actions = model.filteredActions([]);
const { rootItem } = buildActionTree(actions);
const actionTree: string[] = [];
const visit = (actionItem: ActionTreeItem, indent: string) => {
diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts
index abf35f6234..5352621baf 100644
--- a/tests/library/trace-viewer.spec.ts
+++ b/tests/library/trace-viewer.spec.ts
@@ -911,8 +911,7 @@ test('should highlight target elements', async ({ page, runAndTrace, browserName
});
}
- await traceViewer.showSettings();
- await traceViewer.showAllActionsSetting.click();
+ await traceViewer.showAllActions();
const framePageClick = await traceViewer.snapshotFrame('Click');
await expect.poll(() => highlightedDivs(framePageClick)).toEqual(['t1']);
@@ -1483,8 +1482,7 @@ test('should open snapshot in new browser context', async ({ browser, page, runA
test('should show similar actions from legacy library-only trace', async ({ showTraceViewer, asset }) => {
const traceViewer = await showTraceViewer([asset('trace-library-1.46.zip')]);
- await traceViewer.showSettings();
- await traceViewer.showAllActionsSetting.click();
+ await traceViewer.showAllActions();
await expect(traceViewer.actionTitles).toHaveText([
/page\.setContent/,
/locator\.getAttribute/,
@@ -1971,9 +1969,7 @@ test('should show all actions', async ({ runAndTrace, page }) => {
/Expect "toBeChecked"/,
]);
- await traceViewer.showSettings();
- await expect(traceViewer.showAllActionsSetting).not.toBeChecked();
- await traceViewer.showAllActionsSetting.click();
+ await traceViewer.showAllActions();
await expect(traceViewer.actionTitles).toHaveText([
/Route requests/,
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index d7e0f946f3..24c6bbea11 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -716,9 +716,9 @@ for (const useIntermediateMergeReport of [true, false] as const) {
// Trace viewer should not hang here when displaying parallal requests.
await expect(page.getByTestId('actions-tree')).toContainText('GET');
- await page.getByText('GET').nth(2).click();
- await page.getByText('GET').nth(1).click();
- await page.getByText('GET').nth(0).click();
+ await page.getByText('GET "/empty.html"').nth(2).click();
+ await page.getByText('GET "/empty.html"').nth(1).click();
+ await page.getByText('GET "/empty.html"').nth(0).click();
});
test('should warn user when viewing via file:// protocol', async ({ runInlineTest, page, showReport }, testInfo) => {
diff --git a/tests/playwright-test/ui-mode-trace.spec.ts b/tests/playwright-test/ui-mode-trace.spec.ts
index 76fca1c3c4..56c4607bef 100644
--- a/tests/playwright-test/ui-mode-trace.spec.ts
+++ b/tests/playwright-test/ui-mode-trace.spec.ts
@@ -507,7 +507,9 @@ test('should hide boxed fixtures and contents, reveal upon show all actions sett
`);
await page.getByText('Settings').click();
- await page.getByText('Show all actions').click();
+ await page.getByText('Show route actions').click();
+ await page.getByText('Show configuration actions').click();
+ await page.getByText('Show getter actions').click();
await page.getByTestId('actions-tree').getByRole('treeitem', { name: 'Before Hooks' }).locator('.codicon-chevron-right').click();
await page.getByTestId('actions-tree').getByRole('treeitem', { name: 'Fixture "fixture"' }).locator('.codicon-chevron-right').click();