How do I use the `test.step()` API in Playwright to log each step of a test?


Sure, you can easily log each step of your test in Playwright using the test.step() API. This API lets you break down long tests into manageable steps and provides detailed information about each step in the reporters API.

Here's a quick example:

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

test('test', async ({ page }) => {
  await test.step('Log in', async () => {
    // ... perform login actions

  await test.step('news feed', async () => {
    // ... perform news feed actions

In this test, we have two steps: "Log in" and "news feed". Each step represents a specific action or set of actions.

If you need to start a web server before your tests, you can use the webServer option in your playwright.config.ts file. Here's an example:

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

export default defineConfig({
  webServer: {
    command: 'npm run start',
    url: '',
    timeout: 120 * 1000,
    reuseExistingServer: !process.env.CI,

Playwright will wait for the specified URL to be available before running your tests.

For more information, check out these links:

I hope this helps! If you have any more questions, just let me know.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

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.