Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reporter): report TestStep#attachments #34037

Merged
merged 29 commits into from
Jan 2, 2025

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Dec 16, 2024

Closes #32748.

Adds a TestStep.attachments array to the Reporter API that shows all attachments created by the step. Removes the artificial attach "foo" step for all calls except TestInfo.attach().

This also means some changes to the HTML report attachment links introduced in #33267:

  • the icon button goes from the removed attach "foo" step to their parent step
  • the internal anchoring now goes by attachment index instead of the attachment name

@Skn0tt Skn0tt requested a review from dgozman December 16, 2024 17:46
@Skn0tt Skn0tt self-assigned this Dec 16, 2024

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Skn0tt Skn0tt changed the title feat(html reporter): show attachments in attachment steps feat(reporter): report TestStep#attachments Dec 17, 2024
@Skn0tt Skn0tt changed the title feat(reporter): report TestStep#attachments feat(reporter): report TestStep#attachments Dec 17, 2024

This comment has been minimized.

This comment has been minimized.

docs/src/test-reporter-api/class-teststep.md Outdated Show resolved Hide resolved
docs/src/test-reporter-api/class-teststep.md Outdated Show resolved Hide resolved
packages/playwright/src/index.ts Outdated Show resolved Hide resolved
packages/playwright/src/matchers/expect.ts Outdated Show resolved Hide resolved
tests/playwright-test/playwright.trace.spec.ts Outdated Show resolved Hide resolved
packages/playwright/src/matchers/toMatchSnapshot.ts Outdated Show resolved Hide resolved
packages/playwright/src/matchers/toMatchSnapshot.ts Outdated Show resolved Hide resolved
packages/playwright/src/matchers/toMatchSnapshot.ts Outdated Show resolved Hide resolved
packages/playwright/src/worker/testInfo.ts Outdated Show resolved Hide resolved
packages/playwright/src/worker/testInfo.ts Outdated Show resolved Hide resolved
@@ -393,3 +391,48 @@ test('should show custom fixture titles in actions tree', async ({ runUITest })
/After Hooks[\d.]+m?s/,
]);
});

test('attachments tab shows all but top-level .push attachments', async ({ runUITest }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test shows a real regression from this change. As intended, test.info().attachments.push will no longer show up as an action. The trace viewer only stores attachments in AfterActionTraceEvent though. So top-level attachments, which live outside of an action, no longer show up in traces.

I don't think we'll want to merge a regression like this, so i'll make an exception for top-level attachment.push calls, and emit them as actions to the trace viewer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine for now. I see that's already done in the testInfo.ts?

We can follow up by adding a timestamp to attachments and emitting a separate "testend" event in the trace with all the leftover attachments. At that point we can possibly remove "attach foo" steps as well. Up for discussion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's already done 👍 Separate event post execution sounds good.

Copy link
Member Author

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, that was super useful! I've addressed the feedback. I also had another look at what this change means for the trace viewer. There was a problem with top-level attachments that would have gone missing from the trace-viewer - added a workaround for that, see comment above.

Please have another look!

This comment has been minimized.

@Skn0tt Skn0tt requested a review from pavelfeldman December 20, 2024 15:49

This comment has been minimized.

packages/playwright/src/runner/dispatcher.ts Outdated Show resolved Hide resolved
@@ -566,7 +566,7 @@ test('should opt out of attachments', async ({ runInlineTest, server }, testInfo
'After Hooks',
]);
expect(trace.actions[1].attachments).toEqual(undefined);
expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toHaveLength(0);
expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toEqual([expect.stringMatching(/^resources\/src@.*$/)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how did this test work before? This PR does not seem to affect this behavior, does it?

Copy link
Member Author

@Skn0tt Skn0tt Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what exactly, but some change in this PR made filteredStack contain something when testInfo.attach() is called. That leads tracing to include the source code as a resource. Let me refactor this assertion to make that more clear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there you go: d277551

@@ -393,3 +391,48 @@ test('should show custom fixture titles in actions tree', async ({ runUITest })
/After Hooks[\d.]+m?s/,
]);
});

test('attachments tab shows all but top-level .push attachments', async ({ runUITest }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine for now. I see that's already done in the testInfo.ts?

We can follow up by adding a timestamp to attachments and emitting a separate "testend" event in the trace with all the leftover attachments. At that point we can possibly remove "attach foo" steps as well. Up for discussion.

@@ -50,6 +50,16 @@ Start time of this particular test step.

List of steps inside this step.

## property: TestStep.attachments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing that every reporter implementation immediately turns this into indices, perhaps we should revisit the API and make this an array of numbers? This does not block the PR, but please put it as an explicit topic for the API review.

packages/playwright/src/worker/testInfo.ts Show resolved Hide resolved
@@ -512,8 +516,11 @@ class TeleTestStep implements reporterTypes.TestStep {
parent: reporterTypes.TestStep | undefined;
duration: number = -1;
steps: reporterTypes.TestStep[] = [];
attachments: reporterTypes.TestStep['attachments'] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a getter and compute lazily upon access? There is a memory pressure problem when merging a lot of large reports, and this class takes the most memory because there are a lot of steps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it a getter in 365b30f. We can look into refactoring the rest of this as well, so that TeleTestStep only keeps _startPayload and _endPayload references.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Skn0tt Skn0tt requested a review from dgozman January 2, 2025 10:43
@Skn0tt Skn0tt merged commit 04a3574 into microsoft:main Jan 2, 2025
29 checks passed
Copy link
Contributor

github-actions bot commented Jan 2, 2025

Test results for "tests 1"

7 flaky ⚠️ [firefox-page] › page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-setup.spec.ts:98:5 › should show errors in config @macos-latest-node18-1
⚠️ [webkit-library] › library/browsertype-connect.spec.ts:264:5 › launchServer › should support slowmo option @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/proxy.spec.ts:93:11 › should proxy local network requests › by default › localhost @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/selector-generator.spec.ts:35:5 › selector generator › should prefer button over inner span @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:205:3 › should upload multiple large files @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

37498 passed, 650 skipped
✔️✔️✔️

Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support attachment for particular test step
3 participants