@serenity-js/playwright-test 3.36.2 → 3.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +141 -158
- package/lib/api/serenity-fixtures.d.ts +102 -21
- package/lib/api/serenity-fixtures.d.ts.map +1 -1
- package/lib/api/test-api.d.ts +41 -5
- package/lib/api/test-api.d.ts.map +1 -1
- package/lib/api/test-api.js +62 -14
- package/lib/api/test-api.js.map +1 -1
- package/package.json +7 -6
- package/src/api/serenity-fixtures.ts +105 -20
- package/src/api/test-api.ts +81 -29
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.37.0](https://github.com/serenity-js/serenity-js/compare/v3.36.2...v3.37.0) (2025-12-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **playwright-test:** introduced axios fixture ([a836746](https://github.com/serenity-js/serenity-js/commit/a83674697531622d522c6924db2875188efcc834))
|
|
12
|
+
* **playwright-test:** support for providing extraAbilities without overriding the actors ([5e189ca](https://github.com/serenity-js/serenity-js/commit/5e189caa4f4a0f38287f8586f21d8106c7c7dab3))
|
|
13
|
+
* **playwright-test:** useBase supports merging multiple base fixtures ([e37ed77](https://github.com/serenity-js/serenity-js/commit/e37ed77ae2cc8c18349096cc82668cf522d2e7f1))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [3.36.2](https://github.com/serenity-js/serenity-js/compare/v3.36.1...v3.36.2) (2025-11-26)
|
|
7
20
|
|
|
8
21
|
|
package/README.md
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
# Serenity/JS
|
|
1
|
+
# Serenity/JS Playwright Test
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40serenity-js%2Fplaywright-test)
|
|
4
|
+
[](https://github.com/serenity-js/serenity-js/actions)
|
|
5
|
+
[](https://qlty.sh/gh/serenity-js/projects/serenity-js)
|
|
6
|
+
[](https://qlty.sh/gh/serenity-js/projects/serenity-js)
|
|
7
|
+
[](https://github.com/serenity-js/serenity-js/graphs/contributors)
|
|
8
|
+
[](https://snyk.io/test/npm/@serenity-js/playwright-test)
|
|
9
|
+
[](https://github.com/serenity-js/serenity-js)
|
|
2
10
|
|
|
3
11
|
[](https://www.linkedin.com/company/serenity-js)
|
|
4
12
|
[](https://www.youtube.com/@serenity-js)
|
|
5
13
|
[](https://matrix.to/#/#serenity-js:gitter.im)
|
|
6
14
|
[](https://github.com/sponsors/serenity-js)
|
|
7
15
|
|
|
8
|
-
[
|
|
9
|
-
of complex software systems faster, more collaborative and easier to scale.
|
|
10
|
-
|
|
11
|
-
⭐️ Get started with Serenity/JS!
|
|
12
|
-
- [Serenity/JS web testing tutorial](https://serenity-js.org/handbook/web-testing/your-first-web-scenario)
|
|
13
|
-
- [Serenity/JS + Playwright Test deep dive](https://serenity-js.org/handbook/test-runners/playwright-test/)
|
|
14
|
-
- [Serenity/JS Handbook](https://serenity-js.org/handbook)
|
|
15
|
-
- [API documentation](https://serenity-js.org/api/)
|
|
16
|
-
- [Serenity/JS Project Templates](https://serenity-js.org/handbook/project-templates/)
|
|
16
|
+
[`@serenity-js/playwright-test`](https://serenity-js.org/api/playwright-test/) brings full [Serenity reporting](https://serenity-js.org/handbook/reporting/) capabilities to [Playwright Test](https://playwright.dev/docs/intro) and provides fixtures that enable writing tests using the [Screenplay Pattern](https://serenity-js.org/handbook/design/screenplay-pattern/).
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
- Meet other Serenity/JS developers and maintainers on the [Serenity/JS Community chat channel](https://matrix.to/#/#serenity-js:gitter.im),
|
|
20
|
-
- Find answers to your Serenity/JS questions on the [Serenity/JS Forum](https://github.com/orgs/serenity-js/discussions/categories/how-do-i),
|
|
21
|
-
- Learn how to [contribute to Serenity/JS](https://serenity-js.org/community/contributing/),
|
|
22
|
-
- Support the project and gain access to [Serenity/JS Playbooks](https://github.com/serenity-js/playbooks) by becoming a [Serenity/JS GitHub Sponsor](https://github.com/sponsors/serenity-js)!
|
|
18
|
+
Learn more about using [Serenity/JS with Playwright Test](https://serenity-js.org/handbook/test-runners/playwright-test/)
|
|
23
19
|
|
|
24
|
-
##
|
|
20
|
+
## Features
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
- Integrates Serenity/JS with Playwright Test using dedicated test fixtures
|
|
23
|
+
- Supports testing websites, web apps, and HTTP APIs
|
|
24
|
+
- Enables [Screenplay Pattern](https://serenity-js.org/handbook/design/screenplay-pattern/) APIs in Playwright Test scenarios
|
|
25
|
+
- Supports all [Serenity/JS reporting features](https://serenity-js.org/handbook/reporting/) and expands native Playwright Test reports
|
|
26
|
+
- TypeScript-first design with strong typing for safer and more predictable test code.
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
## Installation
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
To install this module, use an existing [Playwright Test project](https://playwright.dev/docs/intro) or generate a new one by running:
|
|
30
|
+
Use an existing [Playwright Test project](https://playwright.dev/docs/intro) or generate a new one by running:
|
|
34
31
|
|
|
35
32
|
```sh
|
|
36
33
|
npm init playwright@latest
|
|
@@ -39,20 +36,43 @@ npm init playwright@latest
|
|
|
39
36
|
Install the below Serenity/JS modules in your Playwright Test project directory:
|
|
40
37
|
|
|
41
38
|
```sh
|
|
42
|
-
npm install --save-dev @serenity-js/assertions @serenity-js/console-reporter @serenity-js/core @serenity-js/serenity-bdd @serenity-js/web @serenity-js/playwright @serenity-js/playwright-test
|
|
39
|
+
npm install --save-dev @serenity-js/assertions @serenity-js/console-reporter @serenity-js/core @serenity-js/rest @serenity-js/serenity-bdd @serenity-js/web @serenity-js/playwright @serenity-js/playwright-test
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
See the [Serenity/JS Installation Guide](https://serenity-js.org/handbook/installation/).
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { describe, it } from '@serenity-js/playwright-test'
|
|
48
|
+
import { Navigate, Page } from '@serenity-js/web'
|
|
49
|
+
import { Ensure, startsWith } from '@serenity-js/assertions'
|
|
50
|
+
|
|
51
|
+
describe('Website', () => {
|
|
52
|
+
|
|
53
|
+
it('should have a title', async ({ actor }) => {
|
|
54
|
+
|
|
55
|
+
await actor.attemptsTo(
|
|
56
|
+
Navigate.to('https://serenity-js.org/'),
|
|
57
|
+
Ensure.that(Page.current().title(), startsWith('Serenity/JS')),
|
|
58
|
+
)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
43
61
|
```
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
Explore the in-depth Serenity/JS and Playwright Test integration guide in the [Serenity/JS Handbook](https://serenity-js.org/handbook/test-runners/playwright-test/).
|
|
64
|
+
|
|
65
|
+
## Serenity/JS Playwright Fixtures
|
|
46
66
|
|
|
47
67
|
To use Serenity/JS Screenplay Pattern APIs and benefit from the in-depth reporting capabilities,
|
|
48
|
-
import Serenity/JS test fixtures instead of the default ones:
|
|
68
|
+
import Serenity/JS `test` fixtures instead of the default ones:
|
|
49
69
|
|
|
50
70
|
```diff
|
|
51
|
-
//
|
|
71
|
+
// todo_app.spec.ts
|
|
52
72
|
+ import { test } from '@serenity-js/playwright-test'
|
|
53
73
|
- import { test } from '@playwright/test'
|
|
54
74
|
|
|
55
|
-
test.describe('
|
|
75
|
+
test.describe('To-do app', () => {
|
|
56
76
|
|
|
57
77
|
test.describe('New Todo', () => {
|
|
58
78
|
|
|
@@ -66,14 +86,14 @@ test.describe('Serenity Screenplay with Playwright', () => {
|
|
|
66
86
|
If you prefer, Serenity/JS also offers the more concise BDD-style `describe/it` syntax:
|
|
67
87
|
|
|
68
88
|
```typescript
|
|
69
|
-
//
|
|
89
|
+
// todo_app.spec.ts
|
|
70
90
|
import { describe, it, test } from '@serenity-js/playwright-test'
|
|
71
91
|
|
|
72
92
|
test.use({
|
|
73
93
|
headless: true,
|
|
74
94
|
})
|
|
75
95
|
|
|
76
|
-
describe('
|
|
96
|
+
describe('To-do app', () => {
|
|
77
97
|
|
|
78
98
|
describe('New Todo', () => {
|
|
79
99
|
|
|
@@ -84,28 +104,32 @@ describe('Serenity Screenplay with Playwright', () => {
|
|
|
84
104
|
})
|
|
85
105
|
```
|
|
86
106
|
|
|
87
|
-
|
|
107
|
+
## Serenity/JS Screenplay Pattern Actors
|
|
88
108
|
|
|
89
|
-
Serenity/JS test fixtures simplify how you
|
|
109
|
+
Serenity/JS test fixtures simplify how you manage the [actors](https://serenity-js.org/api/core/class/Actor/).
|
|
90
110
|
|
|
91
|
-
|
|
111
|
+
### Single-actor scenarios
|
|
92
112
|
|
|
93
113
|
If your tests need only a single actor, you can inject it using the `actor` fixture.
|
|
94
114
|
To configure the name of your default actor, use the `defaultActorName` configuration property:
|
|
95
115
|
|
|
96
116
|
```typescript
|
|
97
|
-
//
|
|
117
|
+
// todo_app.spec.ts
|
|
98
118
|
|
|
99
|
-
|
|
100
|
-
import {
|
|
101
|
-
|
|
119
|
+
// import fixtures
|
|
120
|
+
import { describe, it, test } from '@serenity-js/playwright-test'
|
|
121
|
+
// import Screenplay Pattern web APIs
|
|
122
|
+
import { Navigate, Page } from '@serenity-js/web'
|
|
123
|
+
// import Screenplay Pattern assertion APIs
|
|
124
|
+
import { Ensure, equals } from '@serenity-js/assertions'
|
|
102
125
|
|
|
103
126
|
test.use({
|
|
104
127
|
headless: true,
|
|
105
|
-
|
|
128
|
+
// change default actor name
|
|
129
|
+
defaultActorName: 'Serena'
|
|
106
130
|
})
|
|
107
131
|
|
|
108
|
-
describe('
|
|
132
|
+
describe('To-do app', () => {
|
|
109
133
|
|
|
110
134
|
describe('New Todo', () => {
|
|
111
135
|
|
|
@@ -122,118 +146,60 @@ describe('Serenity Screenplay with Playwright', () => {
|
|
|
122
146
|
})
|
|
123
147
|
```
|
|
124
148
|
|
|
125
|
-
|
|
149
|
+
### Multi-actor scenarios
|
|
126
150
|
|
|
127
|
-
For multi-actor scenarios where you need each actor to use a separate browser,
|
|
128
|
-
|
|
151
|
+
For multi-actor scenarios, for example where you need each actor to use a separate browser,
|
|
152
|
+
use the `actorCalled` fixture.
|
|
129
153
|
|
|
130
154
|
```typescript
|
|
131
|
-
//
|
|
155
|
+
// todo_app.spec.ts
|
|
132
156
|
|
|
133
157
|
import { describe, it, test } from '@serenity-js/playwright-test' // import fixtures
|
|
134
158
|
|
|
135
|
-
|
|
159
|
+
test.use({
|
|
160
|
+
// change default actor name
|
|
161
|
+
defaultActorName: 'Alice'
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('To-do app', () => {
|
|
136
165
|
|
|
137
166
|
describe('Chat app', () => {
|
|
138
167
|
|
|
139
|
-
it('should allow actors to send and receive messages', async ({ actorCalled }) => {
|
|
168
|
+
it('should allow actors to send and receive messages', async ({ actor, actorCalled, browser }) => {
|
|
140
169
|
|
|
141
|
-
//
|
|
142
|
-
await
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
// define parts of the workflow performed by the any other actors:
|
|
148
|
-
await actorCalled('Bob').attemptsTo(
|
|
149
|
-
// navigate to a chat app
|
|
150
|
-
// post a reply to Alice
|
|
170
|
+
// Define part of the workflow performed by the default actor:
|
|
171
|
+
await actor.attemptsTo(
|
|
172
|
+
// Navigate to a chat app...
|
|
173
|
+
// Post a message to Bob...
|
|
151
174
|
)
|
|
152
175
|
|
|
176
|
+
// Fefine parts of the workflow performed by the any other actors.
|
|
153
177
|
// Note that invoking actorCalled(name) multiple times
|
|
154
178
|
// while using the same name and within the scope of a single test
|
|
155
179
|
// returns the same actor, so you don't need to cache them:
|
|
156
|
-
await actorCalled('
|
|
157
|
-
//
|
|
180
|
+
await actorCalled('Bob')
|
|
181
|
+
// The second actor can use a separate browser instance
|
|
182
|
+
.whoCan(BrowseTheWebWithPlaywright.using(browser))
|
|
183
|
+
.attemptsTo(
|
|
184
|
+
// Navigate to a chat app...
|
|
185
|
+
// Post a reply to Alice...
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
await actor.attemptsTo(
|
|
190
|
+
// Check if the reply from Bob is received
|
|
158
191
|
)
|
|
159
192
|
})
|
|
160
193
|
})
|
|
161
194
|
})
|
|
162
195
|
```
|
|
163
196
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
The default [cast](https://serenity-js.org/api/core/class/Cast) of actors is limited to using a single ability
|
|
167
|
-
to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright).
|
|
168
|
-
|
|
169
|
-
If you'd like to give your actors additional abilities, like to [`TakeNotes`](https://serenity-js.org/api/core/class/TakeNotes),
|
|
170
|
-
[`CallAnApi`](https://serenity-js.org/api/rest/class/CallAnApi),
|
|
171
|
-
or [`ManageALocalServer`](https://serenity-js.org/api/local-server/class/ManageALocalServer), you can install the relevant Serenity/JS module
|
|
172
|
-
and configure them as follows:
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
// example.spec.ts
|
|
176
|
-
|
|
177
|
-
import { Cast, TakeNotes } from '@serenity-js/core'
|
|
178
|
-
import { test } from '@serenity-js/playwright-test'
|
|
179
|
-
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
|
|
180
|
-
import { CallAnApi } from '@serenity-js/rest'
|
|
181
|
-
|
|
182
|
-
test.use({
|
|
183
|
-
actors: async ({ browser, baseURL }, use) => {
|
|
184
|
-
await use(
|
|
185
|
-
Cast.where(actor => actor.whoCan(
|
|
186
|
-
BrowseTheWebWithPlaywright.using(browser),
|
|
187
|
-
TakeNotes.usingAnEmptyNotepad(),
|
|
188
|
-
CallAnApi.at(baseURL),
|
|
189
|
-
))
|
|
190
|
-
)
|
|
191
|
-
},
|
|
192
|
-
})
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
For scenarios where different actors need to be configured differently, you can also implement your own `Cast`:
|
|
197
|
+
To learn more about customising actors and managing their abilities, see the [Serenity/JS Handbook section on Playwright Test customisation](https://serenity-js.org/handbook/test-runners/playwright-test/#modifying-default-abilities).
|
|
196
198
|
|
|
197
|
-
|
|
198
|
-
// example.spec.ts
|
|
199
|
-
|
|
200
|
-
import { Cast } from '@serenity-js/core'
|
|
201
|
-
import { BrowseTheWebWithPlaywright, ExtraBrowserContextOptions } from '@serenity-js/playwright'
|
|
202
|
-
import { test } from '@serenity-js/playwright-test'
|
|
203
|
-
import { CallAnApi } from '@serenity-js/rest'
|
|
204
|
-
import { Browser, BrowserContextOptions } from 'playwright'
|
|
205
|
-
|
|
206
|
-
class Actors implements Cast {
|
|
207
|
-
constructor(
|
|
208
|
-
private readonly browser: Browser,
|
|
209
|
-
private readonly contextOptions: BrowserContextOptions,
|
|
210
|
-
private readonly extraContextOptions: ExtraBrowserContextOptions,
|
|
211
|
-
) {
|
|
212
|
-
}
|
|
199
|
+
### Customising test fixtures
|
|
213
200
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
case 'James':
|
|
217
|
-
return actor.whoCan(BrowseTheWebWithPlaywright.using(this.browser, this.contextOptions, this.extraContextOptions))
|
|
218
|
-
default:
|
|
219
|
-
return actor.whoCan(CallAnApi.at(this.contextOptions.baseURL))
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
test.use({
|
|
225
|
-
actors: async ({ browser, config }) => {
|
|
226
|
-
await use(new Actors(browser, {
|
|
227
|
-
defaultNavigationWaitUntil: 'domcontentloaded'
|
|
228
|
-
}))
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
#### Customising test fixtures
|
|
234
|
-
|
|
235
|
-
[`useFixtures`](https://serenity-js.org/api/playwright-test/function/useFixtures/) lets you configure
|
|
236
|
-
Serenity/JS Screenplay Pattern actors in a single place,
|
|
201
|
+
The [`useFixtures`](https://serenity-js.org/api/playwright-test/function/useFixtures/) function
|
|
202
|
+
lets you configure your actors in a single place,
|
|
237
203
|
and define custom [test fixtures](https://playwright.dev/docs/test-fixtures) if needed.
|
|
238
204
|
|
|
239
205
|
```typescript
|
|
@@ -260,15 +226,16 @@ export const {
|
|
|
260
226
|
})
|
|
261
227
|
```
|
|
262
228
|
|
|
263
|
-
|
|
229
|
+
Next, use your custom test API definition in your test files:
|
|
264
230
|
|
|
265
231
|
```typescript
|
|
266
|
-
//
|
|
232
|
+
// todo_app.spec.ts
|
|
267
233
|
import { Log } from '@serenity-js/core'
|
|
268
234
|
|
|
269
|
-
|
|
235
|
+
// Import describe/it/test from your custom API
|
|
236
|
+
import { describe, it, test } from './my-custom-api'
|
|
270
237
|
|
|
271
|
-
describe('
|
|
238
|
+
describe('To-do app', () => {
|
|
272
239
|
|
|
273
240
|
describe('New Todo', () => {
|
|
274
241
|
|
|
@@ -284,7 +251,7 @@ describe('Serenity Screenplay with Playwright', () => {
|
|
|
284
251
|
})
|
|
285
252
|
```
|
|
286
253
|
|
|
287
|
-
|
|
254
|
+
## UI Component Testing
|
|
288
255
|
|
|
289
256
|
You can use Serenity/JS and Playwright Test to write UI component tests and **reuse your test code** between component and end-to-end test suites.
|
|
290
257
|
|
|
@@ -310,14 +277,14 @@ test('should work', async ({ mount }) => {
|
|
|
310
277
|
})
|
|
311
278
|
```
|
|
312
279
|
|
|
313
|
-
|
|
280
|
+
### Using Serenity/JS actors for Component Testing
|
|
314
281
|
|
|
315
282
|
Serenity/JS [`useBase(test)`](https://serenity-js.org/api/playwright-test/function/useBase/) creates
|
|
316
283
|
a test API that gives you access to all the [`SerenityFixtures`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/)
|
|
317
284
|
you could access in any other regular end-to-end test.
|
|
318
285
|
|
|
319
|
-
This capability allows you to use [Serenity/JS
|
|
320
|
-
and experiment with your [
|
|
286
|
+
This capability allows you to use [Serenity/JS actors](https://serenity-js.org/api/core/class/Actor/) and design
|
|
287
|
+
and experiment with your [tasks](https://serenity-js.org/api/core/class/Task/)
|
|
321
288
|
before incorporating them in your high-level acceptance and end-to-end tests.
|
|
322
289
|
|
|
323
290
|
```tsx
|
|
@@ -349,7 +316,9 @@ describe('EmailInput', () => {
|
|
|
349
316
|
})
|
|
350
317
|
```
|
|
351
318
|
|
|
352
|
-
|
|
319
|
+
Explore the in-depth Serenity/JS and Playwright Test integration guide in the [Serenity/JS Handbook](https://serenity-js.org/handbook/test-runners/playwright-test/).
|
|
320
|
+
|
|
321
|
+
## Reporting
|
|
353
322
|
|
|
354
323
|
To use Serenity/JS reporting capabilities, register the `@serenity-js/playwright-test` reporter in your
|
|
355
324
|
`playwright.config.ts` and define the appropriate reporting services (a.k.a. your "stage crew").
|
|
@@ -364,11 +333,12 @@ npm install --save-dev @serenity-js/console-reporter @serenity-js/serenity-bdd
|
|
|
364
333
|
Next, configure your Playwright project as follows:
|
|
365
334
|
|
|
366
335
|
```typescript
|
|
367
|
-
// playwright.
|
|
336
|
+
// playwright.config.ts
|
|
368
337
|
|
|
369
|
-
import
|
|
338
|
+
import { defineConfig } from '@playwright/test';
|
|
339
|
+
import { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test';
|
|
370
340
|
|
|
371
|
-
|
|
341
|
+
export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
|
|
372
342
|
testDir: './spec',
|
|
373
343
|
|
|
374
344
|
reporter: [
|
|
@@ -387,32 +357,45 @@ const config: PlaywrightTestConfig = {
|
|
|
387
357
|
|
|
388
358
|
// Other configuration omitted for brevity
|
|
389
359
|
// For details, see https://playwright.dev/docs/test-configuration
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
export default config
|
|
360
|
+
})
|
|
393
361
|
```
|
|
394
362
|
|
|
395
|
-
|
|
363
|
+
Serenity/JS reporters work well with native [Playwright reporters](https://playwright.dev/docs/test-reporters).
|
|
396
364
|
|
|
397
|
-
|
|
365
|
+
## Documentation
|
|
398
366
|
|
|
399
|
-
|
|
400
|
-
|
|
367
|
+
- [API Reference](https://serenity-js.org/api/)
|
|
368
|
+
- [Screenplay Pattern Guide](https://serenity-js.org/handbook/design/screenplay-pattern/)
|
|
369
|
+
- [Serenity/JS Project Templates](https://serenity-js.org/handbook/project-templates/)
|
|
370
|
+
- [More examples and reference implementations](https://github.com/serenity-js/serenity-js/tree/main/examples)
|
|
371
|
+
- [Tutorial: First Web Scenario](https://serenity-js.org/handbook/tutorials/your-first-web-scenario/)
|
|
372
|
+
- [Tutorial: First API Scenario](https://serenity-js.org/handbook/tutorials/your-first-api-scenario/)
|
|
401
373
|
|
|
402
|
-
##
|
|
374
|
+
## Contributing
|
|
403
375
|
|
|
404
|
-
|
|
405
|
-
Follow [Serenity/JS on LinkedIn](https://www.linkedin.com/company/serenity-js),
|
|
406
|
-
subscribe to [Serenity/JS channel on YouTube](https://www.youtube.com/@serenity-js) and join the [Serenity/JS Community Chat](https://matrix.to/#/#serenity-js:gitter.im) to stay up to date!
|
|
407
|
-
Please also make sure to star ⭐️ [Serenity/JS on GitHub](https://github.com/serenity-js/serenity-js) to help others discover the framework!
|
|
376
|
+
Contributions of all kinds are welcome! Get started with the [Contributing Guide](https://serenity-js.org/community/contributing/).
|
|
408
377
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
[
|
|
412
|
-
[
|
|
378
|
+
## Community
|
|
379
|
+
|
|
380
|
+
- [Community Chat](https://matrix.to/#/#serenity-js:gitter.im)
|
|
381
|
+
- [Discussions Forum](https://github.com/orgs/serenity-js/discussions)
|
|
382
|
+
- Visit the [💡How to... ?](https://github.com/orgs/serenity-js/discussions/categories/how-to) section for answers to common questions
|
|
383
|
+
|
|
384
|
+
If you enjoy using Serenity/JS, make sure to star ⭐️ [Serenity/JS on GitHub](https://github.com/serenity-js/serenity-js) to help others discover the framework!
|
|
385
|
+
|
|
386
|
+
## License
|
|
387
|
+
|
|
388
|
+
The Serenity/JS code base is licensed under the [Apache-2.0](https://opensource.org/license/apache-2-0) license,
|
|
389
|
+
while its documentation and the [Serenity/JS Handbook](https://serenity-js.org/handbook/) are licensed under the [Creative Commons BY-NC-SA 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/).
|
|
390
|
+
|
|
391
|
+
See the [Serenity/JS License](https://serenity-js.org/legal/license/).
|
|
392
|
+
|
|
393
|
+
## Support
|
|
394
|
+
|
|
395
|
+
Support ongoing development through [GitHub Sponsors](https://github.com/sponsors/serenity-js). Sponsors gain access to [Serenity/JS Playbooks](https://github.com/serenity-js/playbooks)
|
|
396
|
+
and priority help in the [Discussions Forum](https://github.com/orgs/serenity-js/discussions).
|
|
413
397
|
|
|
414
|
-
|
|
398
|
+
For corporate sponsorship or commercial support, please contact [Jan Molak](https://www.linkedin.com/in/janmolak/).
|
|
415
399
|
|
|
416
|
-
|
|
400
|
+
[](https://github.com/sponsors/serenity-js).
|
|
417
401
|
|
|
418
|
-
[](https://github.com/sponsors/serenity-js)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Cast, ClassDescription, Duration, Serenity, StageCrewMember, StageCrewMemberBuilder } from '@serenity-js/core';
|
|
2
|
-
import type { Actor } from '@serenity-js/core';
|
|
1
|
+
import type { Ability, Actor, Cast, ClassDescription, Duration, Serenity, StageCrewMember, StageCrewMemberBuilder } from '@serenity-js/core';
|
|
3
2
|
import type { ExtraBrowserContextOptions } from '@serenity-js/playwright';
|
|
3
|
+
import type { AxiosRequestConfigDefaults } from '@serenity-js/rest';
|
|
4
|
+
import { type AxiosInstance } from 'axios';
|
|
4
5
|
/**
|
|
5
6
|
* Serenity/JS-specific [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
6
7
|
* injected into your [test scenarios](https://serenity-js.org/api/playwright-test/function/it/).
|
|
@@ -227,31 +228,91 @@ export interface SerenityFixtures {
|
|
|
227
228
|
* - [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
228
229
|
*/
|
|
229
230
|
extraContextOptions: Partial<ExtraBrowserContextOptions>;
|
|
231
|
+
/**
|
|
232
|
+
* Extra abilities given to the actors on top of the default ones provided by the [`actors`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actors) fixture.
|
|
233
|
+
*
|
|
234
|
+
* #### Extra abilities for all actors
|
|
235
|
+
*
|
|
236
|
+
* To give the same set of extra abilities to all the actors, make your `extraAbilities` fixture
|
|
237
|
+
* return an array of [`Ability`](https://serenity-js.org/api/core/class/Ability/) objects.
|
|
238
|
+
*
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { type Ability } from '@serenity-js/core';
|
|
241
|
+
* import { describe, it, test } from '@serenity-js/playwright-test';
|
|
242
|
+
* import { MyAbility } from './MyAbility';
|
|
243
|
+
*
|
|
244
|
+
* describe(`My feature`, () => {
|
|
245
|
+
*
|
|
246
|
+
* test.use({
|
|
247
|
+
* extraAbilities: [ new MyAbility() ]
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* it(`...`, async({ actor }) => {
|
|
251
|
+
* // ...
|
|
252
|
+
* });
|
|
253
|
+
* });
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* #### Extra abilities for selected actors
|
|
257
|
+
*
|
|
258
|
+
* To give extra abilities only to selected actors, make your `extraAbilities` fixture return a `(actorName: string) => Ability[]` function that maps
|
|
259
|
+
* the actor name to an array of [`Ability`](https://serenity-js.org/api/core/class/Ability/) objects.
|
|
260
|
+
*
|
|
261
|
+
* ```typescript
|
|
262
|
+
* import { describe, it, test } from '@serenity-js/playwright-test';
|
|
263
|
+
* import { MyAbility } from './MyAbility';
|
|
264
|
+
*
|
|
265
|
+
* describe(`My feature`, () => {
|
|
266
|
+
*
|
|
267
|
+
* test.use({
|
|
268
|
+
* extraAbilities: async ({ }, use) => {
|
|
269
|
+
* await use((actorName: string) => {
|
|
270
|
+
* // Alice gets the extra abilities, but others don't
|
|
271
|
+
* return actorName === 'Alice'
|
|
272
|
+
* ? [ new MyAbility() ]
|
|
273
|
+
* : [];
|
|
274
|
+
* })
|
|
275
|
+
* }
|
|
276
|
+
* });
|
|
277
|
+
*
|
|
278
|
+
* it(`...`, async({ actor }) => {
|
|
279
|
+
* // ...
|
|
280
|
+
* });
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
extraAbilities: ((actorName: string) => Ability[]) | Ability[];
|
|
230
285
|
/**
|
|
231
286
|
* A cast of Serenity/JS actors to be used instead of the default cast
|
|
232
287
|
* when instantiating [`actor`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actor)
|
|
233
288
|
* and invoking [`actorCalled`](https://serenity-js.org/api/playwright-test/interface/SerenityWorkerFixtures/#actorCalled).
|
|
234
289
|
*
|
|
235
290
|
* :::info Did you know?
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* The default abilities should be sufficient in most web testing scenarios. However, you might want to override this default configuration
|
|
240
|
-
* when you need your actors to [interact with REST APIs](https://serenity-js.org/api/rest/class/CallAnApi/),
|
|
241
|
-
* [manage local servers](https://serenity-js.org/api/local-server/class/ManageALocalServer/),
|
|
242
|
-
* start with a notepad that has some [initial state](https://serenity-js.org/api/core/class/TakeNotes/#using),
|
|
243
|
-
* or receive [custom abilities](https://serenity-js.org/api/core/class/Ability/).
|
|
244
|
-
* :::
|
|
291
|
+
* Serenity/JS [test APIs](https://serenity-js.org/api/playwright-test/function/it/) offer fixtures that set up the default cast of actors for you,
|
|
292
|
+
* which should be sufficient in most web and HTTP API testing scenarios.
|
|
245
293
|
*
|
|
294
|
+
* Each one of the default actors receives the following [abilities](https://serenity-js.org/api/core/class/Ability/):
|
|
295
|
+
* - [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/), connected to Playwright [`page`](https://playwright.dev/docs/test-fixtures) fixture
|
|
296
|
+
* - [`TakeNotes`](https://serenity-js.org/api/core/class/TakeNotes/#usingAnEmptyNotepad)
|
|
297
|
+
* - [`CallAnApi`](https://serenity-js.org/api/rest/class/CallAnApi/), pointing at the [`baseURL`](https://playwright.dev/docs/test-use-options#basic-options)
|
|
298
|
+
* and using any `proxy` settings in your Playwright config file.
|
|
299
|
+
*
|
|
300
|
+
* The easiest way to give your actors additional abilities is to use the [`extraAbilities`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#extraAbilities) fixture.
|
|
301
|
+
* :::
|
|
246
302
|
*
|
|
247
303
|
* #### Overriding the default cast of Serenity/JS actors
|
|
248
304
|
*
|
|
249
305
|
* ```typescript
|
|
250
|
-
* import { Cast, TakeNotes } from '@serenity-js/core'
|
|
251
306
|
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
307
|
+
* import { Cast, TakeNotes } from '@serenity-js/core'
|
|
252
308
|
* import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
|
|
309
|
+
* import { CallAnApi } from '@serenity-js/rest'
|
|
253
310
|
* import { describe, it, test } from '@serenity-js/playwright-test'
|
|
254
311
|
*
|
|
312
|
+
* interface MyNotes {
|
|
313
|
+
* username: string;
|
|
314
|
+
* }
|
|
315
|
+
*
|
|
255
316
|
* describe(`Recording items`, () => {
|
|
256
317
|
*
|
|
257
318
|
* test.use({
|
|
@@ -259,17 +320,24 @@ export interface SerenityFixtures {
|
|
|
259
320
|
* defaultNavigationTimeout: 30_000,
|
|
260
321
|
* },
|
|
261
322
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
323
|
+
* actors: async ({ axios, extraAbilities, extraContextOptions, extraHTTPHeaders, page }, use) => {
|
|
324
|
+
* const cast = Cast.where(actor => {
|
|
325
|
+
* const abilities = Array.isArray(extraAbilities)
|
|
326
|
+
* ? extraAbilities
|
|
327
|
+
* : extraAbilities(actor.name);
|
|
328
|
+
*
|
|
329
|
+
* return actor.whoCan(
|
|
330
|
+
* BrowseTheWebWithPlaywright.usingPage(page, extraContextOptions),
|
|
331
|
+
* TakeNotes.using<MyNotes>(Notepad.with({
|
|
332
|
+
* username: 'example.username'
|
|
333
|
+
* }),
|
|
334
|
+
* CallAnApi.using(axios),
|
|
335
|
+
* ...abilities,
|
|
268
336
|
* )
|
|
269
|
-
* )
|
|
337
|
+
* })
|
|
270
338
|
*
|
|
271
339
|
* // Make sure to pass your custom cast to Playwright `use` callback
|
|
272
|
-
* await use(cast)
|
|
340
|
+
* await use(cast);
|
|
273
341
|
* },
|
|
274
342
|
* })
|
|
275
343
|
*
|
|
@@ -307,6 +375,17 @@ export interface SerenityFixtures {
|
|
|
307
375
|
* - Declaring a Serenity/JS [test scenario](https://serenity-js.org/api/playwright-test/function/it/)
|
|
308
376
|
*/
|
|
309
377
|
actor: Actor;
|
|
378
|
+
/**
|
|
379
|
+
* An instance of the Axios HTTP client, or default Axios request configurations,
|
|
380
|
+
* to be used by the [`CallAnApi`](https://serenity-js.org/api/rest/class/CallAnApi/) ability,
|
|
381
|
+
* provided to the actors via the [`actors`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actors) fixture.
|
|
382
|
+
*
|
|
383
|
+
* By default, Serenity/JS configures Axios to use the following settings from your Playwright configuration file:
|
|
384
|
+
* - [`baseURL`](https://playwright.dev/docs/api/class-testoptions#test-options-base-url)
|
|
385
|
+
* - [`proxy`](https://playwright.dev/docs/api/class-testoptions#test-options-proxy)
|
|
386
|
+
* - [`extraHTTPHeaders`](https://playwright.dev/docs/api/class-testoptions#test-options-extra-http-headers)
|
|
387
|
+
*/
|
|
388
|
+
axios: AxiosInstance | AxiosRequestConfigDefaults;
|
|
310
389
|
}
|
|
311
390
|
/**
|
|
312
391
|
* Serenity/JS-specific worker-scope [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
@@ -355,7 +434,9 @@ export interface SerenityWorkerFixtures {
|
|
|
355
434
|
*/
|
|
356
435
|
serenity: Serenity;
|
|
357
436
|
/**
|
|
358
|
-
* Uses the provided [cast](https://serenity-js.org/api/core/class/Cast/) of
|
|
437
|
+
* Uses the provided [cast](https://serenity-js.org/api/core/class/Cast/) of
|
|
438
|
+
* [`actors`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actors) to instantiate
|
|
439
|
+
* an [`Actor`](https://serenity-js.org/api/core/class/Actor/) called `name`
|
|
359
440
|
* and inject it into a [test scenario](https://serenity-js.org/api/playwright-test/function/it/).
|
|
360
441
|
*
|
|
361
442
|
* Retrieves an existing actor if one has already been instantiated.
|