Rayrun
← Back to Discord Forum

How to show the log level (e.g: Trace, info, debug) in report in the playwright?

This thread is trying to answer question "How to show the log level (e.g: Trace, info, debug) in report in the playwright?"

2 replies

For example, I login with acc: abc@gmail.com. So, I want to see this account in report

In html report?

Answer

Displaying Log Levels and Account Information in Playwright Test Reports

To display log levels and account information in your Playwright test reports, you'll need to use the HTML reporter and add custom metadata to your tests.

Using the HTML Reporter

First, specify the HTML reporter in your playwright.config.ts file. This reporter generates an HTML report that includes logs with their respective log levels.

import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [['html', { outputFolder: 'my-report' }]],
});

In this configuration, we're using the HTML reporter and specifying an output folder (my-report in this example) where the report will be generated.

Adding Custom Metadata

Next, add custom metadata to your tests using the test.meta function. This metadata can include additional information such as the account used for logging in.

import { test } from '@playwright/test';

test('Login Test', async ({ page }) => {
  // Login logic here

  // Add metadata for account information
  test.meta({ account: 'user@ray.run' });

  // Rest of your test code
});

In this example, we added a meta call within our login test and specified an account key with its corresponding value (user@ray.run). This metadata will be associated with this specific test case.

When you run your tests with one of Playwright's built-in reporters (such as HTML or JSON), the metadata will be included in the report. You can customize the reporter configuration to display this information in a way that suits your needs.

Remember, while Playwright provides built-in reporters, you can also create custom reporters for more specific reporting functionality. For more details, refer to Playwright's official documentation and the Mastering Playwright Test Automation: Your Comprehensive Cheat Sheet blog post.

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 luc@ray.run.