Rayrun
← Back to Discord Forum

how can i hide "test steps" occurring in a test fixture

leblancmenesesposted in #help-playwright
Open in Discord
leblancmeneses

I have a test fixture that is a mix of networkidle and tracing info. This method has to "await" 2 activities that are recorded as a test step. Is there a way i can hide these? It makes the "test steps" noisy.

image.png
image.png

This thread is trying to answer question "How can I hide 'test steps' occurring in a test fixture when using Playwright's testing library?"

9 replies
leblancmeneses

this could potentnially be a bug. why make a system method a test step?

I believe this is what box will do if you are using 1.39, might suggest watching Debbie and Max's video covering the 1.39 release...

Fixture is supposed to be hidden inside "before" in the report.

leblancmeneses

"before" might be specific to a worker fixture. What I have here is a test fixture unfortunately. So a way to supress this would be great.

// 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

¯_(ツ)_/¯

image.png
leblancmeneses

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);
    }
});
image.png
image.png

Well, a event handler cannot be considered to be executed within a fixture. It has closure of the fixture, but it is not the fixture itself. You can post a feature request on Playwright's GitHub for overriding the reporting behavior of a step, but I doubt that it'll be implemented.

If your objective is to log all the network request, I would suggest using a request library like Axios and write an adapter between PW's request and Axios's request objects, and hook it in with PW's request handlers.

leblancmeneses

I don't think a change would be as big as it seems: (something similar to) set DEBUG=*,-request.allHeaders*,-request.response*

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].