This thread is trying to answer question "How can I hide 'test steps' occurring in a test fixture when using Playwright's testing library?"
// config
export default defineConfig({
// ...
use: {
testIdAttribute: 'data-test-id'
},
// ...
});
// test
import { type Page, test as base } from '@playwright/test';
const test = base.extend<{ myPage: Page }>({
myPage: async ({ page }, use) => {
await page.goto('https://www.ecosia.org/');
await use(page);
}
});
test('test', async ({ myPage }) => {
await myPage.getByTestId('main-nav-toggle').click();
await myPage.getByTestId('main-nav-dropdown').waitFor({ state: 'visible' });
});
Report shows fixtures steps inside the "before" hook. Tested on PW v1.34.3 and v1.39.0
¯_(ツ)_/¯
My fixture uses page.on
that causes events to fall outside "Before hooks". So depending on the test step an "on" event is added under the current node. Would be nice to suppress these.
see:
const test = base.extend<{ myPage: Page }>({
myPage: async ({ page }, use) => {
const captureRequestDetail = async (request, status: string) => {
let allHeaders = {};
if (status !== 'requestfailed') {
allHeaders = await request.allHeaders();
}
const response = await request.response();
const timing = request.timing();
return {
frameUrl: request.frame().url(),
method: request.method(),
url: request.url(),
headers: allHeaders,
postData: request.postData(),
timing,
status,
timingDiffInMs: timing.responseEnd,
statusCode: !!response ? response.status() : undefined,
};
}
page.on('requestfailed', async request => {
console.log('requestfailed', await captureRequestDetail(request, 'requestfailed'));
});
page.on('requestfinished', async request => {
console.log('requestfinished', await captureRequestDetail(request, 'requestfinished'));
});
await page.goto('https://www.ecosia.org/');
await use(page);
}
});
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].