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: follow up to trace filter, rework (#39577)
Pavel Feldman151ff1e8a769
diff --git a/docs/src/trace-viewer.md b/docs/src/trace-viewer.mdindex 2192b98d60..ed5a855e5c 100644--- a/docs/src/trace-viewer.md+++ b/docs/src/trace-viewer.md@@ -686,9 +686,7 @@ public class WithTestNameAttribute : BeforeAfterTestAttribute## Trace Viewer features### Actions-In the Actions tab you can see what locator was used for every action and how long each one took to run. Use the **Filter actions** search field at the top of the list to filter the action hierarchy by text; only actions whose title matches the search (and their parent actions) are shown. Clear the filter to show all actions again; expanded nodes are preserved when the filter is removed.--Hover over each action of your test and visually see the change in the DOM snapshot. Go back and forward in time and click an action to inspect and debug. Use the Before and After tabs to visually see what happened before and after the action.+In the Actions tab you can see what locator was used for every action and how long each one took to run. Hover over each action of your test and visually see the change in the DOM snapshot. Go back and forward in time and click an action to inspect and debug. Use the Before and After tabs to visually see what happened before and after the action.<img src="https://github.com/microsoft/playwright/assets/13063165/948b65cd-f0fd-4c7f-8e53-2c632b5a07f1" alt="actions tab in trace viewer" width="3598" height="2218" />diff --git a/packages/trace-viewer/src/ui/actionList.css b/packages/trace-viewer/src/ui/actionList.cssindex a9339c6a97..435b6ada3f 100644--- a/packages/trace-viewer/src/ui/actionList.css+++ b/packages/trace-viewer/src/ui/actionList.css@@ -123,3 +123,10 @@height: 28px;align-items: center;}++.action-list-container {+ min-height: 0;+ flex: auto;+ display: flex;+ flex-direction: column;+}diff --git a/packages/trace-viewer/src/ui/actionList.tsx b/packages/trace-viewer/src/ui/actionList.tsxindex 8ca6955798..56fb5e0e16 100644--- a/packages/trace-viewer/src/ui/actionList.tsx+++ b/packages/trace-viewer/src/ui/actionList.tsx@@ -29,92 +29,6 @@ import { testStatusIcon } from './testUtils';import { methodMetainfo } from '@isomorphic/protocolMetainfo';import { formatProtocolParam } from '@isomorphic/protocolFormatter';-function getTitleFormat(action: ActionTraceEvent): string {- const metaTitle = methodMetainfo.get(`${action.class}.${action.method}`)?.title;- const raw = action.title ?? metaTitle ?? action.method ?? '';- return String(raw).replace(/\n/g, ' ');-}--function expandPlaceholders(format: string, params: Record<string, any>): string {- return format.replace(/\{([^}]+)\}/g, (fullMatch, paramKey) => {- const value = formatProtocolParam(params, paramKey);- return value === undefined ? fullMatch : String(value);- });-}--export function getActionSearchText(action: ActionTraceEvent): string {- try {- const titleFormat = getTitleFormat(action);- return expandPlaceholders(titleFormat, action.params ?? {});- } catch {- return String(action.title ?? action.method ?? '');- }-}--function computeVisibleCallIds(- actionFilterText: string | undefined,- itemMap: Map<string, ActionTreeItem>,-): Set<string> | null {- const query = actionFilterText?.trim().toLowerCase();- if (!query)- return null;-- const matchingCallIds = new Set<string>();- for (const item of itemMap.values()) {- const callId = item.action.callId;- if (!callId)- continue;-- const searchText = getActionSearchText(item.action).toLowerCase();- if (searchText.includes(query))- matchingCallIds.add(callId);- }-- const visibleCallIds = new Set<string>();-- const addAncestors = (item: ActionTreeItem | undefined) => {- if (!item)- return;-- const callId = item.action.callId;- if (callId && visibleCallIds.has(callId))- return;-- if (callId)- visibleCallIds.add(callId);-- if (item.parent)- addAncestors(item.parent);- };-- for (const callId of matchingCallIds)- addAncestors(itemMap.get(callId));-- for (const callId of matchingCallIds)- visibleCallIds.add(callId);-- return visibleCallIds;-}--function expandTreeForCallIds(- callIdsToExpand: Set<string>,- itemMap: Map<string, ActionTreeItem>,- previousState: TreeState,-): TreeState {- const expandedItems = new Map(previousState.expandedItems);-- for (const callId of callIdsToExpand) {- const item = itemMap.get(callId);- if (!item)- continue;-- for (let parent: ActionTreeItem | undefined = item.parent; parent && parent.action.callId; parent = parent.parent)- expandedItems.set(parent.action.callId, true);- }-- return { ...previousState, expandedItems };-}-export interface ActionListProps {actions: ActionTraceEventInContext[],selectedAction: ActionTraceEventInContext | undefined,@@ -155,27 +69,6 @@ export const ActionList: React.FC<ActionListProps> = ({return { selectedItem };}, [itemMap, selectedAction]);- const visibleCallIds = React.useMemo(() => {- return computeVisibleCallIds(actionFilterText, itemMap);- }, [itemMap, actionFilterText]);-- const prevVisibleCallIdsRef = React.useRef<Set<string> | null>(null);- React.useEffect(() => {- if (visibleCallIds) {- prevVisibleCallIdsRef.current = visibleCallIds;- return;- }-- const previousVisibleCallIds = prevVisibleCallIdsRef.current;- if (!previousVisibleCallIds)- return;-- prevVisibleCallIdsRef.current = null;- setTreeState(previousState =>- expandTreeForCallIds(previousVisibleCallIds, itemMap, previousState),- );- }, [visibleCallIds, itemMap, setTreeState]);-const isError = React.useCallback((item: ActionTreeItem) => {return !!item.action.error?.message;}, []);@@ -193,10 +86,12 @@ export const ActionList: React.FC<ActionListProps> = ({const timeVisible = !selectedTime || !item.action || (item.action.startTime <= selectedTime.maximum && item.action.endTime >= selectedTime.minimum);if (!timeVisible)return false;- if (!visibleCallIds || !item.action.callId)+ const title = renderTitleForCall(item.action).title;+ if (!actionFilterText)return true;- return visibleCallIds.has(item.action.callId);- }, [selectedTime, visibleCallIds]);+ const isIncluded = title.toLowerCase().includes(actionFilterText.toLowerCase());+ return isIncluded ? true : 'if-needed';+ }, [selectedTime, actionFilterText]);const onSelectedAction = React.useCallback((item: ActionTreeItem) => {onSelected?.(item.action);@@ -266,7 +161,7 @@ export const renderAction = (</div>;};-export function renderTitleForCall(action: ActionTraceEvent): { elements: React.ReactNode[], title: string } {+export function renderTitleForCall(action: ActionTraceEvent, sdkLanguage?: Language): { elements: React.ReactNode[], title: string } {let titleFormat = action.title ?? methodMetainfo.get(action.class + '.' + action.method)?.title ?? action.method;titleFormat = titleFormat.replace(/\n/g, ' ');@@ -303,5 +198,10 @@ export function renderTitleForCall(action: ActionTraceEvent): { elements: React.title.push(chunk);}+ const locator = action.params.selector ? asLocatorDescription(sdkLanguage || 'javascript', action.params.selector) : undefined;+ if (locator) {+ title.push(' ');+ title.push(locator);+ }return { elements, title: title.join('') };}diff --git a/packages/trace-viewer/src/ui/workbench.css b/packages/trace-viewer/src/ui/workbench.cssindex b557d7aa03..928b2e5845 100644--- a/packages/trace-viewer/src/ui/workbench.css+++ b/packages/trace-viewer/src/ui/workbench.css@@ -46,30 +46,12 @@}.workbench-action-filter {- flex: none;- padding: 4px;+ margin-top: 3px;border-bottom: 1px solid var(--vscode-panel-border);}.workbench-action-filter input[type=search] {width: 100%;- box-sizing: border-box;padding: 4px 8px;line-height: 20px;- outline: none;- border: 1px solid var(--vscode-input-border);- border-radius: 2px;- color: var(--vscode-input-foreground);- background-color: var(--vscode-input-background);-}--.workbench-action-filter input[type=search]:focus {- border-color: var(--vscode-focusBorder);-}--.action-list-container {- min-height: 0;- flex: auto;- display: flex;- flex-direction: column;}diff --git a/packages/web/src/components/treeView.tsx b/packages/web/src/components/treeView.tsxindex 60d3886d4d..b2f98af0dc 100644--- a/packages/web/src/components/treeView.tsx+++ b/packages/web/src/components/treeView.tsx@@ -35,7 +35,7 @@ export type TreeViewProps<T> = {title?: (item: T) => string,icon?: (item: T) => string | undefined,isError?: (item: T) => boolean,- isVisible?: (item: T) => boolean,+ isVisible?: (item: T) => boolean | 'if-needed',selectedItem?: T,onAccepted?: (item: T) => void,onSelected?: (item: T) => void,@@ -336,13 +336,27 @@ type TreeItemData = {prev: TreeItem | null;};+function isEffectivelyVisible<T extends TreeItem>(+ item: T,+ isVisible: (item: T) => boolean | 'if-needed',+ cache: Map<string, boolean>): boolean {+ const cached = cache.get(item.id);+ if (cached !== undefined)+ return cached;+ const v = isVisible(item);+ const result = v === 'if-needed' ? item.children.some(child => isEffectivelyVisible(child as T, isVisible, cache)) : v;+ cache.set(item.id, result);+ return result;+}+function indexTree<T extends TreeItem>(rootItem: T,selectedItem: T | undefined,expandedItems: Map<string, boolean | undefined>,autoExpandDepth: number,- isVisible: (item: T) => boolean = () => true): Map<T, TreeItemData> {- if (!isVisible(rootItem))+ isVisible: (item: T) => boolean | 'if-needed' = () => true): Map<T, TreeItemData> {+ const visibilityCache = new Map<string, boolean>();+ if (!isEffectivelyVisible(rootItem, isVisible, visibilityCache))return new Map();const result = new Map<T, TreeItemData>();@@ -353,7 +367,7 @@ function indexTree<T extends TreeItem>(const appendChildren = (parent: T, depth: number) => {for (const item of parent.children as T[]) {- if (!isVisible(item))+ if (!isEffectivelyVisible(item, isVisible, visibilityCache))continue;const expandState = temporaryExpanded.has(item.id) || expandedItems.get(item.id);const autoExpandMatches = autoExpandDepth > depth && result.size < 25 && expandState !== false;