chore(trace): remove screenshot instead of snapshot code
This commit is contained in:
parent
b275c19612
commit
309ccd8420
|
|
@ -22,16 +22,15 @@ import * as React from 'react';
|
||||||
import './sourceTab.css';
|
import './sourceTab.css';
|
||||||
|
|
||||||
export const InspectorTab: React.FunctionComponent<{
|
export const InspectorTab: React.FunctionComponent<{
|
||||||
showScreenshot: boolean,
|
|
||||||
sdkLanguage: Language,
|
sdkLanguage: Language,
|
||||||
setIsInspecting: (isInspecting: boolean) => void,
|
setIsInspecting: (isInspecting: boolean) => void,
|
||||||
highlightedLocator: string,
|
highlightedLocator: string,
|
||||||
setHighlightedLocator: (locator: string) => void,
|
setHighlightedLocator: (locator: string) => void,
|
||||||
}> = ({ showScreenshot, sdkLanguage, setIsInspecting, highlightedLocator, setHighlightedLocator }) => {
|
}> = ({ sdkLanguage, setIsInspecting, highlightedLocator, setHighlightedLocator }) => {
|
||||||
return <div className='vbox' style={{ backgroundColor: 'var(--vscode-sideBar-background)' }}>
|
return <div className='vbox' style={{ backgroundColor: 'var(--vscode-sideBar-background)' }}>
|
||||||
<div style={{ margin: '10px 0px 10px 10px', color: 'var(--vscode-editorCodeLens-foreground)', flex: 'none' }}>Locator</div>
|
<div style={{ margin: '10px 0px 10px 10px', color: 'var(--vscode-editorCodeLens-foreground)', flex: 'none' }}>Locator</div>
|
||||||
<div style={{ margin: '0 10px 10px', flex: 'auto' }}>
|
<div style={{ margin: '0 10px 10px', flex: 'auto' }}>
|
||||||
<CodeMirrorWrapper text={showScreenshot ? '/* disable "show screenshot" setting to pick locator */' : highlightedLocator} language={sdkLanguage} focusOnChange={true} isFocused={true} wrapLines={true} onChange={text => {
|
<CodeMirrorWrapper text={highlightedLocator} language={sdkLanguage} focusOnChange={true} isFocused={true} wrapLines={true} onChange={text => {
|
||||||
// Updating text needs to go first - react can squeeze a render between the state updates.
|
// Updating text needs to go first - react can squeeze a render between the state updates.
|
||||||
setHighlightedLocator(text);
|
setHighlightedLocator(text);
|
||||||
setIsInspecting(false);
|
setIsInspecting(false);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import type { ActionEntry, ContextEntry, PageEntry } from '../types/entries';
|
||||||
import type { StackFrame } from '@protocol/channels';
|
import type { StackFrame } from '@protocol/channels';
|
||||||
|
|
||||||
const contextSymbol = Symbol('context');
|
const contextSymbol = Symbol('context');
|
||||||
const pageSymbol = Symbol('page');
|
|
||||||
const nextInContextSymbol = Symbol('next');
|
const nextInContextSymbol = Symbol('next');
|
||||||
const prevInListSymbol = Symbol('prev');
|
const prevInListSymbol = Symbol('prev');
|
||||||
const eventsSymbol = Symbol('events');
|
const eventsSymbol = Symbol('events');
|
||||||
|
|
@ -148,7 +147,6 @@ function indexModel(context: ContextEntry) {
|
||||||
for (let i = 0; i < context.actions.length; ++i) {
|
for (let i = 0; i < context.actions.length; ++i) {
|
||||||
const action = context.actions[i] as any;
|
const action = context.actions[i] as any;
|
||||||
action[contextSymbol] = context;
|
action[contextSymbol] = context;
|
||||||
action[pageSymbol] = context.pages.find(page => page.pageId === action.pageId);
|
|
||||||
}
|
}
|
||||||
let lastNonRouteAction = undefined;
|
let lastNonRouteAction = undefined;
|
||||||
for (let i = context.actions.length - 1; i >= 0; i--) {
|
for (let i = context.actions.length - 1; i >= 0; i--) {
|
||||||
|
|
@ -353,10 +351,6 @@ export function prevInList(action: ActionTraceEvent): ActionTraceEvent {
|
||||||
return (action as any)[prevInListSymbol];
|
return (action as any)[prevInListSymbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pageForAction(action: ActionTraceEvent): PageEntry {
|
|
||||||
return (action as any)[pageSymbol];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function stats(action: ActionTraceEvent): { errors: number, warnings: number } {
|
export function stats(action: ActionTraceEvent): { errors: number, warnings: number } {
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
let warnings = 0;
|
let warnings = 0;
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,6 @@ const PropertiesView: React.FunctionComponent<{
|
||||||
id: 'inspector',
|
id: 'inspector',
|
||||||
title: 'Locator',
|
title: 'Locator',
|
||||||
render: () => <InspectorTab
|
render: () => <InspectorTab
|
||||||
showScreenshot={false}
|
|
||||||
sdkLanguage={sdkLanguage}
|
sdkLanguage={sdkLanguage}
|
||||||
setIsInspecting={setIsInspecting}
|
setIsInspecting={setIsInspecting}
|
||||||
highlightedLocator={highlightedLocator}
|
highlightedLocator={highlightedLocator}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
import './snapshotTab.css';
|
import './snapshotTab.css';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import type { ActionTraceEvent } from '@trace/trace';
|
import type { ActionTraceEvent } from '@trace/trace';
|
||||||
import { context, type MultiTraceModel, pageForAction, prevInList } from './modelUtil';
|
import { context, type MultiTraceModel, prevInList } from './modelUtil';
|
||||||
import { Toolbar } from '@web/components/toolbar';
|
import { Toolbar } from '@web/components/toolbar';
|
||||||
import { ToolbarButton } from '@web/components/toolbarButton';
|
import { ToolbarButton } from '@web/components/toolbarButton';
|
||||||
import { clsx, useMeasure } from '@web/uiUtils';
|
import { clsx, useMeasure } from '@web/uiUtils';
|
||||||
|
|
@ -29,16 +29,6 @@ import type { Language } from '@isomorphic/locatorGenerators';
|
||||||
import { locatorOrSelectorAsSelector } from '@isomorphic/locatorParser';
|
import { locatorOrSelectorAsSelector } from '@isomorphic/locatorParser';
|
||||||
import { TabbedPaneTab } from '@web/components/tabbedPane';
|
import { TabbedPaneTab } from '@web/components/tabbedPane';
|
||||||
import { BrowserFrame } from './browserFrame';
|
import { BrowserFrame } from './browserFrame';
|
||||||
import { ClickPointer } from './clickPointer';
|
|
||||||
|
|
||||||
function findClosest<T>(items: T[], metric: (v: T) => number, target: number) {
|
|
||||||
return items.find((item, index) => {
|
|
||||||
if (index === items.length - 1)
|
|
||||||
return true;
|
|
||||||
const next = items[index + 1];
|
|
||||||
return Math.abs(metric(item) - target) < Math.abs(metric(next) - target);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SnapshotTabsView: React.FunctionComponent<{
|
export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
action: ActionTraceEvent | undefined,
|
action: ActionTraceEvent | undefined,
|
||||||
|
|
@ -52,7 +42,6 @@ export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
openPage?: (url: string, target?: string) => Window | any,
|
openPage?: (url: string, target?: string) => Window | any,
|
||||||
}> = ({ action, sdkLanguage, testIdAttributeName, isInspecting, setIsInspecting, highlightedLocator, setHighlightedLocator, openPage }) => {
|
}> = ({ action, sdkLanguage, testIdAttributeName, isInspecting, setIsInspecting, highlightedLocator, setHighlightedLocator, openPage }) => {
|
||||||
const [snapshotTab, setSnapshotTab] = React.useState<'action'|'before'|'after'>('action');
|
const [snapshotTab, setSnapshotTab] = React.useState<'action'|'before'|'after'>('action');
|
||||||
const showScreenshotInsteadOfSnapshot = false;
|
|
||||||
|
|
||||||
const snapshots = React.useMemo(() => {
|
const snapshots = React.useMemo(() => {
|
||||||
return collectSnapshots(action);
|
return collectSnapshots(action);
|
||||||
|
|
@ -64,7 +53,7 @@ export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
|
|
||||||
return <div className='snapshot-tab vbox'>
|
return <div className='snapshot-tab vbox'>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<ToolbarButton className='pick-locator' title={showScreenshotInsteadOfSnapshot ? 'Disable "screenshots instead of snapshots" to pick a locator' : 'Pick locator'} icon='target' toggled={isInspecting} onClick={() => setIsInspecting(!isInspecting)} disabled={showScreenshotInsteadOfSnapshot} />
|
<ToolbarButton className='pick-locator' title='Pick locator' icon='target' toggled={isInspecting} onClick={() => setIsInspecting(!isInspecting)} />
|
||||||
{['action', 'before', 'after'].map(tab => {
|
{['action', 'before', 'after'].map(tab => {
|
||||||
return <TabbedPaneTab
|
return <TabbedPaneTab
|
||||||
key={tab}
|
key={tab}
|
||||||
|
|
@ -75,7 +64,7 @@ export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
></TabbedPaneTab>;
|
></TabbedPaneTab>;
|
||||||
})}
|
})}
|
||||||
<div style={{ flex: 'auto' }}></div>
|
<div style={{ flex: 'auto' }}></div>
|
||||||
<ToolbarButton icon='link-external' title={showScreenshotInsteadOfSnapshot ? 'Not available when showing screenshot' : 'Open snapshot in a new tab'} disabled={!snapshotUrls?.popoutUrl || showScreenshotInsteadOfSnapshot} onClick={() => {
|
<ToolbarButton icon='link-external' title='Open snapshot in a new tab' disabled={!snapshotUrls?.popoutUrl} onClick={() => {
|
||||||
if (!openPage)
|
if (!openPage)
|
||||||
openPage = window.open;
|
openPage = window.open;
|
||||||
const win = openPage(snapshotUrls?.popoutUrl || '', '_blank');
|
const win = openPage(snapshotUrls?.popoutUrl || '', '_blank');
|
||||||
|
|
@ -85,7 +74,7 @@ export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
});
|
});
|
||||||
}} />
|
}} />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
{!showScreenshotInsteadOfSnapshot && <SnapshotView
|
<SnapshotView
|
||||||
snapshotUrls={snapshotUrls}
|
snapshotUrls={snapshotUrls}
|
||||||
sdkLanguage={sdkLanguage}
|
sdkLanguage={sdkLanguage}
|
||||||
testIdAttributeName={testIdAttributeName}
|
testIdAttributeName={testIdAttributeName}
|
||||||
|
|
@ -93,11 +82,7 @@ export const SnapshotTabsView: React.FunctionComponent<{
|
||||||
setIsInspecting={setIsInspecting}
|
setIsInspecting={setIsInspecting}
|
||||||
highlightedLocator={highlightedLocator}
|
highlightedLocator={highlightedLocator}
|
||||||
setHighlightedLocator={setHighlightedLocator}
|
setHighlightedLocator={setHighlightedLocator}
|
||||||
/>}
|
/>
|
||||||
{showScreenshotInsteadOfSnapshot && <ScreenshotView
|
|
||||||
action={action}
|
|
||||||
snapshotUrls={snapshotUrls}
|
|
||||||
snapshot={snapshots[snapshotTab]} />}
|
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -193,38 +178,6 @@ export const SnapshotView: React.FunctionComponent<{
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ScreenshotView: React.FunctionComponent<{
|
|
||||||
action: ActionTraceEvent | undefined,
|
|
||||||
snapshotUrls: SnapshotUrls | undefined,
|
|
||||||
snapshot: Snapshot | undefined,
|
|
||||||
}> = ({ action, snapshotUrls, snapshot }) => {
|
|
||||||
const [snapshotInfo, setSnapshotInfo] = React.useState<SnapshotInfo>({ viewport: kDefaultViewport, url: '' });
|
|
||||||
React.useEffect(() => {
|
|
||||||
fetchSnapshotInfo(snapshotUrls?.snapshotInfoUrl).then(setSnapshotInfo);
|
|
||||||
}, [snapshotUrls?.snapshotInfoUrl]);
|
|
||||||
|
|
||||||
const page = action ? pageForAction(action) : undefined;
|
|
||||||
const screencastFrame = React.useMemo(() => {
|
|
||||||
if (snapshotInfo.wallTime && page?.screencastFrames[0]?.frameSwapWallTime)
|
|
||||||
return findClosest(page.screencastFrames, frame => frame.frameSwapWallTime!, snapshotInfo.wallTime);
|
|
||||||
|
|
||||||
if (snapshotInfo.timestamp && page?.screencastFrames)
|
|
||||||
return findClosest(page.screencastFrames, frame => frame.timestamp, snapshotInfo.timestamp);
|
|
||||||
},
|
|
||||||
[page?.screencastFrames, snapshotInfo.timestamp, snapshotInfo.wallTime]);
|
|
||||||
|
|
||||||
const point = snapshot?.point;
|
|
||||||
|
|
||||||
return <SnapshotWrapper snapshotInfo={snapshotInfo}>
|
|
||||||
{screencastFrame && (
|
|
||||||
<>
|
|
||||||
{point && <ClickPointer point={point} />}
|
|
||||||
<img alt={`Screenshot of ${action?.apiName}`} src={`sha1/${screencastFrame.sha1}`} width={screencastFrame.width} height={screencastFrame.height} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</SnapshotWrapper>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const SnapshotWrapper: React.FunctionComponent<React.PropsWithChildren<{
|
const SnapshotWrapper: React.FunctionComponent<React.PropsWithChildren<{
|
||||||
snapshotInfo: SnapshotInfo,
|
snapshotInfo: SnapshotInfo,
|
||||||
}>> = ({ snapshotInfo, children }) => {
|
}>> = ({ snapshotInfo, children }) => {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ export const Workbench: React.FunctionComponent<{
|
||||||
const [highlightedLocator, setHighlightedLocator] = React.useState<string>('');
|
const [highlightedLocator, setHighlightedLocator] = React.useState<string>('');
|
||||||
const [selectedTime, setSelectedTime] = React.useState<Boundaries | undefined>();
|
const [selectedTime, setSelectedTime] = React.useState<Boundaries | undefined>();
|
||||||
const [sidebarLocation, setSidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');
|
const [sidebarLocation, setSidebarLocation] = useSetting<'bottom' | 'right'>('propertiesSidebarLocation', 'bottom');
|
||||||
const showScreenshot = false;
|
|
||||||
|
|
||||||
const setSelectedAction = React.useCallback((action: modelUtil.ActionTraceEventInContext | undefined) => {
|
const setSelectedAction = React.useCallback((action: modelUtil.ActionTraceEventInContext | undefined) => {
|
||||||
setSelectedCallId(action?.callId);
|
setSelectedCallId(action?.callId);
|
||||||
|
|
@ -164,7 +163,6 @@ export const Workbench: React.FunctionComponent<{
|
||||||
id: 'inspector',
|
id: 'inspector',
|
||||||
title: 'Locator',
|
title: 'Locator',
|
||||||
render: () => <InspectorTab
|
render: () => <InspectorTab
|
||||||
showScreenshot={showScreenshot}
|
|
||||||
sdkLanguage={sdkLanguage}
|
sdkLanguage={sdkLanguage}
|
||||||
setIsInspecting={setIsInspecting}
|
setIsInspecting={setIsInspecting}
|
||||||
highlightedLocator={highlightedLocator}
|
highlightedLocator={highlightedLocator}
|
||||||
|
|
|
||||||
|
|
@ -1421,36 +1421,6 @@ test('should serve css without content-type', async ({ page, runAndTrace, server
|
||||||
await expect(snapshotFrame.locator('body')).toHaveCSS('background-color', 'rgb(255, 0, 0)', { timeout: 0 });
|
await expect(snapshotFrame.locator('body')).toHaveCSS('background-color', 'rgb(255, 0, 0)', { timeout: 0 });
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('should allow showing screenshots instead of snapshots', async ({ runAndTrace, page, server }) => {
|
|
||||||
const traceViewer = await runAndTrace(async () => {
|
|
||||||
await page.goto(server.PREFIX + '/one-style.html');
|
|
||||||
await page.waitForTimeout(1000); // ensure we could take a screenshot
|
|
||||||
});
|
|
||||||
|
|
||||||
const screenshot = traceViewer.page.getByAltText(`Screenshot of page.goto`);
|
|
||||||
const snapshot = (await traceViewer.snapshotFrame('page.goto')).owner();
|
|
||||||
await expect(snapshot).toBeVisible();
|
|
||||||
await expect(screenshot).not.toBeVisible();
|
|
||||||
|
|
||||||
await traceViewer.page.getByTitle('Settings').click();
|
|
||||||
await traceViewer.page.getByText('Show screenshot instead of snapshot').setChecked(true);
|
|
||||||
|
|
||||||
await expect(snapshot).not.toBeVisible();
|
|
||||||
await expect(screenshot).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test.skip('should handle case where neither snapshots nor screenshots exist', async ({ runAndTrace, page, server }) => {
|
|
||||||
const traceViewer = await runAndTrace(async () => {
|
|
||||||
await page.goto(server.PREFIX + '/one-style.html');
|
|
||||||
}, { snapshots: false, screenshots: false });
|
|
||||||
|
|
||||||
await traceViewer.page.getByTitle('Settings').click();
|
|
||||||
await traceViewer.page.getByText('Show screenshot instead of snapshot').setChecked(true);
|
|
||||||
|
|
||||||
const screenshot = traceViewer.page.getByAltText(`Screenshot of page.goto > Action`);
|
|
||||||
await expect(screenshot).not.toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should show only one pointer with multilevel iframes', async ({ page, runAndTrace, server, browserName }) => {
|
test('should show only one pointer with multilevel iframes', async ({ page, runAndTrace, server, browserName }) => {
|
||||||
test.fixme(browserName === 'firefox', 'Elements in iframe are not marked');
|
test.fixme(browserName === 'firefox', 'Elements in iframe are not marked');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue