@serenity-js/playwright 3.41.2 → 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.
Files changed (154) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/esm/ExtraBrowserContextOptions.d.ts +36 -0
  3. package/esm/ExtraBrowserContextOptions.d.ts.map +1 -0
  4. package/esm/ExtraBrowserContextOptions.js +2 -0
  5. package/esm/ExtraBrowserContextOptions.js.map +1 -0
  6. package/esm/index.d.ts +4 -0
  7. package/esm/index.d.ts.map +1 -0
  8. package/esm/index.js +4 -0
  9. package/esm/index.js.map +1 -0
  10. package/esm/screenplay/abilities/BrowseTheWebWithPlaywright.d.ts +163 -0
  11. package/esm/screenplay/abilities/BrowseTheWebWithPlaywright.d.ts.map +1 -0
  12. package/esm/screenplay/abilities/BrowseTheWebWithPlaywright.js +168 -0
  13. package/esm/screenplay/abilities/BrowseTheWebWithPlaywright.js.map +1 -0
  14. package/esm/screenplay/abilities/index.d.ts +2 -0
  15. package/esm/screenplay/abilities/index.d.ts.map +1 -0
  16. package/esm/screenplay/abilities/index.js +2 -0
  17. package/esm/screenplay/abilities/index.js.map +1 -0
  18. package/esm/screenplay/index.d.ts +3 -0
  19. package/esm/screenplay/index.d.ts.map +1 -0
  20. package/esm/screenplay/index.js +3 -0
  21. package/esm/screenplay/index.js.map +1 -0
  22. package/esm/screenplay/models/PlaywrightBrowsingSession.d.ts +32 -0
  23. package/esm/screenplay/models/PlaywrightBrowsingSession.d.ts.map +1 -0
  24. package/esm/screenplay/models/PlaywrightBrowsingSession.js +54 -0
  25. package/esm/screenplay/models/PlaywrightBrowsingSession.js.map +1 -0
  26. package/esm/screenplay/models/PlaywrightBrowsingSessionWithBrowser.d.ts +18 -0
  27. package/esm/screenplay/models/PlaywrightBrowsingSessionWithBrowser.d.ts.map +1 -0
  28. package/esm/screenplay/models/PlaywrightBrowsingSessionWithBrowser.js +38 -0
  29. package/esm/screenplay/models/PlaywrightBrowsingSessionWithBrowser.js.map +1 -0
  30. package/esm/screenplay/models/PlaywrightBrowsingSessionWithPage.d.ts +21 -0
  31. package/esm/screenplay/models/PlaywrightBrowsingSessionWithPage.d.ts.map +1 -0
  32. package/esm/screenplay/models/PlaywrightBrowsingSessionWithPage.js +44 -0
  33. package/esm/screenplay/models/PlaywrightBrowsingSessionWithPage.js.map +1 -0
  34. package/esm/screenplay/models/PlaywrightCookie.d.ts +15 -0
  35. package/esm/screenplay/models/PlaywrightCookie.d.ts.map +1 -0
  36. package/esm/screenplay/models/PlaywrightCookie.js +41 -0
  37. package/esm/screenplay/models/PlaywrightCookie.js.map +1 -0
  38. package/esm/screenplay/models/PlaywrightModalDialogHandler.d.ts +19 -0
  39. package/esm/screenplay/models/PlaywrightModalDialogHandler.d.ts.map +1 -0
  40. package/esm/screenplay/models/PlaywrightModalDialogHandler.js +48 -0
  41. package/esm/screenplay/models/PlaywrightModalDialogHandler.js.map +1 -0
  42. package/esm/screenplay/models/PlaywrightPage.d.ts +54 -0
  43. package/esm/screenplay/models/PlaywrightPage.d.ts.map +1 -0
  44. package/esm/screenplay/models/PlaywrightPage.js +190 -0
  45. package/esm/screenplay/models/PlaywrightPage.js.map +1 -0
  46. package/esm/screenplay/models/PlaywrightPageElement.d.ts +33 -0
  47. package/esm/screenplay/models/PlaywrightPageElement.d.ts.map +1 -0
  48. package/esm/screenplay/models/PlaywrightPageElement.js +198 -0
  49. package/esm/screenplay/models/PlaywrightPageElement.js.map +1 -0
  50. package/esm/screenplay/models/index.d.ts +8 -0
  51. package/esm/screenplay/models/index.d.ts.map +1 -0
  52. package/esm/screenplay/models/index.js +8 -0
  53. package/esm/screenplay/models/index.js.map +1 -0
  54. package/esm/screenplay/models/locators/PlaywrightLocator.d.ts +31 -0
  55. package/esm/screenplay/models/locators/PlaywrightLocator.d.ts.map +1 -0
  56. package/esm/screenplay/models/locators/PlaywrightLocator.js +166 -0
  57. package/esm/screenplay/models/locators/PlaywrightLocator.js.map +1 -0
  58. package/esm/screenplay/models/locators/PlaywrightRootLocator.d.ts +39 -0
  59. package/esm/screenplay/models/locators/PlaywrightRootLocator.d.ts.map +1 -0
  60. package/esm/screenplay/models/locators/PlaywrightRootLocator.js +48 -0
  61. package/esm/screenplay/models/locators/PlaywrightRootLocator.js.map +1 -0
  62. package/esm/screenplay/models/locators/index.d.ts +3 -0
  63. package/esm/screenplay/models/locators/index.d.ts.map +1 -0
  64. package/esm/screenplay/models/locators/index.js +3 -0
  65. package/esm/screenplay/models/locators/index.js.map +1 -0
  66. package/esm/screenplay/promised.d.ts +10 -0
  67. package/esm/screenplay/promised.d.ts.map +1 -0
  68. package/esm/screenplay/promised.js +12 -0
  69. package/esm/screenplay/promised.js.map +1 -0
  70. package/esm/selector-engines/PlaywrightSelectorEngine.d.ts +5 -0
  71. package/esm/selector-engines/PlaywrightSelectorEngine.d.ts.map +1 -0
  72. package/esm/selector-engines/PlaywrightSelectorEngine.js +2 -0
  73. package/esm/selector-engines/PlaywrightSelectorEngine.js.map +1 -0
  74. package/esm/selector-engines/SerenitySelectorEngines.d.ts +14 -0
  75. package/esm/selector-engines/SerenitySelectorEngines.d.ts.map +1 -0
  76. package/esm/selector-engines/SerenitySelectorEngines.js +40 -0
  77. package/esm/selector-engines/SerenitySelectorEngines.js.map +1 -0
  78. package/esm/selector-engines/index.d.ts +2 -0
  79. package/esm/selector-engines/index.d.ts.map +1 -0
  80. package/esm/selector-engines/index.js +2 -0
  81. package/esm/selector-engines/index.js.map +1 -0
  82. package/lib/index.d.ts +3 -3
  83. package/lib/index.d.ts.map +1 -1
  84. package/lib/index.js +3 -3
  85. package/lib/index.js.map +1 -1
  86. package/lib/package.json +1 -0
  87. package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.d.ts +1 -1
  88. package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.d.ts.map +1 -1
  89. package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.js +3 -3
  90. package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.js.map +1 -1
  91. package/lib/screenplay/abilities/index.d.ts +1 -1
  92. package/lib/screenplay/abilities/index.d.ts.map +1 -1
  93. package/lib/screenplay/abilities/index.js +1 -1
  94. package/lib/screenplay/abilities/index.js.map +1 -1
  95. package/lib/screenplay/index.d.ts +2 -2
  96. package/lib/screenplay/index.d.ts.map +1 -1
  97. package/lib/screenplay/index.js +2 -2
  98. package/lib/screenplay/index.js.map +1 -1
  99. package/lib/screenplay/models/PlaywrightBrowsingSession.d.ts +3 -3
  100. package/lib/screenplay/models/PlaywrightBrowsingSession.d.ts.map +1 -1
  101. package/lib/screenplay/models/PlaywrightBrowsingSession.js +7 -6
  102. package/lib/screenplay/models/PlaywrightBrowsingSession.js.map +1 -1
  103. package/lib/screenplay/models/PlaywrightBrowsingSessionWithBrowser.d.ts +3 -3
  104. package/lib/screenplay/models/PlaywrightBrowsingSessionWithBrowser.d.ts.map +1 -1
  105. package/lib/screenplay/models/PlaywrightBrowsingSessionWithBrowser.js +2 -2
  106. package/lib/screenplay/models/PlaywrightBrowsingSessionWithBrowser.js.map +1 -1
  107. package/lib/screenplay/models/PlaywrightBrowsingSessionWithPage.d.ts +3 -3
  108. package/lib/screenplay/models/PlaywrightBrowsingSessionWithPage.d.ts.map +1 -1
  109. package/lib/screenplay/models/PlaywrightBrowsingSessionWithPage.js +5 -5
  110. package/lib/screenplay/models/PlaywrightBrowsingSessionWithPage.js.map +1 -1
  111. package/lib/screenplay/models/PlaywrightPage.d.ts +3 -3
  112. package/lib/screenplay/models/PlaywrightPage.d.ts.map +1 -1
  113. package/lib/screenplay/models/PlaywrightPage.js +11 -11
  114. package/lib/screenplay/models/PlaywrightPage.js.map +1 -1
  115. package/lib/screenplay/models/PlaywrightPageElement.js +1 -1
  116. package/lib/screenplay/models/PlaywrightPageElement.js.map +1 -1
  117. package/lib/screenplay/models/index.d.ts +7 -7
  118. package/lib/screenplay/models/index.d.ts.map +1 -1
  119. package/lib/screenplay/models/index.js +7 -7
  120. package/lib/screenplay/models/index.js.map +1 -1
  121. package/lib/screenplay/models/locators/PlaywrightLocator.d.ts +1 -1
  122. package/lib/screenplay/models/locators/PlaywrightLocator.d.ts.map +1 -1
  123. package/lib/screenplay/models/locators/PlaywrightLocator.js +8 -8
  124. package/lib/screenplay/models/locators/PlaywrightLocator.js.map +1 -1
  125. package/lib/screenplay/models/locators/PlaywrightRootLocator.d.ts +2 -1
  126. package/lib/screenplay/models/locators/PlaywrightRootLocator.d.ts.map +1 -1
  127. package/lib/screenplay/models/locators/PlaywrightRootLocator.js +2 -2
  128. package/lib/screenplay/models/locators/PlaywrightRootLocator.js.map +1 -1
  129. package/lib/screenplay/models/locators/index.d.ts +2 -2
  130. package/lib/screenplay/models/locators/index.d.ts.map +1 -1
  131. package/lib/screenplay/models/locators/index.js +2 -2
  132. package/lib/screenplay/models/locators/index.js.map +1 -1
  133. package/lib/selector-engines/index.d.ts +1 -1
  134. package/lib/selector-engines/index.d.ts.map +1 -1
  135. package/lib/selector-engines/index.js +1 -1
  136. package/lib/selector-engines/index.js.map +1 -1
  137. package/package.json +23 -7
  138. package/src/index.ts +3 -3
  139. package/src/screenplay/abilities/BrowseTheWebWithPlaywright.ts +2 -2
  140. package/src/screenplay/abilities/index.ts +1 -1
  141. package/src/screenplay/index.ts +2 -2
  142. package/src/screenplay/models/PlaywrightBrowsingSession.ts +5 -4
  143. package/src/screenplay/models/PlaywrightBrowsingSessionWithBrowser.ts +3 -3
  144. package/src/screenplay/models/PlaywrightBrowsingSessionWithPage.ts +4 -4
  145. package/src/screenplay/models/PlaywrightPage.ts +8 -8
  146. package/src/screenplay/models/PlaywrightPageElement.ts +2 -2
  147. package/src/screenplay/models/index.ts +7 -7
  148. package/src/screenplay/models/locators/PlaywrightLocator.ts +4 -4
  149. package/src/screenplay/models/locators/PlaywrightRootLocator.ts +5 -2
  150. package/src/screenplay/models/locators/index.ts +2 -2
  151. package/src/selector-engines/SerenitySelectorEngines.ts +1 -1
  152. package/src/selector-engines/index.ts +1 -1
  153. package/tsconfig-cjs.build.json +18 -0
  154. package/tsconfig-esm.build.json +18 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.42.0](https://github.com/serenity-js/serenity-js/compare/v3.41.2...v3.42.0) (2026-03-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * **core:** add ESM/CJS dual build support for web packages ([94c5a64](https://github.com/serenity-js/serenity-js/commit/94c5a6423dc369477bbabbacee5a54f8fca20209))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [3.41.2](https://github.com/serenity-js/serenity-js/compare/v3.41.1...v3.41.2) (2026-03-05)
7
18
 
8
19
  **Note:** Version bump only for package @serenity-js/playwright
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Playwright-specific options used to configure the ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/)
3
+ *
4
+ * ## Learn more
5
+ * - [Playwright `Browser.newContext` options](https://playwright.dev/docs/api/class-browser#browser-new-context)
6
+ *
7
+ * @group Configuration
8
+ */
9
+ export interface ExtraBrowserContextOptions {
10
+ /**
11
+ * Changes the default maximum navigation time for the browser context used by [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/)
12
+ *
13
+ * #### Learn more
14
+ * - [Playwright `browserContext.setDefaultNavigationTimeout(timeout)`](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout)
15
+ */
16
+ defaultNavigationTimeout?: number;
17
+ /**
18
+ * When to consider navigation operation succeeded, defaults to `load`. Events can be either:
19
+ * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
20
+ * - `'load'` - consider operation to be finished when the `load` event is fired.
21
+ * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
22
+ * - `'commit'` - consider operation to be finished when network response is received and the document started loading.
23
+ *
24
+ * #### Learn more
25
+ * - [Playwright `page.goto(url[, options])`](https://playwright.dev/docs/api/class-page#page-goto-option-wait-until)
26
+ */
27
+ defaultNavigationWaitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
28
+ /**
29
+ * This setting will change the default maximum time for all Playwright methods accepting `timeout` option.
30
+ *
31
+ * #### Learn more
32
+ * - [Playwright `page.setDefaultTimeout(timeout)`](https://playwright.dev/docs/api/class-page#page-set-default-timeout)
33
+ */
34
+ defaultTimeout?: number;
35
+ }
36
+ //# sourceMappingURL=ExtraBrowserContextOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtraBrowserContextOptions.d.ts","sourceRoot":"","sources":["../src/ExtraBrowserContextOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,0BAA0B;IAEvC;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;;;;OASG;IACH,0BAA0B,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,aAAa,GAAG,QAAQ,CAAC;IAEpF;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExtraBrowserContextOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtraBrowserContextOptions.js","sourceRoot":"","sources":["../src/ExtraBrowserContextOptions.ts"],"names":[],"mappings":""}
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './ExtraBrowserContextOptions.js';
2
+ export * from './screenplay/index.js';
3
+ export * from './selector-engines/index.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './ExtraBrowserContextOptions.js';
2
+ export * from './screenplay/index.js';
3
+ export * from './selector-engines/index.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,163 @@
1
+ import type { Discardable } from '@serenity-js/core';
2
+ import { BrowseTheWeb } from '@serenity-js/web';
3
+ import * as playwright from 'playwright-core';
4
+ import type { ExtraBrowserContextOptions } from '../../ExtraBrowserContextOptions.js';
5
+ /**
6
+ * This implementation of the [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
7
+ * enables the [`Actor`](https://serenity-js.org/api/core/class/Actor/) to interact with web front-ends using [Playwright](https://playwright.dev/).
8
+ *
9
+ * ## Using Playwright to `BrowseTheWeb`
10
+ *
11
+ * In the example below, we configure the ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/) with a Playwright
12
+ * [`Browser`](https://playwright.dev/docs/api/class-browser) so that Serenity/JS [actors](https://serenity-js.org/api/core/class/Actor/)
13
+ * can create a new [`BrowserContext`](https://playwright.dev/docs/api/class-browsercontext) and
14
+ * instantiate Playwright [`page`s](https://playwright.dev/docs/api/class-page) as and when needed.
15
+ *
16
+ * This configuration allows Serenity/JS to control the process of launching and shutting down browser instances
17
+ * and is useful when your test runner, e.g. [Cucumber.js](https://serenity-js.org/api/cucumber), doesn't offer this functionality.
18
+ *
19
+ * ```ts
20
+ * import { actorCalled } from '@serenity-js/core'
21
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
22
+ * import { By, Navigate, PageElement, Text } from '@serenity-js/web'
23
+ * import { Ensure, equals } from '@serenity-js/assertions'
24
+ * import { Browser, chromium } from 'playwright'
25
+ *
26
+ * const HomePage = {
27
+ * title: () =>
28
+ * PageElement.located(By.css('h1')).describedAs('title')
29
+ * }
30
+ *
31
+ * const browser = await chromium.launch({ headless: true });
32
+ *
33
+ * await actorCalled('Wendy')
34
+ * .whoCan(BrowseTheWebWithPlaywright.using(browser))
35
+ * .attemptsTo(
36
+ * Navigate.to(`https://serenity-js.org`),
37
+ * Ensure.that(Text.of(HomePage.title()), equals('Serenity/JS')),
38
+ * )
39
+ * ```
40
+ *
41
+ * ## Using `BrowseTheWeb` with an existing Playwright `page`
42
+ *
43
+ * Test runners like [Playwright Test](https://serenity-js.org/api/playwright-test/) manage Playwright browsers for you
44
+ * and offer a [`page`](https://playwright.dev/docs/api/class-page) instance you can
45
+ * inject into the ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/).
46
+ *
47
+ * Note that [Serenity/JS Playwright Test module](https://serenity-js.org/api/playwright-test/)
48
+ * automatically configures all your [actors](https://serenity-js.org/api/core/class/Actor/)
49
+ * with an ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/),
50
+ * so you don't need to do it by hand unless you want to override the [default configuration](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/).
51
+ *
52
+ * The example below demonstrates how to use the [`BrowseTheWebWithPlaywright.usingPage`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/#usingPage) API and
53
+ * override the default [cast](https://serenity-js.org/api/core/class/Cast/) of actors.
54
+ *
55
+ * ```ts
56
+ * import { describe, it, test } from '@playwright/playwright-test'
57
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
58
+ * import { By, Navigate, PageElement, Text } from '@serenity-js/web'
59
+ * import { Ensure, equals } from '@serenity-js/assertions'
60
+ *
61
+ * const HomePage = {
62
+ * title: () =>
63
+ * PageElement.located(By.css('h1')).describedAs('title')
64
+ * }
65
+ *
66
+ * describe('Serenity/JS with Playwright', () => {
67
+ *
68
+ * test.use({
69
+ * actors: async ({ page, contextOptions }, use) => {
70
+ * await use(
71
+ * Cast.where((actorName: string) => {
72
+ * return actor.whoCan(
73
+ * BrowseTheWebWithPlaywright.usingPage(page),
74
+ * // ... add any other abilities
75
+ * )
76
+ * })
77
+ * )
78
+ * }
79
+ * })
80
+ *
81
+ * it('lets you reuse an existing page', async ({ actor }) => {
82
+ * await actor.attemptsTo(
83
+ * Navigate.to(`https://serenity-js.org`),
84
+ * Ensure.that(Text.of(HomePage.title()), equals('Serenity/JS')),
85
+ * )
86
+ * })
87
+ * })
88
+ * ```
89
+ *
90
+ * ## Configuring Playwright
91
+ *
92
+ * If you're using Serenity/JS with [Playwright Test](https://serenity-js.org/handbook/test-runners/playwright-test/),
93
+ * Serenity/JS will automatically pick up your configuration from the [`playwright.config.ts`](https://playwright.dev/docs/test-configuration) file.
94
+ *
95
+ * With other [test runners](https://serenity-js.org/handbook/test-runners/), you can configure Playwright by:
96
+ * - providing the browser-level configuration when calling [`BrowserType.launch`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch),
97
+ * - providing the browser context-level [`ExtraBrowserContextOptions`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/)
98
+ * when initialising the ability to `BrowseTheWebWithPlaywright`.
99
+ *
100
+ * The code snippet below demonstrates how to configure the browser and some popular browser context options,
101
+ * such as
102
+ * [`viewport` size](https://playwright.dev/docs/api/class-browser#browser-new-context-option-viewport),
103
+ * [`geolocation`](https://playwright.dev/docs/api/class-browser#browser-new-page-option-geolocation),
104
+ * and [`permissions`](https://playwright.dev/docs/api/class-browser#browser-new-page-option-permissions),
105
+ * but you can use it to configure any other option available in Playwright, like
106
+ * [`userAgent`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-user-agent)
107
+ * or [`storageState`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-storage-state).
108
+ *
109
+ * ```ts
110
+ * import { actorCalled } from '@serenity-js/core'
111
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
112
+ * import { Navigate } from '@serenity-js/web'
113
+ * import { Browser, chromium } from 'playwright'
114
+ *
115
+ * // specify browser launch options
116
+ * const browser = await chromium.launch({
117
+ * headless: true
118
+ * });
119
+ *
120
+ * await actorCalled('Wendy')
121
+ * .whoCan(BrowseTheWebWithPlaywright.using(browser, {
122
+ * // specify browser context options
123
+ * viewport: { width: 1600, height: 1200 },
124
+ * geolocation: { longitude: 51.50084271042897, latitude: -0.12462540129500639 },
125
+ * permissions: [ 'geolocation' ],
126
+ * }, {
127
+ * defaultNavigationTimeout: 30_000,
128
+ * defaultTimeout: 10_000
129
+ * }))
130
+ * .attemptsTo(
131
+ * Navigate.to(`https://serenity-js.org`),
132
+ * // ...
133
+ * )
134
+ * ```
135
+ *
136
+ * Note that in addition to all the standard Playwright BrowserContextOptions,
137
+ * you can also provide several others defined in Serenity/JS [`ExtraBrowserContextOptions`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/),
138
+ * such as:
139
+ * - `defaultNavigationTimeout`, which changes the default maximum navigation timeout for the browser context,
140
+ * - `defaultTimeout`, which changes the default maximum time for all Playwright methods accepting the `timeout` option.
141
+ *
142
+ * ## Learn more
143
+ * - [Full list of Playwright `BrowserContextOptions`](https://playwright.dev/docs/api/class-browser#browser-new-context)
144
+ * - [Playwright website](https://playwright.dev/)
145
+ * - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
146
+ * - [`Ability`](https://serenity-js.org/api/core/class/Ability/)
147
+ * - [`Actor`](https://serenity-js.org/api/core/class/Actor/)
148
+ *
149
+ * @group Abilities
150
+ */
151
+ export declare class BrowseTheWebWithPlaywright extends BrowseTheWeb<playwright.Locator> implements Discardable {
152
+ static using(browser: playwright.Browser, browserContextOptions?: playwright.BrowserContextOptions, extraBrowserContextOptions?: ExtraBrowserContextOptions): BrowseTheWebWithPlaywright;
153
+ static usingPage(page: playwright.Page, extraBrowserContextOptions?: ExtraBrowserContextOptions): BrowseTheWebWithPlaywright;
154
+ /**
155
+ * Automatically closes any open [pages](https://serenity-js.org/api/web/class/Page/) when the [SceneFinishes](https://serenity-js.org/api/core-events/class/SceneFinishes/)
156
+ *
157
+ * #### Learn more
158
+ * - [`PlaywrightBrowsingSession.closeAllPages`](https://serenity-js.org/api/playwright/class/PlaywrightBrowsingSession/#closeAllPages)
159
+ * - [`Discardable`](https://serenity-js.org/api/core/interface/Discardable/)
160
+ */
161
+ discard(): Promise<void>;
162
+ }
163
+ //# sourceMappingURL=BrowseTheWebWithPlaywright.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowseTheWebWithPlaywright.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/BrowseTheWebWithPlaywright.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAMtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiJG;AACH,qBAAa,0BAA2B,SAAQ,YAAY,CAAC,UAAU,CAAC,OAAO,CAAE,YAAW,WAAW;IAEnG,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,qBAAqB,CAAC,EAAE,UAAU,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,EAAE,0BAA0B,GAAG,0BAA0B;IAIxL,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,0BAA0B,CAAC,EAAE,0BAA0B,GAAG,0BAA0B;IAI5H;;;;;;OAMG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGjC"}
@@ -0,0 +1,168 @@
1
+ import { BrowseTheWeb } from '@serenity-js/web';
2
+ import * as playwright from 'playwright-core';
3
+ import { PlaywrightBrowsingSessionWithBrowser, PlaywrightBrowsingSessionWithPage } from '../models/index.js';
4
+ /**
5
+ * This implementation of the [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
6
+ * enables the [`Actor`](https://serenity-js.org/api/core/class/Actor/) to interact with web front-ends using [Playwright](https://playwright.dev/).
7
+ *
8
+ * ## Using Playwright to `BrowseTheWeb`
9
+ *
10
+ * In the example below, we configure the ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/) with a Playwright
11
+ * [`Browser`](https://playwright.dev/docs/api/class-browser) so that Serenity/JS [actors](https://serenity-js.org/api/core/class/Actor/)
12
+ * can create a new [`BrowserContext`](https://playwright.dev/docs/api/class-browsercontext) and
13
+ * instantiate Playwright [`page`s](https://playwright.dev/docs/api/class-page) as and when needed.
14
+ *
15
+ * This configuration allows Serenity/JS to control the process of launching and shutting down browser instances
16
+ * and is useful when your test runner, e.g. [Cucumber.js](https://serenity-js.org/api/cucumber), doesn't offer this functionality.
17
+ *
18
+ * ```ts
19
+ * import { actorCalled } from '@serenity-js/core'
20
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
21
+ * import { By, Navigate, PageElement, Text } from '@serenity-js/web'
22
+ * import { Ensure, equals } from '@serenity-js/assertions'
23
+ * import { Browser, chromium } from 'playwright'
24
+ *
25
+ * const HomePage = {
26
+ * title: () =>
27
+ * PageElement.located(By.css('h1')).describedAs('title')
28
+ * }
29
+ *
30
+ * const browser = await chromium.launch({ headless: true });
31
+ *
32
+ * await actorCalled('Wendy')
33
+ * .whoCan(BrowseTheWebWithPlaywright.using(browser))
34
+ * .attemptsTo(
35
+ * Navigate.to(`https://serenity-js.org`),
36
+ * Ensure.that(Text.of(HomePage.title()), equals('Serenity/JS')),
37
+ * )
38
+ * ```
39
+ *
40
+ * ## Using `BrowseTheWeb` with an existing Playwright `page`
41
+ *
42
+ * Test runners like [Playwright Test](https://serenity-js.org/api/playwright-test/) manage Playwright browsers for you
43
+ * and offer a [`page`](https://playwright.dev/docs/api/class-page) instance you can
44
+ * inject into the ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/).
45
+ *
46
+ * Note that [Serenity/JS Playwright Test module](https://serenity-js.org/api/playwright-test/)
47
+ * automatically configures all your [actors](https://serenity-js.org/api/core/class/Actor/)
48
+ * with an ability to [`BrowseTheWebWithPlaywright`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/),
49
+ * so you don't need to do it by hand unless you want to override the [default configuration](https://serenity-js.org/api/playwright-test/interface/SerenityFixtures/).
50
+ *
51
+ * The example below demonstrates how to use the [`BrowseTheWebWithPlaywright.usingPage`](https://serenity-js.org/api/playwright/class/BrowseTheWebWithPlaywright/#usingPage) API and
52
+ * override the default [cast](https://serenity-js.org/api/core/class/Cast/) of actors.
53
+ *
54
+ * ```ts
55
+ * import { describe, it, test } from '@playwright/playwright-test'
56
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
57
+ * import { By, Navigate, PageElement, Text } from '@serenity-js/web'
58
+ * import { Ensure, equals } from '@serenity-js/assertions'
59
+ *
60
+ * const HomePage = {
61
+ * title: () =>
62
+ * PageElement.located(By.css('h1')).describedAs('title')
63
+ * }
64
+ *
65
+ * describe('Serenity/JS with Playwright', () => {
66
+ *
67
+ * test.use({
68
+ * actors: async ({ page, contextOptions }, use) => {
69
+ * await use(
70
+ * Cast.where((actorName: string) => {
71
+ * return actor.whoCan(
72
+ * BrowseTheWebWithPlaywright.usingPage(page),
73
+ * // ... add any other abilities
74
+ * )
75
+ * })
76
+ * )
77
+ * }
78
+ * })
79
+ *
80
+ * it('lets you reuse an existing page', async ({ actor }) => {
81
+ * await actor.attemptsTo(
82
+ * Navigate.to(`https://serenity-js.org`),
83
+ * Ensure.that(Text.of(HomePage.title()), equals('Serenity/JS')),
84
+ * )
85
+ * })
86
+ * })
87
+ * ```
88
+ *
89
+ * ## Configuring Playwright
90
+ *
91
+ * If you're using Serenity/JS with [Playwright Test](https://serenity-js.org/handbook/test-runners/playwright-test/),
92
+ * Serenity/JS will automatically pick up your configuration from the [`playwright.config.ts`](https://playwright.dev/docs/test-configuration) file.
93
+ *
94
+ * With other [test runners](https://serenity-js.org/handbook/test-runners/), you can configure Playwright by:
95
+ * - providing the browser-level configuration when calling [`BrowserType.launch`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch),
96
+ * - providing the browser context-level [`ExtraBrowserContextOptions`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/)
97
+ * when initialising the ability to `BrowseTheWebWithPlaywright`.
98
+ *
99
+ * The code snippet below demonstrates how to configure the browser and some popular browser context options,
100
+ * such as
101
+ * [`viewport` size](https://playwright.dev/docs/api/class-browser#browser-new-context-option-viewport),
102
+ * [`geolocation`](https://playwright.dev/docs/api/class-browser#browser-new-page-option-geolocation),
103
+ * and [`permissions`](https://playwright.dev/docs/api/class-browser#browser-new-page-option-permissions),
104
+ * but you can use it to configure any other option available in Playwright, like
105
+ * [`userAgent`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-user-agent)
106
+ * or [`storageState`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-storage-state).
107
+ *
108
+ * ```ts
109
+ * import { actorCalled } from '@serenity-js/core'
110
+ * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
111
+ * import { Navigate } from '@serenity-js/web'
112
+ * import { Browser, chromium } from 'playwright'
113
+ *
114
+ * // specify browser launch options
115
+ * const browser = await chromium.launch({
116
+ * headless: true
117
+ * });
118
+ *
119
+ * await actorCalled('Wendy')
120
+ * .whoCan(BrowseTheWebWithPlaywright.using(browser, {
121
+ * // specify browser context options
122
+ * viewport: { width: 1600, height: 1200 },
123
+ * geolocation: { longitude: 51.50084271042897, latitude: -0.12462540129500639 },
124
+ * permissions: [ 'geolocation' ],
125
+ * }, {
126
+ * defaultNavigationTimeout: 30_000,
127
+ * defaultTimeout: 10_000
128
+ * }))
129
+ * .attemptsTo(
130
+ * Navigate.to(`https://serenity-js.org`),
131
+ * // ...
132
+ * )
133
+ * ```
134
+ *
135
+ * Note that in addition to all the standard Playwright BrowserContextOptions,
136
+ * you can also provide several others defined in Serenity/JS [`ExtraBrowserContextOptions`](https://serenity-js.org/api/playwright/interface/ExtraBrowserContextOptions/),
137
+ * such as:
138
+ * - `defaultNavigationTimeout`, which changes the default maximum navigation timeout for the browser context,
139
+ * - `defaultTimeout`, which changes the default maximum time for all Playwright methods accepting the `timeout` option.
140
+ *
141
+ * ## Learn more
142
+ * - [Full list of Playwright `BrowserContextOptions`](https://playwright.dev/docs/api/class-browser#browser-new-context)
143
+ * - [Playwright website](https://playwright.dev/)
144
+ * - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
145
+ * - [`Ability`](https://serenity-js.org/api/core/class/Ability/)
146
+ * - [`Actor`](https://serenity-js.org/api/core/class/Actor/)
147
+ *
148
+ * @group Abilities
149
+ */
150
+ export class BrowseTheWebWithPlaywright extends BrowseTheWeb {
151
+ static using(browser, browserContextOptions, extraBrowserContextOptions) {
152
+ return new BrowseTheWebWithPlaywright(new PlaywrightBrowsingSessionWithBrowser(browser, browserContextOptions, extraBrowserContextOptions, playwright.selectors));
153
+ }
154
+ static usingPage(page, extraBrowserContextOptions) {
155
+ return new BrowseTheWebWithPlaywright(new PlaywrightBrowsingSessionWithPage(page, extraBrowserContextOptions, playwright.selectors));
156
+ }
157
+ /**
158
+ * Automatically closes any open [pages](https://serenity-js.org/api/web/class/Page/) when the [SceneFinishes](https://serenity-js.org/api/core-events/class/SceneFinishes/)
159
+ *
160
+ * #### Learn more
161
+ * - [`PlaywrightBrowsingSession.closeAllPages`](https://serenity-js.org/api/playwright/class/PlaywrightBrowsingSession/#closeAllPages)
162
+ * - [`Discardable`](https://serenity-js.org/api/core/interface/Discardable/)
163
+ */
164
+ async discard() {
165
+ await this.session.closeAllPages();
166
+ }
167
+ }
168
+ //# sourceMappingURL=BrowseTheWebWithPlaywright.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowseTheWebWithPlaywright.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/BrowseTheWebWithPlaywright.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EACH,oCAAoC,EACpC,iCAAiC,EACpC,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiJG;AACH,MAAM,OAAO,0BAA2B,SAAQ,YAAgC;IAE5E,MAAM,CAAC,KAAK,CAAC,OAA2B,EAAE,qBAAwD,EAAE,0BAAuD;QACvJ,OAAO,IAAI,0BAA0B,CAAC,IAAI,oCAAoC,CAAC,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACtK,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,IAAqB,EAAE,0BAAuD;QAC3F,OAAO,IAAI,0BAA0B,CAAC,IAAI,iCAAiC,CAAC,IAAI,EAAE,0BAA0B,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACzI,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;IACvC,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export * from './BrowseTheWebWithPlaywright.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './BrowseTheWebWithPlaywright.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './abilities/index.js';
2
+ export * from './models/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/screenplay/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './abilities/index.js';
2
+ export * from './models/index.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/screenplay/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { BrowserCapabilities } from '@serenity-js/web';
2
+ import { BrowsingSession, type Cookie, type CookieData } from '@serenity-js/web';
3
+ import type * as playwright from 'playwright-core';
4
+ import { type ExtraBrowserContextOptions } from '../../ExtraBrowserContextOptions.js';
5
+ import { SerenitySelectorEngines } from '../../selector-engines/index.js';
6
+ import { PlaywrightPage } from './PlaywrightPage.js';
7
+ /**
8
+ * Playwright-specific implementation of [`BrowsingSession`](https://serenity-js.org/api/web/class/BrowsingSession/).
9
+ *
10
+ * @group Models
11
+ */
12
+ export declare abstract class PlaywrightBrowsingSession extends BrowsingSession<PlaywrightPage> {
13
+ protected readonly extraBrowserContextOptions: Partial<ExtraBrowserContextOptions>;
14
+ protected readonly selectors: playwright.Selectors;
15
+ protected readonly serenitySelectorEngines: SerenitySelectorEngines;
16
+ private currentPlaywrightBrowserContext;
17
+ protected constructor(extraBrowserContextOptions: Partial<ExtraBrowserContextOptions>, selectors: playwright.Selectors);
18
+ /**
19
+ * Returns [basic meta-data](https://serenity-js.org/api/web/interface/BrowserCapabilities/) about the browser associated with this ability.
20
+ *
21
+ * **Please note** that since Playwright does not expose information about the operating system
22
+ * the tests are running on, **Serenity/JS assumes that the tests are running locally**
23
+ * and therefore returns the value of Node.js `process.platform` for `platformName`.
24
+ */
25
+ abstract browserCapabilities(): Promise<BrowserCapabilities>;
26
+ cookie(name: string): Promise<Cookie>;
27
+ setCookie(cookie: CookieData): Promise<void>;
28
+ deleteAllCookies(): Promise<void>;
29
+ protected browserContext(): Promise<playwright.BrowserContext>;
30
+ protected abstract createBrowserContext(): Promise<playwright.BrowserContext>;
31
+ }
32
+ //# sourceMappingURL=PlaywrightBrowsingSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightBrowsingSession.d.ts","sourceRoot":"","sources":["../../../src/screenplay/models/PlaywrightBrowsingSession.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;GAIG;AACH,8BAAsB,yBAA0B,SAAQ,eAAe,CAAC,cAAc,CAAC;IAM/E,SAAS,CAAC,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC,0BAA0B,CAAC;IAClF,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS;IALtD,SAAS,CAAC,QAAQ,CAAC,uBAAuB,0BAAiC;IAC3E,OAAO,CAAC,+BAA+B,CAA4B;IAEnE,SAAS,aACc,0BAA0B,EAAE,OAAO,CAAC,0BAA0B,CAAC,EAC/D,SAAS,EAAE,UAAU,CAAC,SAAS;IAKtD;;;;;;OAMG;aACa,mBAAmB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAE7D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKrC,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5C,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;cAKvB,cAAc,IAAI,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC;IA2BpE,SAAS,CAAC,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC;CAChF"}
@@ -0,0 +1,54 @@
1
+ import { CorrelationId } from '@serenity-js/core/model';
2
+ import { BrowsingSession } from '@serenity-js/web';
3
+ import { SerenitySelectorEngines } from '../../selector-engines/index.js';
4
+ import { PlaywrightCookie } from './PlaywrightCookie.js';
5
+ import { PlaywrightPage } from './PlaywrightPage.js';
6
+ /**
7
+ * Playwright-specific implementation of [`BrowsingSession`](https://serenity-js.org/api/web/class/BrowsingSession/).
8
+ *
9
+ * @group Models
10
+ */
11
+ export class PlaywrightBrowsingSession extends BrowsingSession {
12
+ extraBrowserContextOptions;
13
+ selectors;
14
+ serenitySelectorEngines = new SerenitySelectorEngines();
15
+ currentPlaywrightBrowserContext;
16
+ constructor(extraBrowserContextOptions, selectors) {
17
+ super();
18
+ this.extraBrowserContextOptions = extraBrowserContextOptions;
19
+ this.selectors = selectors;
20
+ }
21
+ async cookie(name) {
22
+ const context = await this.browserContext();
23
+ return new PlaywrightCookie(context, name);
24
+ }
25
+ async setCookie(cookie) {
26
+ const context = await this.browserContext();
27
+ await context.addCookies([cookie]);
28
+ }
29
+ async deleteAllCookies() {
30
+ const context = await this.browserContext();
31
+ await context.clearCookies();
32
+ }
33
+ async browserContext() {
34
+ if (!this.currentPlaywrightBrowserContext) {
35
+ await this.serenitySelectorEngines.ensureRegisteredWith(this.selectors);
36
+ this.currentPlaywrightBrowserContext = await this.createBrowserContext();
37
+ this.currentPlaywrightBrowserContext.on('page', async (page) => {
38
+ const playwrightPage = new PlaywrightPage(this, page, this.extraBrowserContextOptions, CorrelationId.create());
39
+ this.register(playwrightPage);
40
+ page.on('close', _closedPage => {
41
+ this.deregister(playwrightPage.id);
42
+ });
43
+ });
44
+ if (this.extraBrowserContextOptions?.defaultNavigationTimeout) {
45
+ this.currentPlaywrightBrowserContext.setDefaultNavigationTimeout(this.extraBrowserContextOptions?.defaultNavigationTimeout);
46
+ }
47
+ if (this.extraBrowserContextOptions?.defaultTimeout) {
48
+ this.currentPlaywrightBrowserContext.setDefaultTimeout(this.extraBrowserContextOptions?.defaultTimeout);
49
+ }
50
+ }
51
+ return this.currentPlaywrightBrowserContext;
52
+ }
53
+ }
54
+ //# sourceMappingURL=PlaywrightBrowsingSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightBrowsingSession.js","sourceRoot":"","sources":["../../../src/screenplay/models/PlaywrightBrowsingSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAgC,MAAM,kBAAkB,CAAC;AAIjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;GAIG;AACH,MAAM,OAAgB,yBAA0B,SAAQ,eAA+B;IAM5D;IACA;IALJ,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC;IACnE,+BAA+B,CAA4B;IAEnE,YACuB,0BAA+D,EAC/D,SAA+B;QAElD,KAAK,EAAE,CAAC;QAHW,+BAA0B,GAA1B,0BAA0B,CAAqC;QAC/D,cAAS,GAAT,SAAS,CAAsB;IAGtD,CAAC;IAWD,KAAK,CAAC,MAAM,CAAC,IAAY;QACrB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5C,OAAO,IAAI,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAkB;QAC9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5C,MAAM,OAAO,CAAC,UAAU,CAAC,CAAE,MAAM,CAAE,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,gBAAgB;QAClB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;QAC3C,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC;IACjC,CAAC;IAES,KAAK,CAAC,cAAc;QAC1B,IAAI,CAAE,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACzC,MAAM,IAAI,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACxE,IAAI,CAAC,+BAA+B,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAEzE,IAAI,CAAC,+BAA+B,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBACzD,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,0BAA0B,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;gBAE/G,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;gBAE9B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE;oBAC3B,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBACvC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,IAAI,IAAI,CAAC,0BAA0B,EAAE,wBAAwB,EAAE,CAAC;gBAC5D,IAAI,CAAC,+BAA+B,CAAC,2BAA2B,CAAC,IAAI,CAAC,0BAA0B,EAAE,wBAAwB,CAAC,CAAC;YAChI,CAAC;YAED,IAAI,IAAI,CAAC,0BAA0B,EAAE,cAAc,EAAE,CAAC;gBAClD,IAAI,CAAC,+BAA+B,CAAC,iBAAiB,CAAC,IAAI,CAAC,0BAA0B,EAAE,cAAc,CAAC,CAAC;YAC5G,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,+BAA+B,CAAC;IAChD,CAAC;CAGJ"}
@@ -0,0 +1,18 @@
1
+ import type { BrowserCapabilities } from '@serenity-js/web';
2
+ import type * as playwright from 'playwright-core';
3
+ import type { ExtraBrowserContextOptions } from '../../ExtraBrowserContextOptions.js';
4
+ import { PlaywrightBrowsingSession } from './PlaywrightBrowsingSession.js';
5
+ import type { PlaywrightPage } from './PlaywrightPage.js';
6
+ /**
7
+ * @group Models
8
+ */
9
+ export declare class PlaywrightBrowsingSessionWithBrowser extends PlaywrightBrowsingSession {
10
+ protected readonly browser: playwright.Browser;
11
+ protected readonly browserContextOptions: playwright.BrowserContextOptions;
12
+ constructor(browser: playwright.Browser, browserContextOptions: playwright.BrowserContextOptions, extraBrowserContextOptions: ExtraBrowserContextOptions, selectors: playwright.Selectors);
13
+ protected createBrowserContext(): Promise<playwright.BrowserContext>;
14
+ protected registerCurrentPage(): Promise<PlaywrightPage>;
15
+ closeAllPages(): Promise<void>;
16
+ browserCapabilities(): Promise<BrowserCapabilities>;
17
+ }
18
+ //# sourceMappingURL=PlaywrightBrowsingSessionWithBrowser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightBrowsingSessionWithBrowser.d.ts","sourceRoot":"","sources":["../../../src/screenplay/models/PlaywrightBrowsingSessionWithBrowser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,yBAAyB;IAG3E,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO;IAC9C,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,qBAAqB;gBADvD,OAAO,EAAE,UAAU,CAAC,OAAO,EAC3B,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,EAC1E,0BAA0B,EAAE,0BAA0B,EACtD,SAAS,EAAE,UAAU,CAAC,SAAS;cAKV,oBAAoB,IAAI,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC;cAI1D,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;IAcxD,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,mBAAmB,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAOrE"}
@@ -0,0 +1,38 @@
1
+ import { PlaywrightBrowsingSession } from './PlaywrightBrowsingSession.js';
2
+ /**
3
+ * @group Models
4
+ */
5
+ export class PlaywrightBrowsingSessionWithBrowser extends PlaywrightBrowsingSession {
6
+ browser;
7
+ browserContextOptions;
8
+ constructor(browser, browserContextOptions, extraBrowserContextOptions, selectors) {
9
+ super(extraBrowserContextOptions, selectors);
10
+ this.browser = browser;
11
+ this.browserContextOptions = browserContextOptions;
12
+ }
13
+ async createBrowserContext() {
14
+ return this.browser.newContext(this.browserContextOptions);
15
+ }
16
+ async registerCurrentPage() {
17
+ const context = await this.browserContext();
18
+ await context.newPage();
19
+ // calling context.newPage() triggers a callback registered via browserContext(),
20
+ // which wraps playwright.Page in PlaywrightPage and adds it to the list of pages
21
+ // returned by this.allPages()
22
+ const allPages = await this.allPages();
23
+ return allPages.at(-1);
24
+ }
25
+ async closeAllPages() {
26
+ await super.closeAllPages();
27
+ const context = await this.browserContext();
28
+ await context.close();
29
+ }
30
+ async browserCapabilities() {
31
+ return {
32
+ browserName: this.browser._initializer.name, // todo: raise a PR to Playwright to expose this information
33
+ platformName: process.platform, // todo: get the actual platform from Playwright
34
+ browserVersion: this.browser.version()
35
+ };
36
+ }
37
+ }
38
+ //# sourceMappingURL=PlaywrightBrowsingSessionWithBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightBrowsingSessionWithBrowser.js","sourceRoot":"","sources":["../../../src/screenplay/models/PlaywrightBrowsingSessionWithBrowser.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAG3E;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,yBAAyB;IAGxD;IACA;IAFvB,YACuB,OAA2B,EAC3B,qBAAuD,EAC1E,0BAAsD,EACtD,SAA+B;QAE/B,KAAK,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC;QAL1B,YAAO,GAAP,OAAO,CAAoB;QAC3B,0BAAqB,GAArB,qBAAqB,CAAkC;IAK9E,CAAC;IAEkB,KAAK,CAAC,oBAAoB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAC/D,CAAC;IAEkB,KAAK,CAAC,mBAAmB;QACxC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5C,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAExB,iFAAiF;QACjF,iFAAiF;QACjF,8BAA8B;QAE9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;QAEtC,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAEQ,KAAK,CAAC,aAAa;QACxB,MAAM,KAAK,CAAC,aAAa,EAAE,CAAC;QAE5B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5C,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAEQ,KAAK,CAAC,mBAAmB;QAC9B,OAAO;YACH,WAAW,EAAG,IAAI,CAAC,OAAe,CAAC,YAAY,CAAC,IAAI,EAAI,4DAA4D;YACpH,YAAY,EAAE,OAAO,CAAC,QAAQ,EAA0B,gDAAgD;YACxG,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;SACzC,CAAA;IACL,CAAC;CACJ"}