-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Feature]: allow to pass arbitrary location to test.step #30160
Comments
If you use boxing in the test.step it'll give you the right locations. https://playwright.dev/docs/release-notes#hide-implementation-details-box-test-steps |
Yes, but it boxes only 1 stack frame up (I think because of this line). If I wrap my export async function clickButton2(text: string) {
return clickButton(text);
}
export async function clickButton(text: string) {
return test.step(`User clicks button "${text}"`, async () => {
// ...
}, { box: true });
} Running: test('test', async ({ }) => {
await clickButton2('foo');
await clickButton2('bar');
await clickButton2('baz');
}); |
That's because you did not box clickButton2. Any time you want to pass location to step, box it instead. |
That's something we can fix, open to making the step title optional. Marking as open to a pr. |
@pavelfeldman will these empty-title steps keep nesting structure? Because I'm caring about this:
|
Being able to pass a custom location would be great for Serenity/JS integration with Playwright Test, too. @pavelfeldman - would you be open to extending
Alternatively, a separate |
We had this implemented us the non-public |
Thank you! |
@vitalets @osohyun0224 @WestonThayer @jan-molak Are you generating your playwright tests? We have discussed this with the team, and feel like for generated tests the best solution would be a source map. It is an established technology that gives you plenty of control over source locations. Let me know what you think. |
Hi @dgozman So I don't need source maps, as it's a regular Playwright tests execution. Pointing to feature files is a nice option, but it adds complexity to the code generation process. Currently, I just output correct JavaScript code. I think the general use case is following: Passing custom location as a step property is so straightforward. Why do you think we need another solution? |
Hi @dgozman and thanks for looking into this! Serenity/JS doesn't generate Playwright tests, so source maps would not be appropriate in our case. It would be ideal if we could specify the location instead. To give you some more context, Serenity/JS integrates with Playwright Test and uses This integration also offers a nice developer experience in VSCode with the Playwright extension: Since, at the moment, the public The need to monkey-patch is not ideal. However, this approach allows us to inject the location where the Serenity/JS task is instantiated in the test file (or in a user-land test library built on top of Serenity/JS) instead of where the As per my previous suggestion, we'd love for the test.step('my step', () => { ... }, { location: { ... } }) If your team prefers to keep the I'd happily answer any other questions your team has and collaborate on a solution. |
@vitalets @jan-molak Thank you for the information. We decided to proceed with adding |
@dgozman Sorry for the late reply. I understood @vitalets and @jan-molak opinions well, and it's really cool! 👏🏻 |
@dgozman apologies for the delay as well. We also are not generating tests, we have a custom fixture similar to Page optimized for accessibility testing (it has access to a screen reader, etc). It has methods analogous to |
) Fixes #30160 ### Description: This pull request introduces the ability to specify custom locations for test steps in Playwright. By enabling the provision of arbitrary locations to the test.step method, it resolves the limitation where helper methods obfuscate the original call site, providing more accurate and meaningful location data in test reports. ### Motivation: To enhance the utility and clarity of test reports in Playwright. Specifically, it addresses the need to trace test steps back to their precise location in the code, which is especially important when steps are abstracted in helper functions. This feature is crucial for maintaining accurate documentation and facilitating debugging processes. ### Changes: Added functionality to pass a custom location object to test.step. ### Expected Outcome: This PR is expected to significantly improve the precision and usefulness of diagnostic data in test reports by allowing specific locations within helper functions to be accurately documented. It facilitates better tracking of test executions and simplifies the debugging process, making it easier for developers to understand and address issues within complex tests. ### References: Closes #30160 - "[Feature]: allow to pass arbitrary location to test.step" **Code Check** I conducted tests on this new feature by integrating it into some existing test codes, and it worked well. I will attach the code used for testing and a screenshot showing the successful outcome. <details> <summary>�toggle dropdown</summary> <div markdown="1"> ``` import type { Location } from '../../../packages/playwright/types/testReporter' ... test('should respect the back button', async ({ page }) => { await page.locator('.todo-list li .toggle').nth(1).check(); await checkNumberOfCompletedTodosInLocalStorage(page, 1); ... await test.step('Showing active items', async () => { await page.getByRole('link', { name: 'Active' }).click(); }, {location}); ``` <img width="1109" alt="image" src="https://github.com/user-attachments/assets/359feafa-0949-4c71-9426-46debef21bdd"> </div> </details>
Thank you! |
🚀 Feature Request
Currently
test.step
method binds location in file to the place of it's call.When
test.step
is wrapped with helper methods, it produces the same location for different steps.Suggestion is to allow to pass arbitrary location to
test.step
. See example below.Example
Imagine I have a
helper.ts
where I define step helper for my tests:Now I run the following test from
./e2e/test.ts
:In the report I get all steps with the same location:
It would be great to see more meaningful locations in the report, e.g.:
If I were able to provide a custom location to
test.step
, I would achieve it. Example:Motivation
In general this feature provides more opportunities for writing high order step helpers.
Personally, I need it for managing
playwright-bdd
project. I'm wrappingtest.step
withGiven / When / Then
helpers to have correct step titles in the report:Before Playwright 1.43 I've used private
testInfo._runAsStep
method to run step with a custom location. Since 1.43testInfo._runAsStep
was replaced with a more complex logic and now I need more tricky hacks to achieve the same.The text was updated successfully, but these errors were encountered: