Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/html-reporter/src/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,22 @@ article, aside, details, figcaption, figure, footer, header, main, menu, nav, se
user-select: none;
}

button.subnav-item {
background: none;
font-family: inherit;
font-size: inherit;
cursor: pointer;
}

.subnav-item:hover {
background-color: var(--color-canvas-subtle);
}

.subnav-item:focus-visible {
outline: 1px solid var(--color-accent-fg);
outline-offset: -1px;
}

.subnav-item[aria-selected="true"] {
background: var(--color-control-transparent-bg-hover);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/html-reporter/src/headerView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ test('should render counters', async ({ mount }) => {
`);
});

test('should open settings with keyboard', async ({ mount }) => {
const component = await mount<typeof Default>('headerView/Default');
const settings = component.getByRole('button', { name: 'Settings' });
const dialog = component.getByTestId('settings-dialog');
await settings.focus();
await expect(settings).toBeFocused();
await expect(dialog).toBeHidden();
await settings.press('Enter');
await expect(dialog).toBeVisible();
await settings.press(' ');
await expect(dialog).toBeHidden();
});

test('should toggle filters', async ({ page, mount }) => {
const component = await mount<typeof Default>('headerView/Default');
const filterText = component.getByTestId('filter-text');
Expand Down
11 changes: 6 additions & 5 deletions packages/html-reporter/src/headerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,25 @@ const NavLink: React.FC<{
};

const SettingsButton: React.FC = () => {
const settingsRef = React.useRef<HTMLDivElement>(null);
const settingsRef = React.useRef<HTMLButtonElement>(null);
const [settingsOpen, setSettingsOpen] = React.useState(false);
const [theme, setTheme] = useThemeSetting();

return <>
<div
role='button'
<button
type='button'
ref={settingsRef}
style={{ cursor: 'pointer' }}
className='subnav-item'
title='Settings'
aria-haspopup='dialog'
aria-expanded={settingsOpen}
onClick={e => {
setSettingsOpen(!settingsOpen);
e.preventDefault();
}}
onMouseDown={preventDefault}>
{icons.settings()}
</div>
</button>

<Dialog
open={settingsOpen}
Expand Down
10 changes: 10 additions & 0 deletions packages/html-reporter/src/metadataView.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@
*/

.metadata-toggle {
all: unset;
box-sizing: border-box;
display: inline-flex;
align-items: center;
border-radius: 4px;
cursor: pointer;
user-select: none;
color: var(--color-fg-default);
}

.metadata-toggle:focus-visible {
outline: 1px solid var(--color-accent-fg);
outline-offset: 2px;
}

.metadata-toggle-second-line {
margin-top: 8px;
margin-left: 8px;
Expand Down
9 changes: 7 additions & 2 deletions packages/html-reporter/src/testFilesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ export const TestFilesHeader: React.FC<{
const isMetadataInTopLine = !showProject && !filteredStats;

const metadataToggleButton = !isMetadataEmpty(report.metadata) && (
<div className={clsx('metadata-toggle', !isMetadataInTopLine && 'metadata-toggle-second-line')} role='button' onClick={toggleMetadataVisible} title={metadataVisible ? 'Hide metadata' : 'Show metadata'}>
<button
type='button'
className={clsx('metadata-toggle', !isMetadataInTopLine && 'metadata-toggle-second-line')}
aria-expanded={metadataVisible}
onClick={toggleMetadataVisible}
title={metadataVisible ? 'Hide metadata' : 'Show metadata'}>
{metadataVisible ? icons.downArrow() : icons.rightArrow()}Metadata
</div>
</button>
);

const leftSuperHeader = <div className='test-file-header-info'>
Expand Down
16 changes: 16 additions & 0 deletions packages/trace-viewer/src/ui/actionList.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
}

.action-icons {
all: unset;
box-sizing: border-box;
flex: none;
display: flex;
flex-direction: row;
Expand All @@ -89,6 +91,11 @@
border-bottom: 1px solid var(--vscode-sideBarTitle-foreground);
}

.action-icons:focus-visible {
outline: 1px solid var(--vscode-focusBorder);
outline-offset: 1px;
}

.action-error {
color: var(--vscode-errorForeground);
position: relative;
Expand Down Expand Up @@ -118,10 +125,19 @@
}

.action-list-show-all {
all: unset;
box-sizing: border-box;
display: flex;
cursor: pointer;
height: 28px;
align-items: center;
align-self: flex-start;
border-radius: 4px;
}

.action-list-show-all:focus-visible {
outline: 1px solid var(--vscode-focusBorder);
outline-offset: -1px;
}

.action-list-container {
Expand Down
18 changes: 15 additions & 3 deletions packages/trace-viewer/src/ui/actionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ActionList: React.FC<ActionListProps> = ({
}, [setSelectedTime]);

return <div className='vbox action-list-container'>
{selectedTime && <div className='action-list-show-all' onClick={onShowAll}><span className='codicon codicon-triangle-left'></span>Show all</div>}
{selectedTime && <button type='button' className='action-list-show-all' onClick={onShowAll}><span className='codicon codicon-triangle-left'></span>Show all</button>}
<ActionTreeView
name='actions'
rootItem={rootItem}
Expand Down Expand Up @@ -145,6 +145,7 @@ export const renderAction = (
}) => {
const { model, sdkLanguage, revealConsole, revealActionAttachment, isLive, showDuration, showBadges, showAttachments } = options;
const { errors, warnings } = model?.stats(action) ?? { errors: 0, warnings: 0 };
const badgeLabel = [pluralize(errors, 'error'), pluralize(warnings, 'warning')].filter(Boolean).join(', ');

const locator = action.params.selector ? asLocatorDescription(sdkLanguage || 'javascript', action.params.selector) : undefined;

Expand All @@ -164,10 +165,15 @@ export const renderAction = (
{showAttachments && <ToolbarButton icon='attach' title='Open Attachment' onClick={() => revealActionAttachment?.()} />}
{showDuration && !isSkipped && <div className='action-duration'>{time || <span className='codicon codicon-loading'></span>}</div>}
{isSkipped && <span className={clsx('action-skipped', 'codicon', testStatusIcon('skipped'))} title='skipped'></span>}
{showBadges && <div className='action-icons' onClick={() => revealConsole?.()}>
{showBadges && !!badgeLabel && <button
type='button'
className='action-icons'
title='Reveal console'
aria-label={`Reveal console, ${badgeLabel}`}
onClick={() => revealConsole?.()}>
{!!errors && <div className='action-icon'><span className='codicon codicon-error'></span><span className='action-icon-value'>{errors}</span></div>}
{!!warnings && <div className='action-icon'><span className='codicon codicon-warning'></span><span className='action-icon-value'>{warnings}</span></div>}
</div>}
</button>}
</div>
{locator && <div className='action-title-selector' title={locator}>{locator}</div>}
</div>;
Expand Down Expand Up @@ -217,3 +223,9 @@ export function renderTitleForCall(action: ActionTraceEvent, sdkLanguage?: Langu
}
return { elements, title: title.join('') };
}

function pluralize(count: number, noun: string): string {
if (!count)
return '';
return `${count} ${noun}${count === 1 ? '' : 's'}`;
}
3 changes: 2 additions & 1 deletion packages/web/src/components/treeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export function TreeView<T extends TreeItem>({
role={treeItems.size > 0 ? 'tree' : undefined}
tabIndex={0}
onKeyDown={event => {
if (selectedItem && event.key === 'Enter') {
// Enter is handled by the focused button inside the row, if any.
if (selectedItem && event.key === 'Enter' && event.target === event.currentTarget) {
onAccepted?.(selectedItem);
return;
}
Expand Down
28 changes: 28 additions & 0 deletions tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ test('should keep selected action in view after Show all', async ({ runAndTrace,
await expect(selected).toBeInViewport();
});

test('should activate Show all with keyboard', async ({ runAndTrace, page }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42323' });
const traceViewer = await runAndTrace(async () => {
await page.setContent('<div>hello</div>');
await page.evaluate(x => x, 1);
});

await traceViewer.actionsTree.getByRole('treeitem').filter({ hasText: 'Evaluate' }).dblclick();

const showAll = traceViewer.page.getByRole('button', { name: 'Show all' });
await showAll.focus();
await expect(showAll).toBeFocused();
await showAll.press('Enter');
await expect(showAll).toBeHidden();
});

test('should open uncompressed trace directory', async ({ showTraceViewer }) => {
const traceDir = test.info().outputPath('unzipped-trace');
await extractZip(traceFile, { dir: traceDir });
Expand Down Expand Up @@ -397,6 +413,18 @@ test('should open console errors on click', async ({ showTraceViewer }) => {
await traceViewer.page.getByRole('tabpanel', { name: 'Console' }).waitFor();
});

test('should open console errors with keyboard', async ({ showTraceViewer }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42323' });
const traceViewer = await showTraceViewer(traceFile);
const badge = traceViewer.actionIcons('Evaluate');
await expect(badge).toHaveAccessibleName('Reveal console, 2 errors, 1 warning');
await badge.focus();
await expect(badge).toBeFocused();
await expect(traceViewer.page.getByRole('tabpanel', { name: 'Console' })).toBeHidden();
await badge.press('Enter');
await traceViewer.page.getByRole('tabpanel', { name: 'Console' }).waitFor();
});

test('should show params and return value', async ({ showTraceViewer }) => {
const traceViewer = await showTraceViewer(traceFile);
await traceViewer.selectAction('Evaluate');
Expand Down
35 changes: 35 additions & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,41 @@ for (const useIntermediateMergeReport of [true, false] as const) {
`);
});

test('should toggle metadata with keyboard', async ({ runInlineTest, writeFiles, showReport, page }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42323' });
const files = {
'playwright.config.ts': `
export default {
captureGitInfo: { commit: true },
};
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
test('sample', async ({}) => { expect(2).toBe(2); });
`,
};
const baseDir = await writeFiles(files);
await initGitRepo(baseDir);

const result = await runInlineTest(files, { reporter: 'dot,html' }, {
PLAYWRIGHT_HTML_OPEN: 'never',
});

await showReport();

expect(result.exitCode).toBe(0);
const toggle = page.getByRole('button', { name: 'Metadata' });
await toggle.focus();
await expect(toggle).toBeFocused();
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
await toggle.press('Enter');
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
await expect(page.locator('.metadata-view')).toBeVisible();
await toggle.press(' ');
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
await expect(page.locator('.metadata-view')).toBeHidden();
});

test('should not include git metadata w/o CI', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
'playwright.config.ts': `
Expand Down
Loading