Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion packages/playwright/src/worker/testInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ export class TestInfoImpl implements TestInfo {
title: `Attach ${escapeWithQuotes(name, '"')}`,
category: 'test.attach',
});
this._attach(await normalizeAndSaveAttachment(this.outputPath(), name, options), step.stepId);
this._attach(
await normalizeAndSaveAttachment(this.outputPath(), name, options),
step.group ? undefined : step.stepId
);
step.complete({});
}

Expand Down
27 changes: 27 additions & 0 deletions tests/playwright-test/reporter-attachment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,30 @@ test('render text attachment with multiple lines', async ({ runInlineTest }) =>
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
expect(result.exitCode).toBe(1);
});

test('attaching inside boxed fixture should not log error', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
import { test as base } from '@playwright/test';

const test = base.extend<{ myFixture: void }>({
myFixture: [async ({}, use, testInfo) => {
await testInfo.attach('my attachment', {
body: 'foo',
contentType: 'text/plain',
});
await use();
}, { box: true }],
});

test('my test', ({ myFixture }) => {
expect(1).toBe(0);
});
`,
}, { reporter: 'line' }, {});
const text = result.output;
expect(text).toContain(' attachment #1: my attachment (text/plain) ──────────────────────────────────────────────────────');
expect(text).toContain(' foo');
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
expect(result.exitCode).toBe(1);
});
29 changes: 29 additions & 0 deletions tests/playwright-test/ui-mode-test-attachments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,35 @@ test('should link from attachment step to attachments view', async ({ runUITest
await expect(attachment).toBeInViewport();
});

test('attachments from inside boxed fixture should be visible', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runUITest }) => {
const { page } = await runUITest({
'a.test.ts': `
import { test as base } from '@playwright/test';

const test = base.extend<{ myFixture: void }>({
myFixture: [async ({}, use, testInfo) => {
await testInfo.attach('my attachment', {
body: 'foo',
contentType: 'text/plain',
});
await use();
}, { box: true }],
});

test('my test', ({ myFixture }) => {});
`,
}, { reporter: 'line' }, {});
await page.getByText('my test').click();
await page.getByTitle('Run all').click();
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');

await page.getByRole('treeitem', { name: 'attach "my attachment"' }).getByLabel('Open Attachment').click();
await expect(page.getByRole('tabpanel', { name: 'Attachments' })).toMatchAriaSnapshot(`
- tabpanel:
- button /my attachment/
`);
});

function readAllFromStream(stream: NodeJS.ReadableStream): Promise<Buffer> {
return new Promise(resolve => {
const chunks: Buffer[] = [];
Expand Down
Loading