-
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
feat(playwright-test): test.step supports passing step params to trace view #32704
Conversation
@microsoft-github-policy-service agree |
Test results for "tests 1"2 flaky35525 passed, 661 skipped Merge workflow run. |
I'm not sure I like the change. It fits the steps infrastructure nicely with the params being passed directly into the trace, but at the same time it is unclear why it is bypassing the reporters API. Could you give me a better idea on a couple of typical use cases for this? |
Hi @pavelfeldman and thanks for reviewing the PR.
Sure thing. Trace viewer is very useful in debugging complex test scenarios as it provides information about all the low-level Playwright API calls, network requests, and so on. However, I am not aware of a way to make it report the higher-level abstractions alongside the low-level calls. For example, consider a test scenario that requires setting up some test data before making Playwright interact with the UI. Let's say we're testing a product search functionality and we need to inject product-related data into the system: const products = [
{ name: 'apples', price: '£2.50', .... },
{ name: 'oranges', .. },
// etc.
] Let's also assume that setting up each product is itself quite involved and requires several REST API calls. We could model a function to set up a test product using describe('Search', () => {
it('find products based on name', ({ page, request }) => {
for (const product of products) {
await createTestProduct(product, request)
}
await page.goto('...')
// enter search term, find the product, and so on
})
})
async function createTestProduct(product: Product, request): Promise<void> {
await test.step('create test product', async () => {
await request... // create product
await request... // update product details
await request... // add product to search categories
// ...
});
} The limitation here is that even though the report will now show several calls to It would be great if instead we could tell Playwright what the "high-level" parameter was, for example: async function createTestProduct(product: Product, request): Promise<void> {
await test.step('create test product', async () => {
await request... // create product
await request... // update product details
await request... // add product to search categories
// ...
}, { params: { product } });
} While this example is pretty basic, I'm sure you can see the challenge if, instead of apples and oranges, we wanted to set up several test customers in a banking system, each customer with one or more accounts, each account with an initial balance, overdraft limits and so on. Being able to make Playwright aware of those higher-level parameters would make the report even more useful in such complex scenarios. I hope this helps. Please let me know if you have any concerns or if there's a different way available in Playwright to support this use case. |
We could invest in improving the rendering of attachments: import { test } from '@playwright/test';
const products = [
{ name: 'apples', price: '£2.50' },
{ name: 'oranges', price: '$2' },
];
test.describe('Search', () => {
test('find products based on name', async ({}) => {
for (const product of products)
await createTestProduct(product);
});
});
async function createTestProduct(product): Promise<void> {
await test.step('create test product', async () => {
// ...
await test.info().attach('product', { body: JSON.stringify(product, undefined, 2), contentType: 'text/plain' });
});
} that way information would get both into the report and the trace. |
Linking a similar issue for attributing steps with attachments data: #32748 Some points from previous discussions, that are important for attachments + steps:
|
These are good points, but to me they speak in favor of prioritizing the step attachment fixes! Closing this PR, please file an issue where we could track it. I'm supportive of fixing attachments for steps on the API level. |
@pavelfeldman @vitalets - would injecting the I think an interface like this could be quite neat (and avoid the problem with the global object returned by async function createTestProduct(product): Promise<void> {
await test.step('create test product', async ({ testInfo }) => {
// ...
await testInfo.attach('product', { body: JSON.stringify(product, undefined, 2), contentType: 'text/plain' });
});
} |
Extending the functionality requested in #30160 and #32680 and building on #32504 and #32687, this pull request enables the
test.step
API to accept an optionalparams
object, to be included in the trace viewer.This enables test automation frameworks that integrate with Playwright Test, such as Serenity/JS, to add extra context to Playwright reports.
Example usage:
Example result (using Serenity/JS Playwright example):
CC: @dgozman, @mxschmitt, @vitalets, @osohyun0224, @WestonThayer