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): do not update total time when filtering tests (#27808)

Yury Semikhatsky86c78c1e0fd9
diff --git a/packages/html-reporter/src/testFilesView.tsx b/packages/html-reporter/src/testFilesView.tsx
index 710beaf3ad..51a3780f77 100644
--- a/packages/html-reporter/src/testFilesView.tsx
+++ b/packages/html-reporter/src/testFilesView.tsx
@@ -45,12 +45,12 @@ export const TestFilesView: React.FC<{
return <>
<div className='mt-2 mx-1' style={{ display: 'flex' }}>
{projectNames.length === 1 && !!projectNames[0] && <div data-testid="project-name" style={{ color: 'var(--color-fg-subtle)' }}>Project: {projectNames[0]}</div>}
- {!filter.empty() && <div data-testid="filtered-tests-count" style={{ color: 'var(--color-fg-subtle)', padding: '0 10px' }}>Filtered: {filteredStats.total}</div>}
+ {!filter.empty() && <div data-testid="filtered-tests-count" style={{ color: 'var(--color-fg-subtle)', padding: '0 10px' }}>Filtered: {filteredStats.total} {!!filteredStats.total && ('(' + msToString(filteredStats.duration) + ')')}</div>}
<div style={{ flex: 'auto' }}></div>
<div data-testid="overall-time" style={{ color: 'var(--color-fg-subtle)', marginRight: '10px' }}>{report ? new Date(report.startTime).toLocaleString() : ''}</div>
- <div data-testid="overall-duration" style={{ color: 'var(--color-fg-subtle)' }}>Total time: {msToString(filteredStats.duration)}</div>
+ <div data-testid="overall-duration" style={{ color: 'var(--color-fg-subtle)' }}>Total time: {msToString(report?.duration ?? 0)}</div>
</div>
- {report && report.errors.length && <AutoChip header='Errors' dataTestId='report-errors'>
+ {report && !!report.errors.length && <AutoChip header='Errors' dataTestId='report-errors'>
{report.errors.map((error, index) => <TestErrorView key={'test-report-error-message-' + index} error={error}></TestErrorView>)}
</AutoChip>}
{report && filteredFiles.map(({ file, defaultExpanded }) => {
diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts
index 4f273be2d3..e44216f063 100644
--- a/tests/playwright-test/reporter-blob.spec.ts
+++ b/tests/playwright-test/reporter-blob.spec.ts
@@ -388,7 +388,7 @@ test('total time is from test run not from merge', async ({ runInlineTest, merge
// "Total time: 2.1s"
const time = /Total time: (\d+)(\.\d+)?s/.exec(durationText);
expect(time).toBeTruthy();
- expect(parseInt(time[1], 10)).toBeGreaterThan(2);
+ expect(parseInt(time[1], 10)).toBeGreaterThanOrEqual(2);
});
test('merge into list report by default', async ({ runInlineTest, mergeReports }) => {
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 9a82a0f87d..8090972125 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -1356,11 +1356,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(regressionLabelButton).not.toBeVisible();
- {
- const testDuration = await page.getByTestId('test-duration').textContent();
- const totalDuration = await page.getByTestId('overall-duration').textContent();
- expect(totalDuration).toBe('Total time: ' + testDuration);
- }
+ await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.clear();
@@ -1376,11 +1372,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
await expect(page.locator('.test-file-test .test-file-title')).toHaveText('Error Pages › @regression passes');
- {
- const testDuration = await page.getByTestId('test-duration').textContent();
- const totalDuration = await page.getByTestId('overall-duration').textContent();
- expect(totalDuration).toBe('Total time: ' + testDuration);
- }
+ await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.clear();
@@ -1534,21 +1526,15 @@ for (const useIntermediateMergeReport of [false, true] as const) {
return total;
}
- async function checkTotalDuration(testNames: string[]) {
- for (const testDuration of await page.getByTestId('test-duration').allTextContents())
- expect(testDuration).toMatch(/\d+m?s$/);
-
- const expectedTotalTimeInMs = calculateTotalTestDuration(testNames);
- await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(expectedTotalTimeInMs)}`);
- }
-
const searchInput = page.locator('.subnav-search-input');
await expect(page.getByTestId('filtered-tests-count')).not.toBeVisible();
+ await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.fill('s:failed');
- await expect(page.getByTestId('filtered-tests-count')).toHaveText('Filtered: 3');
- await checkTotalDuration(['a-one foo', 'a-two foo', 'b-one foo']);
+ const threeTestsDuration = calculateTotalTestDuration(['a-one foo', 'a-two foo', 'b-one foo']);
+ await expect(page.getByTestId('filtered-tests-count')).toHaveText(`Filtered: 3 (${msToString(threeTestsDuration)})`);
+ await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('10');
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('7');
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('3');
@@ -1559,8 +1545,9 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(page.getByTestId('filtered-tests-count')).not.toBeVisible();
await searchInput.fill('foo');
- await expect(page.getByTestId('filtered-tests-count')).toHaveText('Filtered: 4');
- await checkTotalDuration(['a-one foo', 'a-two foo', 'b-one foo', 'b-two foo']);
+ const fourTestsDuration = calculateTotalTestDuration(['a-one foo', 'a-two foo', 'b-one foo', 'b-two foo']);
+ await expect(page.getByTestId('filtered-tests-count')).toHaveText(`Filtered: 4 (${msToString(fourTestsDuration)})`);
+ await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('10');
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('7');
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('3');