@serenity-js/playwright-test 3.41.1 → 3.42.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 +22 -0
- package/esm/api/PerformActivitiesAsPlaywrightSteps.d.ts +14 -0
- package/esm/api/PerformActivitiesAsPlaywrightSteps.d.ts.map +1 -0
- package/esm/api/PerformActivitiesAsPlaywrightSteps.js +40 -0
- package/esm/api/PerformActivitiesAsPlaywrightSteps.js.map +1 -0
- package/esm/api/PlaywrightTestConfig.d.ts +42 -0
- package/esm/api/PlaywrightTestConfig.d.ts.map +1 -0
- package/esm/api/PlaywrightTestConfig.js +2 -0
- package/esm/api/PlaywrightTestConfig.js.map +1 -0
- package/esm/api/WorkerEventStreamReader.d.ts +13 -0
- package/esm/api/WorkerEventStreamReader.d.ts.map +1 -0
- package/esm/api/WorkerEventStreamReader.js +18 -0
- package/esm/api/WorkerEventStreamReader.js.map +1 -0
- package/esm/api/WorkerEventStreamWriter.d.ts +24 -0
- package/esm/api/WorkerEventStreamWriter.d.ts.map +1 -0
- package/esm/api/WorkerEventStreamWriter.js +79 -0
- package/esm/api/WorkerEventStreamWriter.js.map +1 -0
- package/esm/api/index.d.ts +4 -0
- package/esm/api/index.d.ts.map +1 -0
- package/esm/api/index.js +4 -0
- package/esm/api/index.js.map +1 -0
- package/esm/api/serenity-fixtures.d.ts +452 -0
- package/esm/api/serenity-fixtures.d.ts.map +1 -0
- package/esm/api/serenity-fixtures.js +2 -0
- package/esm/api/serenity-fixtures.js.map +1 -0
- package/esm/api/test-api.d.ts +387 -0
- package/esm/api/test-api.d.ts.map +1 -0
- package/esm/api/test-api.js +521 -0
- package/esm/api/test-api.js.map +1 -0
- package/esm/events/EventFactory.d.ts +16 -0
- package/esm/events/EventFactory.d.ts.map +1 -0
- package/esm/events/EventFactory.js +90 -0
- package/esm/events/EventFactory.js.map +1 -0
- package/esm/events/PlaywrightSceneId.d.ts +7 -0
- package/esm/events/PlaywrightSceneId.d.ts.map +1 -0
- package/esm/events/PlaywrightSceneId.js +15 -0
- package/esm/events/PlaywrightSceneId.js.map +1 -0
- package/esm/events/index.d.ts +3 -0
- package/esm/events/index.d.ts.map +1 -0
- package/esm/events/index.js +3 -0
- package/esm/events/index.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/reporter/PlaywrightErrorParser.d.ts +7 -0
- package/esm/reporter/PlaywrightErrorParser.d.ts.map +1 -0
- package/esm/reporter/PlaywrightErrorParser.js +23 -0
- package/esm/reporter/PlaywrightErrorParser.js.map +1 -0
- package/esm/reporter/PlaywrightEventBuffer.d.ts +25 -0
- package/esm/reporter/PlaywrightEventBuffer.d.ts.map +1 -0
- package/esm/reporter/PlaywrightEventBuffer.js +143 -0
- package/esm/reporter/PlaywrightEventBuffer.js.map +1 -0
- package/esm/reporter/PlaywrightStepReporter.d.ts +14 -0
- package/esm/reporter/PlaywrightStepReporter.d.ts.map +1 -0
- package/esm/reporter/PlaywrightStepReporter.js +38 -0
- package/esm/reporter/PlaywrightStepReporter.js.map +1 -0
- package/esm/reporter/PlaywrightTestSceneIdFactory.d.ts +8 -0
- package/esm/reporter/PlaywrightTestSceneIdFactory.d.ts.map +1 -0
- package/esm/reporter/PlaywrightTestSceneIdFactory.js +11 -0
- package/esm/reporter/PlaywrightTestSceneIdFactory.js.map +1 -0
- package/esm/reporter/SerenityReporterForPlaywrightTest.d.ts +58 -0
- package/esm/reporter/SerenityReporterForPlaywrightTest.d.ts.map +1 -0
- package/esm/reporter/SerenityReporterForPlaywrightTest.js +112 -0
- package/esm/reporter/SerenityReporterForPlaywrightTest.js.map +1 -0
- package/esm/reporter/index.d.ts +3 -0
- package/esm/reporter/index.d.ts.map +1 -0
- package/esm/reporter/index.js +3 -0
- package/esm/reporter/index.js.map +1 -0
- package/lib/api/PerformActivitiesAsPlaywrightSteps.d.ts +1 -1
- package/lib/api/PerformActivitiesAsPlaywrightSteps.d.ts.map +1 -1
- package/lib/api/PerformActivitiesAsPlaywrightSteps.js +2 -2
- package/lib/api/PerformActivitiesAsPlaywrightSteps.js.map +1 -1
- package/lib/api/PlaywrightTestConfig.d.ts +1 -1
- package/lib/api/PlaywrightTestConfig.d.ts.map +1 -1
- package/lib/api/WorkerEventStreamReader.d.ts +1 -1
- package/lib/api/WorkerEventStreamReader.d.ts.map +1 -1
- package/lib/api/WorkerEventStreamReader.js +1 -1
- package/lib/api/WorkerEventStreamReader.js.map +1 -1
- package/lib/api/WorkerEventStreamWriter.d.ts +2 -2
- package/lib/api/WorkerEventStreamWriter.d.ts.map +1 -1
- package/lib/api/WorkerEventStreamWriter.js +1 -1
- package/lib/api/WorkerEventStreamWriter.js.map +1 -1
- package/lib/api/index.d.ts +3 -3
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +3 -3
- package/lib/api/index.js.map +1 -1
- package/lib/api/test-api.d.ts +3 -3
- package/lib/api/test-api.d.ts.map +1 -1
- package/lib/api/test-api.js +12 -12
- package/lib/api/test-api.js.map +1 -1
- package/lib/events/EventFactory.d.ts +3 -3
- package/lib/events/EventFactory.d.ts.map +1 -1
- package/lib/events/EventFactory.js +6 -6
- package/lib/events/EventFactory.js.map +1 -1
- package/lib/events/PlaywrightSceneId.d.ts +1 -1
- package/lib/events/PlaywrightSceneId.d.ts.map +1 -1
- package/lib/events/PlaywrightSceneId.js +1 -1
- package/lib/events/PlaywrightSceneId.js.map +1 -1
- package/lib/events/index.d.ts +2 -2
- package/lib/events/index.d.ts.map +1 -1
- package/lib/events/index.js +2 -2
- package/lib/events/index.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -0
- package/lib/reporter/PlaywrightEventBuffer.d.ts +1 -1
- package/lib/reporter/PlaywrightEventBuffer.d.ts.map +1 -1
- package/lib/reporter/PlaywrightEventBuffer.js +12 -12
- package/lib/reporter/PlaywrightEventBuffer.js.map +1 -1
- package/lib/reporter/PlaywrightStepReporter.d.ts +1 -1
- package/lib/reporter/PlaywrightStepReporter.d.ts.map +1 -1
- package/lib/reporter/PlaywrightStepReporter.js +2 -2
- package/lib/reporter/PlaywrightStepReporter.js.map +1 -1
- package/lib/reporter/PlaywrightTestSceneIdFactory.d.ts +2 -2
- package/lib/reporter/PlaywrightTestSceneIdFactory.d.ts.map +1 -1
- package/lib/reporter/PlaywrightTestSceneIdFactory.js +1 -1
- package/lib/reporter/PlaywrightTestSceneIdFactory.js.map +1 -1
- package/lib/reporter/SerenityReporterForPlaywrightTest.d.ts +1 -1
- package/lib/reporter/SerenityReporterForPlaywrightTest.d.ts.map +1 -1
- package/lib/reporter/SerenityReporterForPlaywrightTest.js +8 -8
- package/lib/reporter/SerenityReporterForPlaywrightTest.js.map +1 -1
- package/lib/reporter/index.d.ts +2 -2
- package/lib/reporter/index.d.ts.map +1 -1
- package/lib/reporter/index.js +2 -2
- package/lib/reporter/index.js.map +1 -1
- package/package.json +58 -10
- package/src/api/PerformActivitiesAsPlaywrightSteps.ts +2 -2
- package/src/api/PlaywrightTestConfig.ts +1 -1
- package/src/api/WorkerEventStreamReader.ts +2 -2
- package/src/api/WorkerEventStreamWriter.ts +2 -2
- package/src/api/index.ts +3 -3
- package/src/api/test-api.ts +8 -8
- package/src/events/EventFactory.ts +5 -5
- package/src/events/PlaywrightSceneId.ts +1 -1
- package/src/events/index.ts +2 -2
- package/src/index.ts +2 -2
- package/src/reporter/PlaywrightEventBuffer.ts +8 -8
- package/src/reporter/PlaywrightStepReporter.ts +4 -4
- package/src/reporter/PlaywrightTestSceneIdFactory.ts +2 -2
- package/src/reporter/SerenityReporterForPlaywrightTest.ts +6 -6
- package/src/reporter/index.ts +2 -2
- package/tsconfig-cjs.build.json +18 -0
- package/tsconfig-esm.build.json +18 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import type { Ability, Actor, Cast, ClassDescription, Duration, Serenity, StageCrewMember, StageCrewMemberBuilder } from '@serenity-js/core';
|
|
2
|
+
import type { ExtraBrowserContextOptions } from '@serenity-js/playwright';
|
|
3
|
+
import type { AxiosRequestConfigDefaults } from '@serenity-js/rest';
|
|
4
|
+
import { type AxiosInstance } from 'axios';
|
|
5
|
+
/**
|
|
6
|
+
* Serenity/JS-specific [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
7
|
+
* injected into your [test scenarios](https://serenity-js.org/api/playwright-test/function/it/).
|
|
8
|
+
*
|
|
9
|
+
* ### Configuring Serenity/JS using a test file
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
13
|
+
* import { describe, it, test } from '@serenity-js/playwright-test'
|
|
14
|
+
* import { Photographer, TakePhotosOfFailures } from '@serenity-js/web'
|
|
15
|
+
*
|
|
16
|
+
* describe(`Recording items`, () => {
|
|
17
|
+
*
|
|
18
|
+
* test.use({
|
|
19
|
+
* defaultActorName: 'Serena',
|
|
20
|
+
* crew: [
|
|
21
|
+
* Photographer.whoWill(TakePhotosOfFailures),
|
|
22
|
+
* ],
|
|
23
|
+
*
|
|
24
|
+
* // Register a custom cast of Serenity/JS actors to replace the default one
|
|
25
|
+
* actors: async ({ browser, contextOptions, extraContextOptions, baseURL }, use) => {
|
|
26
|
+
* const cast = Cast.where(actor =>
|
|
27
|
+
* actor.whoCan(
|
|
28
|
+
* BrowseTheWebWithPlaywright.using(browser, contextOptions, extraContextOptions),
|
|
29
|
+
* TakeNotes.usingAnEmptyNotepad(),
|
|
30
|
+
* CallAnApi.at(baseURL),
|
|
31
|
+
* )
|
|
32
|
+
* )
|
|
33
|
+
*
|
|
34
|
+
* await use(cast)
|
|
35
|
+
* },
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* describe(`Todo List App`, () => {
|
|
39
|
+
*
|
|
40
|
+
* it(`should allow me to add a todo item`, async ({ actor }) => {
|
|
41
|
+
* await actor.attemptsTo(
|
|
42
|
+
* startWithAnEmptyList(),
|
|
43
|
+
*
|
|
44
|
+
* recordItem('Buy some milk'),
|
|
45
|
+
*
|
|
46
|
+
* Ensure.that(itemNames(), equals([
|
|
47
|
+
* 'Buy some milk',
|
|
48
|
+
* ])),
|
|
49
|
+
* )
|
|
50
|
+
* })
|
|
51
|
+
* })
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* ### Configuring Serenity/JS using Playwright configuration file
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // playwright.config.ts
|
|
59
|
+
* import { defineConfig } from '@playwright/test'
|
|
60
|
+
* import type { Cast, TakeNotes } from '@serenity-js/core'
|
|
61
|
+
* import type { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
|
|
62
|
+
* import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
|
|
63
|
+
* import type { CallAnApi } from '@serenity-js/rest'
|
|
64
|
+
*
|
|
65
|
+
* export default defineConfig<SerenityFixtures & MyCustomOptions, SerenityWorkerFixtures> = {
|
|
66
|
+
*
|
|
67
|
+
* // Register Serenity/JS reporter for Playwright Test
|
|
68
|
+
* // to enable integration with Serenity/JS stage crew members
|
|
69
|
+
* // and have them instantiated in the Playwright reporter process
|
|
70
|
+
* reporter: [
|
|
71
|
+
* [ '@serenity-js/playwright-test', {
|
|
72
|
+
* // Stage crew members instantiated in the test reporter process
|
|
73
|
+
* crew: [
|
|
74
|
+
* '@serenity-js/serenity-bdd',
|
|
75
|
+
* '@serenity-js/console-reporter',
|
|
76
|
+
* [ '@serenity-js/core:ArtifactArchiver', { outputDirectory: 'target/site/serenity' } ],
|
|
77
|
+
* ]
|
|
78
|
+
* }]
|
|
79
|
+
* ],
|
|
80
|
+
*
|
|
81
|
+
* use: {
|
|
82
|
+
*
|
|
83
|
+
* // Register Serenity/JS stage crew members
|
|
84
|
+
* // and have them instantiated in Playwright Test worker processes
|
|
85
|
+
* crew: [
|
|
86
|
+
* [ '@serenity-js/web:Photographer', { strategy: 'TakePhotosOfFailures' } ]
|
|
87
|
+
* ],
|
|
88
|
+
*
|
|
89
|
+
* // Name to be given to an actor injected via `actor` fixture
|
|
90
|
+
* defaultActorName: 'Alice',
|
|
91
|
+
*
|
|
92
|
+
* // Any other Playwright options
|
|
93
|
+
* baseURL: 'https://todo-app.serenity-js.org/',
|
|
94
|
+
* video: 'on-first-retry',
|
|
95
|
+
* trace: 'on-first-retry',
|
|
96
|
+
* },
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* ## Learn more
|
|
101
|
+
* - [Using Serenity/JS with Playwright Test](https://serenity-js.org/handbook/test-runners/playwright-test/)
|
|
102
|
+
* - [`PlaywrightTestConfig`](https://serenity-js.org/api/playwright-test/#PlaywrightTestConfig)
|
|
103
|
+
* - [`Cast`](https://serenity-js.org/api/core/class/Cast/)
|
|
104
|
+
* - [`SerenityFixtures`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/)
|
|
105
|
+
*/
|
|
106
|
+
export interface SerenityFixtures {
|
|
107
|
+
/**
|
|
108
|
+
* Configures the name given to the default Serenity/JS [`actor`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actor)
|
|
109
|
+
* injected into a [test scenario](https://serenity-js.org/api/playwright-test/function/it/).
|
|
110
|
+
*
|
|
111
|
+
* #### Learn more
|
|
112
|
+
* - Declaring a Serenity/JS [test scenario](https://serenity-js.org/api/playwright-test/function/it/)
|
|
113
|
+
* - [`SerenityFixtures`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/)
|
|
114
|
+
*/
|
|
115
|
+
defaultActorName: string;
|
|
116
|
+
/**
|
|
117
|
+
* Configures the [stage crew members](https://serenity-js.org/api/core/class/SerenityConfig/#crew)
|
|
118
|
+
* to be instantiated in Playwright Test worker processes.
|
|
119
|
+
*
|
|
120
|
+
* :::info Did you know?
|
|
121
|
+
* By default, Serenity/JS registers a [`Photographer`](https://serenity-js.org/api/web/class/Photographer/).whoWill([`TakePhotosOfFailures`](https://serenity-js.org/api/web/class/TakePhotosOfFailures/)),
|
|
122
|
+
* so that any test failures are automatically accompanied by a screenshot.
|
|
123
|
+
*
|
|
124
|
+
* If you prefer a different behaviour, you can configure the `crew` with an empty array to disable taking screenshots altogether (`crew: []`),
|
|
125
|
+
* or with a [`Photographer`](https://serenity-js.org/api/web/class/Photographer/) who uses a different [`PhotoTakingStrategy`](https://serenity-js.org/api/web/class/PhotoTakingStrategy/), like to [`TakePhotosOfInteractions`](https://serenity-js.org/api/web/class/TakePhotosOfInteractions/).
|
|
126
|
+
* :::
|
|
127
|
+
*
|
|
128
|
+
* #### Example
|
|
129
|
+
*
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // playwright.config.ts
|
|
132
|
+
* import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
|
|
133
|
+
* import { defineConfig } from '@playwright/test'
|
|
134
|
+
*
|
|
135
|
+
* export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
|
|
136
|
+
* use: {
|
|
137
|
+
* crew: [
|
|
138
|
+
* [ '@serenity-js/web:Photographer', { strategy: 'TakePhotosOfFailures' } ]
|
|
139
|
+
* ],
|
|
140
|
+
* },
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* #### Learn more
|
|
145
|
+
* - [`SerenityConfig.crew`](https://serenity-js.org/api/core/class/SerenityConfig/#crew)
|
|
146
|
+
*/
|
|
147
|
+
crew: Array<ClassDescription | StageCrewMember | StageCrewMemberBuilder>;
|
|
148
|
+
/**
|
|
149
|
+
* Sets the [`cueTimeout`](https://serenity-js.org/api/core/class/SerenityConfig/#cueTimeout) to a given [duration](https://serenity-js.org/api/core/class/Duration/) or a numeric value in milliseconds.
|
|
150
|
+
* Defaults to **5 seconds**.
|
|
151
|
+
*
|
|
152
|
+
* #### Learn more
|
|
153
|
+
* - [`SerenityConfig.cueTimeout`](https://serenity-js.org/api/core/class/SerenityConfig/#cueTimeout)
|
|
154
|
+
* - [`Discardable`](https://serenity-js.org/api/core/interface/Discardable/)
|
|
155
|
+
* - [`Ability`](https://serenity-js.org/api/core/class/Ability/)
|
|
156
|
+
*/
|
|
157
|
+
cueTimeout: number | Duration;
|
|
158
|
+
/**
|
|
159
|
+
* The maximum default amount of time allowed for interactions such as [`Wait.until`](https://serenity-js.org/api/core/class/Wait/#until)
|
|
160
|
+
* to complete.
|
|
161
|
+
*
|
|
162
|
+
* Defaults to **5 seconds**, can be overridden per interaction.
|
|
163
|
+
*
|
|
164
|
+
* #### Learn more
|
|
165
|
+
* - [`Wait.until`](https://serenity-js.org/api/core/class/Wait/#until)
|
|
166
|
+
*/
|
|
167
|
+
interactionTimeout: number | Duration;
|
|
168
|
+
/**
|
|
169
|
+
* Convenience properties to be used with the [ability](https://serenity-js.org/api/core/class/Ability/)
|
|
170
|
+
* to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/),
|
|
171
|
+
* in addition to Playwright [BrowserContextOptions](https://playwright.dev/docs/api/class-testoptions#test-options-context-options):
|
|
172
|
+
*
|
|
173
|
+
* - [`defaultNavigationTimeout`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/#defaultNavigationTimeout)
|
|
174
|
+
* - [`defaultNavigationWaitUntil`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/#defaultNavigationWaitUntil)
|
|
175
|
+
* - [`defaultTimeout`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/#defaultTimeout)
|
|
176
|
+
*
|
|
177
|
+
* #### Using `extraContextOptions` with the default cast of Serenity/JS actors
|
|
178
|
+
*
|
|
179
|
+
* ```typescript
|
|
180
|
+
* // playwright.config.ts
|
|
181
|
+
* import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
|
|
182
|
+
* import { defineConfig } from '@playwright/test'
|
|
183
|
+
*
|
|
184
|
+
* export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
|
|
185
|
+
* use: {
|
|
186
|
+
* extraContextOptions: {
|
|
187
|
+
* defaultNavigationTimeout: 30_000,
|
|
188
|
+
* }
|
|
189
|
+
*
|
|
190
|
+
* // Since `actors` property is not defined,
|
|
191
|
+
* // `extraContextOptions` will be passed to the default cast of Serenity/JS actors
|
|
192
|
+
* // and injected into the ability to `BrowseTheWebWithPlaywright`
|
|
193
|
+
* // that each actor receives.
|
|
194
|
+
* },
|
|
195
|
+
* })
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* #### Using `extraContextOptions` with a custom cast of Serenity/JS actors
|
|
199
|
+
*
|
|
200
|
+
* ```typescript
|
|
201
|
+
* // playwright.config.ts
|
|
202
|
+
* import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
|
|
203
|
+
* import { defineConfig } from '@playwright/test'
|
|
204
|
+
*
|
|
205
|
+
* export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
|
|
206
|
+
* use: {
|
|
207
|
+
* extraContextOptions: {
|
|
208
|
+
* defaultNavigationTimeout: 30_000,
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* // Custom cast of actors receives the default `contextOptions` and
|
|
212
|
+
* // the `extraContextOptions` with the additional Serenity/JS properties.
|
|
213
|
+
* actors: async ({ browser, contextOptions, extraContextOptions }, use) => {
|
|
214
|
+
* const cast = Cast.where(actor => actor.whoCan(
|
|
215
|
+
* BrowseTheWebWithPlaywright.using(browser, contextOptions, extraContextOptions),
|
|
216
|
+
* TakeNotes.usingAnEmptyNotepad(),
|
|
217
|
+
* ))
|
|
218
|
+
*
|
|
219
|
+
* await use(cast)
|
|
220
|
+
* },
|
|
221
|
+
* },
|
|
222
|
+
* })
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* #### Learn more
|
|
226
|
+
* - [`SerenityFixtures`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/)
|
|
227
|
+
* - [Playwright Browser Context options](https://playwright.dev/docs/api/class-testoptions#test-options-context-options)
|
|
228
|
+
* - [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
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[];
|
|
285
|
+
/**
|
|
286
|
+
* A cast of Serenity/JS actors to be used instead of the default cast
|
|
287
|
+
* when instantiating [`actor`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actor)
|
|
288
|
+
* and invoking [`actorCalled`](https://serenity-js.org/api/playwright-test/interface/SerenityWorkerFixtures/#actorCalled).
|
|
289
|
+
*
|
|
290
|
+
* :::info Did you know?
|
|
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.
|
|
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
|
+
* :::
|
|
302
|
+
*
|
|
303
|
+
* #### Overriding the default cast of Serenity/JS actors
|
|
304
|
+
*
|
|
305
|
+
* ```typescript
|
|
306
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
307
|
+
* import { Cast, TakeNotes } from '@serenity-js/core'
|
|
308
|
+
* import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
|
|
309
|
+
* import { CallAnApi } from '@serenity-js/rest'
|
|
310
|
+
* import { describe, it, test } from '@serenity-js/playwright-test'
|
|
311
|
+
*
|
|
312
|
+
* interface MyNotes {
|
|
313
|
+
* username: string;
|
|
314
|
+
* }
|
|
315
|
+
*
|
|
316
|
+
* describe(`Recording items`, () => {
|
|
317
|
+
*
|
|
318
|
+
* test.use({
|
|
319
|
+
* extraContextOptions: {
|
|
320
|
+
* defaultNavigationTimeout: 30_000,
|
|
321
|
+
* },
|
|
322
|
+
*
|
|
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,
|
|
336
|
+
* )
|
|
337
|
+
* })
|
|
338
|
+
*
|
|
339
|
+
* // Make sure to pass your custom cast to Playwright `use` callback
|
|
340
|
+
* await use(cast);
|
|
341
|
+
* },
|
|
342
|
+
* })
|
|
343
|
+
*
|
|
344
|
+
* describe(`Todo List App`, () => {
|
|
345
|
+
*
|
|
346
|
+
* it(`should allow me to add a todo item`, async ({ actor }) => {
|
|
347
|
+
* await actor.attemptsTo(
|
|
348
|
+
* startWithAnEmptyList(),
|
|
349
|
+
*
|
|
350
|
+
* recordItem('Buy some milk'),
|
|
351
|
+
*
|
|
352
|
+
* Ensure.that(itemNames(), equals([
|
|
353
|
+
* 'Buy some milk',
|
|
354
|
+
* ])),
|
|
355
|
+
* )
|
|
356
|
+
* })
|
|
357
|
+
* })
|
|
358
|
+
* })
|
|
359
|
+
* ```
|
|
360
|
+
*
|
|
361
|
+
* #### Learn more
|
|
362
|
+
* - Declaring a Serenity/JS [test scenario](https://serenity-js.org/api/playwright-test/function/it/)
|
|
363
|
+
* - [`SerenityFixtures`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/)
|
|
364
|
+
*/
|
|
365
|
+
actors: Cast;
|
|
366
|
+
/**
|
|
367
|
+
* Default [`actor`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actor) injected into a [test scenario](https://serenity-js.org/api/playwright-test/function/it/).
|
|
368
|
+
*
|
|
369
|
+
* Using `actor` fixture is equivalent to invoking [`actorCalled`](https://serenity-js.org/api/playwright-test/interface/SerenityWorkerFixtures/#actorCalled)
|
|
370
|
+
* with [`defaultActorName`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#defaultActorName).
|
|
371
|
+
*
|
|
372
|
+
* #### Learn more
|
|
373
|
+
* - [`actorCalled`](https://serenity-js.org/api/playwright-test/interface/SerenityWorkerFixtures/#actorCalled)
|
|
374
|
+
* - [`defaultActorName`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#defaultActorName)
|
|
375
|
+
* - Declaring a Serenity/JS [test scenario](https://serenity-js.org/api/playwright-test/function/it/)
|
|
376
|
+
*/
|
|
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;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Serenity/JS-specific worker-scope [Playwright Test fixtures](https://playwright.dev/docs/test-fixtures)
|
|
392
|
+
* injected into your [test scenarios](https://serenity-js.org/api/playwright-test/function/it/).
|
|
393
|
+
*
|
|
394
|
+
* ## Example test scenario
|
|
395
|
+
*
|
|
396
|
+
* ```typescript
|
|
397
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
398
|
+
* import { beforeAll, describe, it } from '@serenity-js/playwright-test'
|
|
399
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
400
|
+
*
|
|
401
|
+
* describe('GitHub', () => {
|
|
402
|
+
*
|
|
403
|
+
* beforeAll('Ensure system is ready to test', async ({ actorCalled }) => {
|
|
404
|
+
* await actorCalled('Stagehand')
|
|
405
|
+
* .whoCan(CallAnApi.at('https://www.githubstatus.com/api/v2/'))
|
|
406
|
+
* .attemptsTo(
|
|
407
|
+
* Send.a(GetRequest.to('status.json')),
|
|
408
|
+
* Ensure.that(
|
|
409
|
+
* LastResponse.status(),
|
|
410
|
+
* equals(200)
|
|
411
|
+
* ),
|
|
412
|
+
* Ensure.that(
|
|
413
|
+
* LastResponse.body().status.description,
|
|
414
|
+
* equals('All Systems Operational')
|
|
415
|
+
* ),
|
|
416
|
+
* );
|
|
417
|
+
* });
|
|
418
|
+
* });
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* ## Learn more
|
|
422
|
+
* - [Using Serenity/JS with Playwright Test](https://serenity-js.org/handbook/test-runners/playwright-test/)
|
|
423
|
+
*/
|
|
424
|
+
export interface SerenityWorkerFixtures {
|
|
425
|
+
/**
|
|
426
|
+
* Name and version of the operating system that Playwright Test worker process runs on.
|
|
427
|
+
*/
|
|
428
|
+
platform: {
|
|
429
|
+
name: string;
|
|
430
|
+
version: string;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Retrieves the root object of the Serenity/JS framework.
|
|
434
|
+
*/
|
|
435
|
+
serenity: Serenity;
|
|
436
|
+
/**
|
|
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`
|
|
440
|
+
* and inject it into a [test scenario](https://serenity-js.org/api/playwright-test/function/it/).
|
|
441
|
+
*
|
|
442
|
+
* Retrieves an existing actor if one has already been instantiated.
|
|
443
|
+
*
|
|
444
|
+
* #### Learn more
|
|
445
|
+
* - Declaring a Serenity/JS [test scenario](https://serenity-js.org/api/playwright-test/function/it/)
|
|
446
|
+
* - [`SerenityFixtures.actors`](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/#actors)
|
|
447
|
+
*
|
|
448
|
+
* @param name
|
|
449
|
+
*/
|
|
450
|
+
actorCalled: (name: string) => Actor;
|
|
451
|
+
}
|
|
452
|
+
//# sourceMappingURL=serenity-fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serenity-fixtures.d.ts","sourceRoot":"","sources":["../../src/api/serenity-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,OAAO,EACP,KAAK,EACL,IAAI,EACJ,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,sBAAsB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AACH,MAAM,WAAW,gBAAgB;IAE7B;;;;;;;OAOG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,IAAI,EAAE,KAAK,CAAC,gBAAgB,GAAG,eAAe,GAAG,sBAAsB,CAAC,CAAC;IAEzE;;;;;;;;OAQG;IACH,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC;IAE9B;;;;;;;;OAQG;IACH,kBAAkB,EAAE,MAAM,GAAG,QAAQ,CAAC;IAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6DG;IACH,mBAAmB,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDG;IACH,cAAc,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC;IAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+EG;IACH,MAAM,EAAE,IAAI,CAAC;IAEb;;;;;;;;;;OAUG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;;;;;;;;OASG;IACH,KAAK,EAAE,aAAa,GAAG,0BAA0B,CAAC;CACrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,sBAAsB;IACnC;;OAEG;IACH,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAE5C;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;;;;;;;;;;;;OAaG;IACH,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serenity-fixtures.js","sourceRoot":"","sources":["../../src/api/serenity-fixtures.ts"],"names":[],"mappings":""}
|