microsoft / microsoft/playwright
[Feature] Allow to set test.use options per single test
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
### Note from maintainers
You can use an anonymous describe to wrap a single test and a `test.use()` call.
```js
test.describe(() => {
test.use({ ... });
test('example test', async ({ page }) => {
// ...
});
});
```
---
This issue was mentioned in a couple of places and seems like it is missing a good solution:
https://github.com/microsoft/playwright/discussions/19893
https://github.com/microsoft/playwright/discussions/21341
Currently we have 2 ways of using fixture options - either by setting it in the config file per project inside `use` block or in `test.use` statement in a spec file. `test.use` statement seems to be not flexible enough because it allows to set whatever we want only for the whole file or per whole `test.describe` block and not for a single test.
Taking simple example from the official documentation https://playwright.dev/docs/test-fixtures#fixtures-options - having fixture option defined like below:
```ts
import { test as base } from '@playwright/test';
import { TodoPage } from './todo-page';
// Declare your options to type-check your configuration.
export type MyOptions = {
defaultItem: string;
};
type MyFixtures = {
todoPage: TodoPage;
};
// Specify both option and fixture types.
export const test = base.extend({
// Define an option and provide a default value.
// We can later override it in the config.
defaultItem: ['Something nice', { option: true }],
// Our "todoPage" fixture depends on the option.
todoPage: async ({ page, defaultItem }, use) => {
// ...
},
});
export { expect } from '@playwright/test';
```
It would be convenient to be able to set use params per single test like that (or any other neat way that would do the trick):
```ts
test('example test #1', async ({ todoPage, page }) => {
// ...
}).use({ defaultItem: 'Something cool' });
test('example test #2', async ({ todoPage, page }) => {
// ...
}).use({ defaultItem: 'Something else' });
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing test.use documentation and the linked discussions, then trace how options are scoped at project, file, and anonymous describe levels. Determine the intended single-test API and its type-checking behavior before identifying the relevant implementation and tests. Done means a single test can set its own fixture options without changing neighboring tests, with coverage for the documented examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- playwright, typescript
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100