Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(html): open `path` attachments in new tab (#35508)
Simon Knottf31e05bd0739
diff --git a/packages/html-reporter/src/links.tsx b/packages/html-reporter/src/links.tsxindex 5b79102ffe..f0054fb501 100644--- a/packages/html-reporter/src/links.tsx+++ b/packages/html-reporter/src/links.tsx@@ -77,10 +77,22 @@ export const AttachmentLink: React.FunctionComponent<{useAnchor('attachment-' + result.attachments.indexOf(attachment), triggerFlash);return <TreeItem title={<span>{attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()}- {attachment.path && <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a>}+ {attachment.path && (+ openInNewTab+ ? <a href={href || attachment.path} target='_blank' rel='noreferrer'>{linkName || attachment.name}</a>+ : <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a>+ )}{!attachment.path && (openInNewTab- ? <a href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))} target='_blank' rel='noreferrer' onClick={e => e.stopPropagation()}>{attachment.name}</a>+ ? (+ <a+ href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))}+ target='_blank' rel='noreferrer'+ onClick={e => e.stopPropagation() /* dont expand the tree item */}+ >+ {attachment.name}+ </a>+ ): <span>{linkifyText(attachment.name)}</span>)}</span>} loadChildren={attachment.body ? () => {diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.tsindex 55e21b48e1..aa827cda08 100644--- a/tests/playwright-test/reporter-html.spec.ts+++ b/tests/playwright-test/reporter-html.spec.ts@@ -942,14 +942,22 @@ for (const useIntermediateMergeReport of [true, false] as const) {});test('should have link for opening HTML attachments in new tab', async ({ runInlineTest, page, showReport }) => {+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32281' });+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/35489' });+const result = await runInlineTest({'a.test.js': `+ import * as fs from 'fs/promises';import { test, expect } from '@playwright/test';test('passing', async ({ page }, testInfo) => {await testInfo.attach('axe-report.html', {contentType: 'text/html',body: '<h1>Axe Report</h1>',});++ const attachmentFile = testInfo.outputPath('foo.html');+ await fs.writeFile(attachmentFile, '<h1>Hello World</h1>');+ await testInfo.attach('foo.html', { path: attachmentFile });});`,}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });@@ -958,13 +966,20 @@ for (const useIntermediateMergeReport of [true, false] as const) {await showReport();await page.getByText('passing', { exact: true }).click();- const [newTab] = await Promise.all([+ const [axeTab] = await Promise.all([page.waitForEvent('popup'),page.getByText('axe-report.html', { exact: true }).click(),]);- await expect(newTab).toHaveURL(/^blob:/);- await expect(newTab.getByText('Axe Report')).toBeVisible();+ await expect(axeTab).toHaveURL(/^blob:/);+ await expect(axeTab.getByText('Axe Report')).toBeVisible();++ const [fooTab] = await Promise.all([+ page.waitForEvent('popup'),+ page.getByText('foo.html', { exact: true }).click(),+ ]);++ await expect(fooTab.getByText('Hello World')).toBeVisible();});test('should use file-browser friendly extensions for buffer attachments based on contentType', async ({ runInlineTest, showReport, page }, testInfo) => {