-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
520d23b
commit 8451727
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
"playwright-decorators": minor | ||
--- | ||
|
||
Add support for fixtures | ||
|
||
This release introduce a new method `extend<T>(customFixture)` that allows to create decorators (`afterAll`, `afterEach`, `test`, `beforeAll`, `beforeEach`) with access to custom fixtures. | ||
|
||
```ts | ||
import { test as base } from 'playwright'; | ||
import { suite, test, extend } from 'playwright-decorators'; | ||
|
||
// #1 Create fixture type | ||
type UserFixture = { | ||
user: { | ||
firstName: string; | ||
lastName: string; | ||
} | ||
} | ||
|
||
// #2 Create user fixture | ||
const withUser = base.extend<UserFixture>({ | ||
user: async ({}, use) => { | ||
await use({ | ||
firstName: 'John', | ||
lastName: 'Doe' | ||
}) | ||
} | ||
}) | ||
|
||
// #3 Generate afterAll, afterEach, test, beforeAll, beforeEach decorators with access to the user fixture | ||
const { | ||
afterAll, | ||
afterEach, | ||
test, | ||
beforeAll, | ||
beforeEach, | ||
} = extend<UserFixture>(withUser); | ||
|
||
// #4 Use decorators | ||
@suite() | ||
class MyTestSuite { | ||
@beforeAll() | ||
async beforeAll({ user }: TestArgs<UserFixture>) { // have access to user fixture | ||
// ... | ||
} | ||
|
||
@test() | ||
async test({ user }: TestArgs<UserFixture>) { // have access to user fixture | ||
// ... | ||
} | ||
} | ||
``` |