Skip to content

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

chore(ui): Speedboard UI improvements (#38194)

Simon Knott3af9725200cd
diff --git a/packages/html-reporter/src/chip.css b/packages/html-reporter/src/chip.css
index b061b1c8cc..1960b7d02c 100644
--- a/packages/html-reporter/src/chip.css
+++ b/packages/html-reporter/src/chip.css
@@ -58,7 +58,6 @@
.chip-footer {
border-top: 1px solid var(--color-border-default);
- padding: 8px;
}
@media only screen and (max-width: 600px) {
diff --git a/packages/html-reporter/src/chip.tsx b/packages/html-reporter/src/chip.tsx
index df79a7181a..93e79abd4b 100644
--- a/packages/html-reporter/src/chip.tsx
+++ b/packages/html-reporter/src/chip.tsx
@@ -40,8 +40,7 @@ export const Chip: React.FC<{
className={clsx('chip-header', setExpanded && ' expanded-' + expanded)}
onClick={() => setExpanded?.(!expanded)}
title={typeof header === 'string' ? header : undefined}>
- {setExpanded && !!expanded && icons.downArrow()}
- {setExpanded && !expanded && icons.rightArrow()}
+ {setExpanded ? (expanded ? <icons.downArrow /> : <icons.rightArrow />) : <icons.spacer />}
{header}
</div>
{(!setExpanded || expanded) && <div id={id} role='region' className={clsx('chip-body', noInsets && 'chip-body-no-insets')}>
diff --git a/packages/html-reporter/src/common.css b/packages/html-reporter/src/common.css
index 2cdb41bd3d..c67df07e6a 100644
--- a/packages/html-reporter/src/common.css
+++ b/packages/html-reporter/src/common.css
@@ -215,6 +215,10 @@ article, aside, details, figcaption, figure, footer, header, main, menu, nav, se
background-color: var(--color-canvas-subtle);
}
+.subnav-item[aria-selected="true"] {
+ background: var(--color-control-transparent-bg-hover);
+}
+
.subnav-item:first-child {
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
diff --git a/packages/html-reporter/src/filter.ts b/packages/html-reporter/src/filter.ts
index c08350feba..36da555464 100644
--- a/packages/html-reporter/src/filter.ts
+++ b/packages/html-reporter/src/filter.ts
@@ -214,13 +214,16 @@ function cacheSearchValues(test: TestCaseSummary & { [searchValuesSymbol]?: Sear
const SEARCH_PARAM_GROUP_REGEX = /("[^"]*"|"[^"]*$|\S+)/g;
export function filterWithQuery(searchParams: URLSearchParams, token: string, append: boolean): string {
+ const result = new URLSearchParams(searchParams);
const existingQuery = searchParams.get('q') ?? '';
const tokens = [...existingQuery.matchAll(SEARCH_PARAM_GROUP_REGEX)].map(m => {
const rawValue = m[0];
return rawValue.startsWith('"') && rawValue.endsWith('"') && rawValue.length > 1 ? rawValue.slice(1, rawValue.length - 1) : rawValue;
});
- if (append)
- return '#?q=' + joinTokens(!tokens.includes(token) ? [...tokens, token] : tokens.filter(t => t !== token));
+ if (append) {
+ result.set('q', joinTokens(!tokens.includes(token) ? [...tokens, token] : tokens.filter(t => t !== token)));
+ return '#?' + result;
+ }
// if metaKey or ctrlKey is not pressed, replace existing token with new token
let prefix: 's:' | 'p:' | '@';
@@ -233,7 +236,9 @@ export function filterWithQuery(searchParams: URLSearchParams, token: string, ap
const newTokens = tokens.filter(t => !t.startsWith(prefix));
newTokens.push(token);
- return '#?q=' + joinTokens(newTokens);
+
+ result.set('q', joinTokens(newTokens));
+ return '#?' + result;
}
function joinTokens(tokens: string[]): string {
diff --git a/packages/html-reporter/src/headerView.tsx b/packages/html-reporter/src/headerView.tsx
index d8c5f7165d..dacfd19b87 100644
--- a/packages/html-reporter/src/headerView.tsx
+++ b/packages/html-reporter/src/headerView.tsx
@@ -89,6 +89,8 @@ export const GlobalFilterView: React.FC<{
const StatsNavView: React.FC<{
stats: Stats
}> = ({ stats }) => {
+ const searchParams = React.useContext(SearchParamsContext);
+
return <nav>
<Link className='subnav-item' href='#?'>
<span className='subnav-item-label'>All</span>
@@ -98,7 +100,7 @@ const StatsNavView: React.FC<{
<NavLink token='failed' count={stats.unexpected} />
<NavLink token='flaky' count={stats.flaky} />
<NavLink token='skipped' count={stats.skipped} />
- <Link className='subnav-item' href='#?speedboard' title='Speedboard'>
+ <Link className='subnav-item' href='#?speedboard' title='Speedboard' aria-selected={searchParams.has('speedboard')}>
{icons.clock()}
</Link>
<SettingsButton />
@@ -109,7 +111,10 @@ const NavLink: React.FC<{
token: string,
count: number,
}> = ({ token, count }) => {
- const searchParams = React.useContext(SearchParamsContext);
+ const searchParams = new URLSearchParams(React.useContext(SearchParamsContext));
+ searchParams.delete('speedboard');
+ searchParams.delete('testId');
+
const queryToken = `s:${token}`;
const clickUrl = filterWithQuery(searchParams, queryToken, false);
diff --git a/packages/html-reporter/src/icons.tsx b/packages/html-reporter/src/icons.tsx
index ab3aaa3b3d..9c5292168e 100644
--- a/packages/html-reporter/src/icons.tsx
+++ b/packages/html-reporter/src/icons.tsx
@@ -17,6 +17,10 @@
import './colors.css';
import './common.css';
+export const spacer = () => {
+ return <span className='octicon' style={{ width: 16, height: 16 }} />;
+};
+
export const search = () => {
return <svg aria-hidden='true' height='16' viewBox='0 0 16 16' version='1.1' width='16' data-view-component='true' className='octicon subnav-search-icon'>
<path fillRule='evenodd' d='M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z'></path>
diff --git a/packages/html-reporter/src/labels.tsx b/packages/html-reporter/src/labels.tsx
index eb8d593ff9..cb356ac26f 100644
--- a/packages/html-reporter/src/labels.tsx
+++ b/packages/html-reporter/src/labels.tsx
@@ -41,15 +41,14 @@ export const ProjectAndTagLabelsView: React.FC<{
projectNames: string[],
activeProjectName: string,
otherLabels: string[],
- useLinks?: boolean,
style?: React.CSSProperties,
-}> = ({ projectNames, activeProjectName, otherLabels, useLinks, style }) => {
+}> = ({ projectNames, activeProjectName, otherLabels, style }) => {
// We can have an empty project name if we have no projects specified in the config
const hasProjectNames = projectNames.length > 0 && !!activeProjectName;
return (hasProjectNames || otherLabels.length > 0) && <span className='label-row' style={style ?? {}}>
<ProjectLink projectNames={projectNames} projectName={activeProjectName} />
- {!!useLinks ? <LabelsLinkView labels={otherLabels} /> : <LabelsClickView labels={otherLabels} />}
+ <LabelsClickView labels={otherLabels} />
</span>;
};
@@ -60,6 +59,9 @@ const LabelsClickView: React.FC<{
const onClickHandle = React.useCallback((e: React.MouseEvent, label: string) => {
e.preventDefault();
+ if (searchParams.has('testId'))
+ searchParams.delete('speedboard');
+ searchParams.delete('testId');
navigate(filterWithQuery(searchParams, label, e.metaKey || e.ctrlKey));
}, [searchParams]);
@@ -67,9 +69,3 @@ const LabelsClickView: React.FC<{
{labels.map(label => <Label key={label} label={label} trimAtSymbolPrefix={true} onClick={onClickHandle} />)}
</>;
};
-
-const LabelsLinkView: React.FC<{
- labels: string[],
-}> = ({ labels }) => <>
- {labels.map((label, index) => <Label key={index} label={label} trimAtSymbolPrefix={true} href={`#?q=${label}`} />)}
-</>;
diff --git a/packages/html-reporter/src/links.css b/packages/html-reporter/src/links.css
index 4735e23da0..74bb25d9bb 100644
--- a/packages/html-reporter/src/links.css
+++ b/packages/html-reporter/src/links.css
@@ -57,6 +57,15 @@
fill: var(--color-fg-muted);
}
+.fullwidth-link {
+ width: 100%;
+ text-align: left;
+}
+
+.fullwidth-link:hover {
+ background-color: var(--color-canvas-subtle);
+}
+
.trace-link {
/* Trace link button has 1px border and 4px padding, so we need 3px right margin to match content on the other side of divider */
margin-right: 3px;
diff --git a/packages/html-reporter/src/links.tsx b/packages/html-reporter/src/links.tsx
index 26f895ba0c..555f935ec6 100644
--- a/packages/html-reporter/src/links.tsx
+++ b/packages/html-reporter/src/links.tsx
@@ -65,6 +65,9 @@ export const ProjectLink: React.FunctionComponent<{
projectName: string,
}> = ({ projectNames, projectName }) => {
const searchParams = React.useContext(SearchParamsContext);
+ if (searchParams.has('testId'))
+ searchParams.delete('speedboard');
+ searchParams.delete('testId');
return <Link click={filterWithQuery(searchParams, `p:${projectName}`, false)} ctrlClick={filterWithQuery(searchParams, `p:${projectName}`, true)}>
<Label label={projectName} colorIndex={projectNames.indexOf(projectName) % 6} />
</Link>;
@@ -214,8 +217,8 @@ export function Anchor({ id, children }: React.PropsWithChildren<{ id: AnchorID
return <div ref={ref}>{children}</div>;
}
-export function testResultHref({ test, result, anchor }: { test?: TestCase | TestCaseSummary, result?: TestResult | TestResultSummary, anchor?: string }) {
- const params = new URLSearchParams();
+export function testResultHref({ test, result, anchor }: { test?: TestCase | TestCaseSummary, result?: TestResult | TestResultSummary, anchor?: string }, searchParams: URLSearchParams) {
+ const params = new URLSearchParams(searchParams);
if (test)
params.set('testId', test.testId);
if (test && result)
diff --git a/packages/html-reporter/src/reportView.tsx b/packages/html-reporter/src/reportView.tsx
index 0b01a5446e..615b182729 100644
--- a/packages/html-reporter/src/reportView.tsx
+++ b/packages/html-reporter/src/reportView.tsx
@@ -38,7 +38,7 @@ declare global {
// These are extracted to preserve the function identity between renders to avoid re-triggering effects.
const testFilesRoutePredicate = (params: URLSearchParams) => !params.has('testId') && !params.has('speedboard');
const testCaseRoutePredicate = (params: URLSearchParams) => params.has('testId');
-const speedboardRoutePredicate = (params: URLSearchParams) => params.has('speedboard');
+const speedboardRoutePredicate = (params: URLSearchParams) => params.has('speedboard') && !params.has('testId');
type TestModelSummary = {
files: TestFileSummary[];
@@ -52,6 +52,7 @@ export const ReportView: React.FC<{
const [expandedFiles, setExpandedFiles] = React.useState<Map<string, boolean>>(new Map());
const [filterText, setFilterText] = React.useState(searchParams.get('q') || '');
const [metadataVisible, setMetadataVisible] = React.useState(false);
+ const speedboard = searchParams.has('speedboard');
const [mergeFiles] = useSetting('mergeFiles', false);
const testId = searchParams.get('testId');
const q = searchParams.get('q')?.toString() || '';
@@ -70,8 +71,12 @@ export const ReportView: React.FC<{
const filter = React.useMemo(() => Filter.parse(filterText), [filterText]);
const filteredStats = React.useMemo(() => filter.empty() ? undefined : computeStats(report?.json().files || [], filter), [report, filter]);
const testModel = React.useMemo(() => {
- return mergeFiles ? createMergedFilesModel(report, filter) : createFilesModel(report, filter);
- }, [report, filter, mergeFiles]);
+ if (speedboard)
+ return createSpeedboardFilesModel(report, filter);
+ if (mergeFiles)
+ return createMergedFilesModel(report, filter);
+ return createFilesModel(report, filter);
+ }, [report, filter, mergeFiles, speedboard]);
const { prev, next } = React.useMemo(() => {
const index = testModel.tests.findIndex(t => t.testId === testId);
@@ -92,22 +97,28 @@ export const ReportView: React.FC<{
break;
case 'p':
event.preventDefault();
+ searchParams.delete('testId');
+ searchParams.delete('speedboard');
navigate(filterWithQuery(searchParams, 's:passed', false));
break;
case 'f':
event.preventDefault();
+ searchParams.delete('testId');
+ searchParams.delete('speedboard');
navigate(filterWithQuery(searchParams, 's:failed', false));
break;
case 'ArrowLeft':
if (prev) {
event.preventDefault();
- navigate(testResultHref({ test: prev }) + filterParam);
+ searchParams.delete('testId');
+ navigate(testResultHref({ test: prev }, searchParams) + filterParam);
}
break;
case 'ArrowRight':
if (next) {
event.preventDefault();
- navigate(testResultHref({ test: next }) + filterParam);
+ searchParams.delete('testId');
+ navigate(testResultHref({ test: next }, searchParams) + filterParam);
}
break;
}
@@ -138,7 +149,7 @@ export const ReportView: React.FC<{
</Route>
<Route predicate={speedboardRoutePredicate}>
<TestFilesHeader report={report?.json()} filteredStats={filteredStats} metadataVisible={metadataVisible} toggleMetadataVisible={() => setMetadataVisible(visible => !visible)}/>
- {report && <Speedboard filter={filter} report={report} />}
+ {report && <Speedboard report={report} tests={testModel.tests} />}
</Route>
<Route predicate={testCaseRoutePredicate}>
{report && <TestCaseViewLoader report={report} next={next} prev={prev} testId={testId} testIdToFileIdMap={testIdToFileIdMap} />}
@@ -252,3 +263,13 @@ function createMergedFilesModel(report: LoadedReport | undefined, filter: Filter
result.tests.push(...group.tests);
return result;
}
+
+function createSpeedboardFilesModel(report: LoadedReport | undefined, filter: Filter): TestModelSummary {
+ const files = report?.json().files || [];
+ const tests = files.flatMap(file => file.tests).filter(t => filter.matches(t));
+ tests.sort((a, b) => b.duration - a.duration);
+ return {
+ files: [],
+ tests,
+ };
+}
diff --git a/packages/html-reporter/src/speedboard.tsx b/packages/html-reporter/src/speedboard.tsx
index 9e2afc9955..b0beb0267a 100644
--- a/packages/html-reporter/src/speedboard.tsx
+++ b/packages/html-reporter/src/speedboard.tsx
@@ -15,36 +15,32 @@
*/
import React from 'react';
-import { Filter } from './filter';
import { LoadedReport } from './loadedReport';
import { TestFileView } from './testFileView';
import * as icons from './icons';
+import { TestCaseSummary } from './types';
-export function Speedboard({ filter, report }: { filter: Filter, report: LoadedReport}) {
+export function Speedboard({ report, tests }: { report: LoadedReport, tests: TestCaseSummary[] }) {
return <>
- <SlowestTests filter={filter} report={report} />
+ <SlowestTests report={report} tests={tests} />
</>;
}
-export function SlowestTests({ filter, report }: { filter: Filter, report: LoadedReport}) {
- const [length, setLength] = React.useState(10);
- const slowestTests = React.useMemo(() => {
- const tests = report.json().files.flatMap(file => file.tests).filter(t => filter.matches(t));
- return tests.sort((a, b) => b.duration - a.duration);
- }, [report, filter]);
+export function SlowestTests({ report, tests }: { report: LoadedReport, tests: TestCaseSummary[] }) {
+ const [length, setLength] = React.useState(50);
return <TestFileView
file={{
fileId: 'slowest',
fileName: 'Slowest Tests',
- tests: slowestTests.slice(0, length),
+ tests: tests.slice(0, length),
stats: null as any,
}}
projectNames={report.json().projectNames}
footer={
- length < slowestTests.length
- ? <button className='link-badge' onClick={() => setLength(l => l + 10)}>
+ length < tests.length
+ ? <button className='link-badge fullwidth-link' style={{ padding: '8px 5px' }} onClick={() => setLength(l => l + 50)}>
{icons.downArrow()}
- Show more
+ Show 50 more
</button>
: undefined
}
diff --git a/packages/html-reporter/src/testCaseView.tsx b/packages/html-reporter/src/testCaseView.tsx
index 22e5c146f8..044820029a 100644
--- a/packages/html-reporter/src/testCaseView.tsx
+++ b/packages/html-reporter/src/testCaseView.tsx
@@ -44,7 +44,6 @@ export const TestCaseView: React.FC<{
const [selectedResultIndex, setSelectedResultIndex] = React.useState(run);
const searchParams = React.useContext(SearchParamsContext);
- const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : '';
const visibleTestAnnotations = test.annotations.filter(a => !a.type.startsWith('_')) ?? [];
return <>
@@ -52,9 +51,9 @@ export const TestCaseView: React.FC<{
title={test.title}
leftSuperHeader={<div className='test-case-path'>{test.path.join(' › ')}</div>}
rightSuperHeader={<>
- <div className={clsx(!prev && 'hidden')}><Link href={testResultHref({ test: prev }) + filterParam}>« previous</Link></div>
+ <div className={clsx(!prev && 'hidden')}><Link href={testResultHref({ test: prev }, searchParams)}>« previous</Link></div>
<div style={{ width: 10 }}></div>
- <div className={clsx(!next && 'hidden')}><Link href={testResultHref({ test: next }) + filterParam}>next »</Link></div>
+ <div className={clsx(!next && 'hidden')}><Link href={testResultHref({ test: next }, searchParams)}>next »</Link></div>
</>}
/>
<div className='hbox' style={{ lineHeight: '24px' }}>
diff --git a/packages/html-reporter/src/testFileView.tsx b/packages/html-reporter/src/testFileView.tsx
index 8a4dc31796..7d38f49c1e 100644
--- a/packages/html-reporter/src/testFileView.tsx
+++ b/packages/html-reporter/src/testFileView.tsx
@@ -33,7 +33,6 @@ export const TestFileView: React.FC<React.PropsWithChildren<{
footer?: React.JSX.Element | string;
}>> = ({ file, projectNames, isFileExpanded, setFileExpanded, footer }) => {
const searchParams = React.useContext(SearchParamsContext);
- const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : '';
return <Chip
expanded={isFileExpanded ? isFileExpanded(file.fileId) : undefined}
noInsets={true}
@@ -51,7 +50,7 @@ export const TestFileView: React.FC<React.PropsWithChildren<{
{statusIcon(test.outcome)}
</span>
<span>
- <Link href={testResultHref({ test }) + filterParam} title={[...test.path, test.title].join(' › ')}>
+ <Link href={testResultHref({ test }, searchParams)} title={[...test.path, test.title].join(' › ')}>
<span className='test-file-title'>{[...test.path, test.title].join(' › ')}</span>
</Link>
<ProjectAndTagLabelsView style={{ marginLeft: '6px' }} projectNames={projectNames} activeProjectName={test.projectName} otherLabels={test.tags} />
@@ -61,11 +60,11 @@ export const TestFileView: React.FC<React.PropsWithChildren<{
</div>
<div className='test-file-details-row'>
<div className='test-file-details-row-items'>
- <Link href={testResultHref({ test })} title={[...test.path, test.title].join(' › ')} className='test-file-path-link'>
+ <Link href={testResultHref({ test }, searchParams)} title={[...test.path, test.title].join(' › ')} className='test-file-path-link'>
<span className='test-file-path'>{test.location.file}:{test.location.line}</span>
</Link>
- {imageDiffBadge(test)}
- {videoBadge(test)}
+ <ImageDiffBadge test={test} />
+ <VideoBadge test={test} />
<TraceLink test={test} dim={true} />
</div>
</div>
@@ -74,16 +73,18 @@ export const TestFileView: React.FC<React.PropsWithChildren<{
</Chip>;
};
-function imageDiffBadge(test: TestCaseSummary): React.JSX.Element | undefined {
+function ImageDiffBadge({ test }: { test: TestCaseSummary }) {
+ const searchParams = React.useContext(SearchParamsContext);
for (const result of test.results) {
for (const attachment of result.attachments) {
if (attachment.contentType.startsWith('image/') && !!attachment.name.match(/-(expected|actual|diff)/))
- return <LinkBadge href={testResultHref({ test, result, anchor: `attachment-${result.attachments.indexOf(attachment)}` })} title='View images' dim={true}>{image()}</LinkBadge>;
+ return <LinkBadge href={testResultHref({ test, result, anchor: `attachment-${result.attachments.indexOf(attachment)}` }, searchParams)} title='View images' dim={true}>{image()}</LinkBadge>;
}
}
}
-function videoBadge(test: TestCaseSummary): React.JSX.Element | undefined {
+function VideoBadge({ test }: { test: TestCaseSummary }) {
+ const searchParams = React.useContext(SearchParamsContext);
const resultWithVideo = test.results.find(result => result.attachments.some(attachment => attachment.name === 'video'));
- return resultWithVideo ? <LinkBadge href={testResultHref({ test, result: resultWithVideo, anchor: 'attachment-video' })} title='View video' dim={true}>{video()}</LinkBadge> : undefined;
+ return resultWithVideo ? <LinkBadge href={testResultHref({ test, result: resultWithVideo, anchor: 'attachment-video' }, searchParams)} title='View video' dim={true}>{video()}</LinkBadge> : undefined;
}
diff --git a/packages/html-reporter/src/testResultView.tsx b/packages/html-reporter/src/testResultView.tsx
index 005b7d8f7c..456fff3f61 100644
--- a/packages/html-reporter/src/testResultView.tsx
+++ b/packages/html-reporter/src/testResultView.tsx
@@ -20,7 +20,7 @@ import { TreeItem } from './treeItem';
import { formatUrl, msToString } from './utils';
import { AutoChip } from './chip';
import { traceImage } from './images';
-import { Anchor, AttachmentLink, generateTraceUrl, testResultHref } from './links';
+import { Anchor, AttachmentLink, generateTraceUrl, SearchParamsContext, testResultHref } from './links';
import { statusIcon } from './statusIcon';
import type { ImageDiff } from '@web/shared/imageDiffView';
import { ImageDiffView } from '@web/shared/imageDiffView';
@@ -193,12 +193,13 @@ const StepTreeItem: React.FC<{
step: TestStep;
depth: number,
}> = ({ test, step, result, depth }) => {
+ const searchParams = React.useContext(SearchParamsContext);
return <TreeItem title={<span aria-label={step.title}>
<span style={{ float: 'right' }}>{msToString(step.duration)}</span>
{step.attachments.length > 0 && <a
style={{ float: 'right' }}
title={`reveal attachment`}
- href={formatUrl(testResultHref({ test, result, anchor: `attachment-${step.attachments[0]}` }))}
+ href={formatUrl(testResultHref({ test, result, anchor: `attachment-${step.attachments[0]}` }, searchParams))}
onClick={evt => { evt.stopPropagation(); }}>
{icons.attachment()}
</a>}
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 18492a4d52..fb5dbea4f8 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -2007,21 +2007,21 @@ for (const useIntermediateMergeReport of [true, false] as const) {
const smokeLabelButton = page.locator('.test-file-test', { has: page.getByText('@smoke fails', { exact: true }) }).locator('.label', { hasText: 'smoke' });
await smokeLabelButton.click();
- await expect(page).toHaveURL(/@smoke/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@smoke');
await expect(searchInput).toHaveValue('@smoke ');
await searchInput.clear();
await page.keyboard.press('Enter');
await expect(searchInput).toHaveValue('');
- await expect(page).not.toHaveURL(/@smoke/);
+ await expect(page).not.toHaveURL(url => getFilter(url) === '@smoke');
const regressionLabelButton = page.locator('.test-file-test', { has: page.getByText('@regression passes', { exact: true }) }).locator('.label', { hasText: 'regression' });
await regressionLabelButton.click();
- await expect(page).toHaveURL(/@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@regression');
await expect(searchInput).toHaveValue('@regression ');
await searchInput.clear();
await page.keyboard.press('Enter');
await expect(searchInput).toHaveValue('');
- await expect(page).not.toHaveURL(/@regression/);
+ await expect(page).not.toHaveURL(url => getFilter(url) === '@regression');
});
test('filter should update stats', async ({ runInlineTest, showReport, page }) => {
@@ -2146,7 +2146,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
await expect(page.locator('.test-file-test .test-file-title')).toHaveText('@smoke fails');
await expect(searchInput).toHaveValue('s:failed @smoke ');
- await expect(page).toHaveURL(/s:failed%20@smoke/);
+ await expect(page).toHaveURL(url => getFilter(url) === 's:failed @smoke');
await passedNavMenu.click();
await smokeLabelButton.click({ modifiers: [process.platform === 'darwin' ? 'Meta' : 'Control'] });
@@ -2156,7 +2156,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
await expect(page.locator('.test-file-test .test-file-title')).toHaveText('@regression passes');
await expect(searchInput).toHaveValue('s:passed @regression ');
- await expect(page).toHaveURL(/s:passed%20@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === 's:passed @regression');
await allNavMenu.click();
await regressionLabelButton.click();
@@ -2165,7 +2165,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
await expect(page.locator('.test-file-test .test-file-title')).toHaveCount(2);
await expect(searchInput).toHaveValue('@regression ');
- await expect(page).toHaveURL(/@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@regression');
});
test('tests should be filtered by label input in search field', async ({ runInlineTest, showReport, page }) => {
@@ -2348,7 +2348,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await smokeButton.click();
await expect(searchInput).toHaveValue('@smoke ');
- await expect(page).toHaveURL(/@smoke/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@smoke');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
@@ -2357,7 +2357,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await regressionButton.click();
await expect(searchInput).toHaveValue('@smoke @regression ');
- await expect(page).toHaveURL(/@smoke%20@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@smoke @regression');
await expect(page.locator('.chip')).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
@@ -2366,7 +2366,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await smokeButton.click();
await expect(searchInput).toHaveValue('@regression ');
- await expect(page).toHaveURL(/@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@regression');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
@@ -2375,7 +2375,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await flakyButton.click();
await expect(searchInput).toHaveValue('@regression @flaky ');
- await expect(page).toHaveURL(/@regression%20@flaky/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@regression @flaky');
await expect(page.locator('.chip')).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(0);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
@@ -2384,7 +2384,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await regressionButton.click();
await expect(searchInput).toHaveValue('@flaky ');
- await expect(page).toHaveURL(/@flaky/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@flaky');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(0);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
@@ -2393,7 +2393,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await flakyButton.click();
await expect(searchInput).toHaveValue('');
- await expect(page).not.toHaveURL(/@/);
+ await expect(page).not.toHaveURL(url => getFilter(url).includes('@'));
await expect(page.locator('.chip')).toHaveCount(3);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
@@ -2403,7 +2403,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await smokeButton.click();
await expect(searchInput).toHaveValue('@smoke ');
- await expect(page).toHaveURL(/@smoke/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@smoke');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
@@ -2412,7 +2412,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await regressionButton.click();
await expect(searchInput).toHaveValue('@regression ');
- await expect(page).toHaveURL(/@regression/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@regression');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(1);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
@@ -2421,7 +2421,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await flakyButton.click();
await expect(searchInput).toHaveValue('@flaky ');
- await expect(page).toHaveURL(/@flaky/);
+ await expect(page).toHaveURL(url => getFilter(url) === '@flaky');
await expect(page.locator('.chip')).toHaveCount(2);
await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(0);
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1);
@@ -3207,6 +3207,105 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await page.keyboard.up('Alt');
});
});
+
+ test.describe('speedboard', () => {
+ test('clicking on label should not exit speedboard', async ({ runInlineTest, showReport, page }) => {
+ await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = {
+ projects: [{ name: 'foo' }, { name: 'bar' }],
+ };
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+ import timers from 'timers/promises';
+ test.beforeEach(async () => {
+ if (test.info().project.name === 'foo')
+ await timers.setTimeout(500);
+ });
+ test('one', async () => {
+ await timers.setTimeout(100);
+ });
+ test('two', async () => {
+ await timers.setTimeout(200);
+ });
+ test('three', async () => {
+ await timers.setTimeout(300);
+ });
+ `,
+ }, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
+ await showReport();
+
+ await expect(page.getByRole('link', { name: 'Speedboard' })).toHaveAttribute('aria-selected', 'false');
+ await page.getByRole('link', { name: 'Speedboard' }).click();
+ await expect(page.getByRole('link', { name: 'Speedboard' })).toHaveAttribute('aria-selected', 'true');
+
+ await expect(page.getByRole('main')).toMatchAriaSnapshot(`
+ - button "Slowest Tests"
+ - region:
+ - link "three"
+ - text: /foo/
+ - link "two"
+ - text: /foo/
+ - link "one"
+ - text: /foo/
+ - link "three"
+ - text: /bar/
+ - link "two"
+ - text: /bar/
+ - link "one"
+ - text: /bar/
+ `);
+ await page.getByText('foo').first().click();
+ await expect(page.getByRole('main')).toMatchAriaSnapshot(`
+ - button "Slowest Tests"
+ `);
+
+ await page.getByRole('link', { name: 'Failed' }).click();
+ await expect(page.getByRole('main')).toContainText('No tests found');
+ });
+
+ test('next/prev buttons should follow speed', async ({ runInlineTest, showReport, page }) => {
+ await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = {};
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+ import timers from 'timers/promises';
+ test('one', async () => {
+ await timers.setTimeout(100);
+ });
+ test('two', async () => {
+ await timers.setTimeout(200);
+ });
+ test('three', async () => {
+ await timers.setTimeout(300);
+ });
+ `,
+ }, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
+ await showReport();
+ await page.getByRole('link', { name: 'Speedboard' }).click();
+ await page.getByRole('link', { name: 'three' }).click();
+ await expect(page.getByRole('link', { name: 'Speedboard' })).toHaveAttribute('aria-selected', 'true');
+ await expect(page.getByRole('link', { name: 'previous' })).not.toBeVisible();
+
+ await page.getByRole('link', { name: 'next' }).click();
+ await expect(page.getByText('two')).toBeVisible();
+ await expect(page.getByRole('link', { name: 'Speedboard' })).toHaveAttribute('aria-selected', 'true');
+
+ await page.getByRole('link', { name: 'next' }).click();
+ await expect(page.getByText('one')).toBeVisible();
+ await expect(page.getByRole('link', { name: 'next' })).not.toBeVisible();
+
+ await page.getByRole('link', { name: 'previous' }).click();
+ await expect(page.getByText('two')).toBeVisible();
+
+ await page.getByRole('link', { name: 'previous' }).click();
+ await expect(page.getByText('three')).toBeVisible();
+ await expect(page.getByRole('link', { name: 'previous' })).not.toBeVisible();
+ });
+ });
});
}
@@ -3296,3 +3395,7 @@ async function ghaPullRequestEnv(baseDir: string) {
GITHUB_EVENT_PATH: eventPath,
};
}
+
+function getFilter(url: URL): string {
+ return new URLSearchParams(url.hash.slice(1)).get('q');
+}