Rayrun
← Back to Discord Forum

How to change the default value of a fixture with default parameters given officially?

optional518posted in #help-playwright
Open in Discord
import { test as base } from '@playwright/test';

export type TestOptions = {
  person: string;
};

export const test = base.extend<TestOptions>({
  // Define an option and provide a default value.
  // We can later override it in the config.
  person: ['John', { option: true }],

  // Override default "page" fixture.
  page: async ({ page, person }, use) => {
    await page.goto('/chat');
    // We use "person" parameter as a "name" for the chat room.
    await page.getByLabel('User Name').fill(person);
    await page.getByText('Enter chat room').click();
    // Each test will get a "page" that already has the person name.
    await use(page);
  },
});

As in the above example, in the test case, how to modify the default value of person, such as changing John to Alice

This thread is trying to answer question "How to modify the default value of a fixture with default parameters in a test case?"

1 reply

Just provide needed value in use test.use({ person: 'Alex' });

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