Skip to content

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

fix(html): truncate step titles (#38884)

Simon Knott428b5576d191
diff --git a/packages/html-reporter/src/testResultView.css b/packages/html-reporter/src/testResultView.css
index 7291d2a1c5..3dbfb1da4a 100644
--- a/packages/html-reporter/src/testResultView.css
+++ b/packages/html-reporter/src/testResultView.css
@@ -43,6 +43,51 @@
border-radius: 12px;
color: var(--color-canvas-default);
padding: 2px 8px;
+ line-height: normal;
+}
+
+.step-title-container {
+ display: flex;
+ align-items: center;
+ flex: auto;
+ min-width: 0;
+}
+
+.step-title-container > * {
+ flex-shrink: 0;
+}
+
+.step-title-text {
+ flex-shrink: 1;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ white-space: nowrap;
+ min-width: 0;
+}
+
+.step-spacer {
+ flex: auto;
+}
+
+.step-attachment-link {
+ display: flex;
+ flex: none;
+ border-radius: 4px;
+ padding: 4px;
+}
+
+.step-attachment-link:hover {
+ background-color: var(--color-neutral-muted);
+}
+
+.step-attachment-link .octicon {
+ margin-right: 0;
+}
+
+.step-duration {
+ flex: none;
+ white-space: nowrap;
+ margin-left: 4px;
}
:root.light-mode {
diff --git a/packages/html-reporter/src/testResultView.tsx b/packages/html-reporter/src/testResultView.tsx
index d611b144d7..08db1aad95 100644
--- a/packages/html-reporter/src/testResultView.tsx
+++ b/packages/html-reporter/src/testResultView.tsx
@@ -194,20 +194,23 @@ const StepTreeItem: React.FC<{
depth: number,
}> = ({ test, step, result, depth }) => {
const searchParams = useSearchParams();
- return <TreeItem title={<span aria-label={step.title}>
- <span style={{ float: 'right' }}>{msToString(step.duration)}</span>
+ return <TreeItem title={<div aria-label={step.title} className='step-title-container'>
+ {statusIcon(step.error || step.duration === -1 ? 'failed' : (step.skipped ? 'skipped' : 'passed'))}
+ <span className='step-title-text'>
+ <span>{step.title}</span>
+ {step.count > 1 && <> ✕ <span className='test-result-counter'>{step.count}</span></>}
+ {step.location && <span className='test-result-path'>— {step.location.file}:{step.location.line}</span>}
+ </span>
+ <span className='step-spacer'></span>
{step.attachments.length > 0 && <a
- style={{ float: 'right' }}
+ className='step-attachment-link'
title={`reveal attachment`}
href={formatUrl(testResultHref({ test, result, anchor: `attachment-${step.attachments[0]}` }, searchParams))}
onClick={evt => { evt.stopPropagation(); }}>
{icons.attachment()}
</a>}
- {statusIcon(step.error || step.duration === -1 ? 'failed' : (step.skipped ? 'skipped' : 'passed'))}
- <span>{step.title}</span>
- {step.count > 1 && <> ✕ <span className='test-result-counter'>{step.count}</span></>}
- {step.location && <span className='test-result-path'>— {step.location.file}:{step.location.line}</span>}
- </span>} loadChildren={step.steps.length || step.snippet ? () => {
+ <span className='step-duration'>{msToString(step.duration)}</span>
+ </div>} loadChildren={step.steps.length || step.snippet ? () => {
const snippet = step.snippet ? [<CodeSnippet testId='test-snippet' key='line' code={step.snippet} />] : [];
const steps = step.steps.map((s, i) => <StepTreeItem key={i} step={s} depth={depth + 1} result={result} test={test} />);
return snippet.concat(steps);
diff --git a/packages/html-reporter/src/treeItem.css b/packages/html-reporter/src/treeItem.css
index b957d1ec5c..b6ada77a4b 100644
--- a/packages/html-reporter/src/treeItem.css
+++ b/packages/html-reporter/src/treeItem.css
@@ -15,14 +15,20 @@
*/
.tree-item {
- text-overflow: ellipsis;
+ display: flex;
+ flex-direction: column;
overflow: hidden;
- white-space: nowrap;
+ min-width: 0;
line-height: 38px;
}
.tree-item-title {
cursor: pointer;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ min-width: 0;
+ display: flex;
+ align-items: center;
}
.tree-item-body {
diff --git a/packages/html-reporter/src/treeItem.tsx b/packages/html-reporter/src/treeItem.tsx
index 389e558650..3e06d7087a 100644
--- a/packages/html-reporter/src/treeItem.tsx
+++ b/packages/html-reporter/src/treeItem.tsx
@@ -30,12 +30,12 @@ export const TreeItem: React.FunctionComponent<{
}> = ({ title, loadChildren, onClick, expandByDefault, depth, style, flash }) => {
const [expanded, setExpanded] = React.useState(expandByDefault || false);
return <div role='treeitem' className={clsx('tree-item', flash && 'yellow-flash')} style={style}>
- <span className='tree-item-title' style={{ whiteSpace: 'nowrap', paddingLeft: depth * 22 + 4 }} onClick={() => { onClick?.(); setExpanded(!expanded); }} >
+ <div className='tree-item-title' style={{ paddingLeft: depth * 22 + 4 }} onClick={() => { onClick?.(); setExpanded(!expanded); }} >
{loadChildren && !!expanded && icons.downArrow()}
{loadChildren && !expanded && icons.rightArrow()}
{!loadChildren && <span style={{ visibility: 'hidden' }}>{icons.rightArrow()}</span>}
{title}
- </span>
+ </div>
{expanded && loadChildren?.()}
</div>;
};