Playwright · Middle · Question 8 of 75

How do you create a custom fixture?

const test = base.extend<{ todoPage: TodoPage }>({
  todoPage: async ({ page }, use) => {
    const todo = new TodoPage(page);
    await todo.goto();
    await use(todo);
  },
});
Show the answer

Correct answer: Extend the base test and provide the value via use

Explanation

Code before use() is setup, code after it is teardown. Tests that list todoPage in their arguments get it ready to use.

Further reading

Problem with a question

Playwright · Middle · question 8

Test yourself

Take the Playwright · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz