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);
},
});- 1Export a variable named
fixturefrom the test file - 2Extend the base
testand provide the value viause - 3Register a
beforeAllhook inplaywright.config
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.