From a08a41f6c996867f2d5652a08635cc4c13bd4f6f Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 7 Dec 2021 18:35:06 -0800 Subject: [PATCH] chore: render annotations in html report (#10774) --- .../src/web/htmlReport/htmlReport.css | 15 ++++++++++++-- .../src/web/htmlReport/htmlReport.tsx | 10 ++++++++-- .../playwright-test/src/reporters/html.ts | 3 +++ tests/playwright-test/reporter-html.spec.ts | 20 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/web/htmlReport/htmlReport.css b/packages/playwright-core/src/web/htmlReport/htmlReport.css index e733bdb696..27e9368120 100644 --- a/packages/playwright-core/src/web/htmlReport/htmlReport.css +++ b/packages/playwright-core/src/web/htmlReport/htmlReport.css @@ -121,7 +121,6 @@ svg { flex: auto; display: flex; flex-direction: column; - padding: 0 16px; margin-bottom: 20px; } @@ -197,6 +196,13 @@ svg { padding: 0 10px; } +.test-case-annotation { + flex: none; + align-items: center; + padding: 0 10px; + line-height: 24px; +} + .test-details-column { overflow-y: auto; } @@ -234,6 +240,7 @@ video, img { max-width: 1024px; margin: 0 auto; width: 100%; + padding: 0 16px; } .file-summary-list { @@ -385,7 +392,7 @@ a.no-decorations { border-radius: 2em; background-color: var(--color-scale-gray-4); color: white; - margin-left: 10px; + margin: 0 10px; flex: none; font-weight: 600; } @@ -573,6 +580,10 @@ article, aside, details, figcaption, figure, footer, header, main, menu, nav, se } @media only screen and (max-width: 600px) { + .flow-container { + padding: 0; + } + .chip-header { border-radius: 0 !important; border-right: none !important; diff --git a/packages/playwright-core/src/web/htmlReport/htmlReport.tsx b/packages/playwright-core/src/web/htmlReport/htmlReport.tsx index dcb6da6300..9d6449f2ae 100644 --- a/packages/playwright-core/src/web/htmlReport/htmlReport.tsx +++ b/packages/playwright-core/src/web/htmlReport/htmlReport.tsx @@ -152,13 +152,13 @@ const TestFileSummaryView: React.FC<{ {file.tests.filter(t => filter.matches(t)).map(test =>
{msToString(test.duration)} + {report.projectNames.length > 1 && !!test.projectName && + } {statusIcon(test.outcome)} {[...test.path, test.title].join(' › ')} — {test.location.file}:{test.location.line} - {report.projectNames.length > 1 && !!test.projectName && - }
)} ; @@ -196,6 +196,12 @@ const TestCaseView: React.FC<{ {test &&
{test?.title}
} {test &&
{test.location.file}:{test.location.line}
} {test && !!test.projectName && } + {test && !!test.annotations.length && + {test.annotations.map(a =>
+ {a.type} + {a.description && : {a.description}} +
)} +
} {test && ({ id: String(index), diff --git a/packages/playwright-test/src/reporters/html.ts b/packages/playwright-test/src/reporters/html.ts index 36b0f185d6..96814dd96c 100644 --- a/packages/playwright-test/src/reporters/html.ts +++ b/packages/playwright-test/src/reporters/html.ts @@ -68,6 +68,7 @@ export type TestCaseSummary = { path: string[]; projectName: string; location: Location; + annotations: { type: string, description?: string }[]; outcome: 'skipped' | 'expected' | 'unexpected' | 'flaky'; duration: number; ok: boolean; @@ -348,6 +349,7 @@ class HtmlBuilder { projectName, location, duration, + annotations: test.annotations, outcome: test.outcome, path, results: test.results.map(r => this._createTestResult(r)), @@ -359,6 +361,7 @@ class HtmlBuilder { projectName, location, duration, + annotations: test.annotations, outcome: test.outcome, path, ok: test.outcome === 'expected' || test.outcome === 'flaky', diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 57c6bb62ce..e84d80e0e8 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -274,3 +274,23 @@ test('should show timed out steps', async ({ runInlineTest, page, showReport }) await expect(page.locator('.tree-item:has-text("outer step") svg.color-text-danger')).toHaveCount(2); await expect(page.locator('.tree-item:has-text("inner step") svg.color-text-danger')).toHaveCount(2); }); + +test('should render annotations', async ({ runInlineTest, page, showReport }) => { + const result = await runInlineTest({ + 'playwright.config.js': ` + module.exports = { timeout: 1500 }; + `, + 'a.test.js': ` + const { test } = pwt; + test('skipped test', async ({ page }) => { + test.skip(true, 'I am not interested in this test'); + }); + `, + }, { reporter: 'dot,html' }); + expect(result.exitCode).toBe(0); + expect(result.skipped).toBe(1); + + await showReport(); + await page.click('text=skipped test'); + await expect(page.locator('.test-case-annotation')).toHaveText('skip: I am not interested in this test'); +});