codeceptjs 4.2.0 → 4.2.1-beta.1

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 (63) hide show
  1. package/README.md +2 -0
  2. package/bin/codecept.js +11 -0
  3. package/docs/agents.md +26 -1
  4. package/docs/ai.md +57 -0
  5. package/docs/alternative-browsers.md +175 -148
  6. package/docs/assertions.md +74 -0
  7. package/docs/bootstrap.md +2 -0
  8. package/docs/commands.md +45 -0
  9. package/docs/configuration.md +37 -0
  10. package/docs/debugging.md +1 -1
  11. package/docs/helpers/ApiDataFactory.md +20 -20
  12. package/docs/helpers/Appium.md +1615 -670
  13. package/docs/helpers/Decision.md +146 -0
  14. package/docs/helpers/GraphQL.md +31 -31
  15. package/docs/helpers/GraphQLDataFactory.md +20 -20
  16. package/docs/helpers/Kitesurf.md +1808 -25
  17. package/docs/helpers/Lightpanda.md +139 -0
  18. package/docs/helpers/Obscura.md +1799 -74
  19. package/docs/helpers/Playwright.md +490 -428
  20. package/docs/helpers/Puppeteer.md +317 -255
  21. package/docs/helpers/REST.md +43 -43
  22. package/docs/helpers/WebDriver.md +237 -175
  23. package/docs/installation.md +16 -0
  24. package/docs/mcp.md +7 -1
  25. package/docs/parallel.md +35 -1
  26. package/docs/plugins/pause.md +2 -1
  27. package/docs/plugins/sitemap.md +48 -0
  28. package/docs/plugins.md +4 -0
  29. package/lib/ai.js +81 -2
  30. package/lib/codecept.js +32 -2
  31. package/lib/command/init.js +22 -0
  32. package/lib/command/initAgent.js +78 -0
  33. package/lib/command/run-multiple.js +3 -0
  34. package/lib/command/run-workers.js +10 -3
  35. package/lib/command/run.js +3 -2
  36. package/lib/command/utils.js +15 -0
  37. package/lib/command/workers/runTests.js +10 -10
  38. package/lib/container.js +4 -2
  39. package/lib/effects.js +19 -1
  40. package/lib/helper/CDPBrowser.js +349 -1384
  41. package/lib/helper/Decision.js +256 -0
  42. package/lib/helper/Kitesurf.js +3 -21
  43. package/lib/helper/Lightpanda.js +137 -0
  44. package/lib/helper/Obscura.js +21 -238
  45. package/lib/helper/Playwright.js +6 -4
  46. package/lib/helper/Puppeteer.js +12 -7
  47. package/lib/helper/WebDriver.js +2 -1
  48. package/lib/listener/result.js +4 -0
  49. package/lib/mocha/bdd.js +19 -1
  50. package/lib/plugin/junitReporter.js +4 -1
  51. package/lib/plugin/pause.js +4 -1
  52. package/lib/plugin/sitemap.js +228 -0
  53. package/lib/recorder.js +19 -18
  54. package/lib/result.js +16 -0
  55. package/lib/step/base.js +12 -0
  56. package/lib/utils.js +2 -10
  57. package/lib/webServer.js +193 -0
  58. package/lib/workers.js +118 -31
  59. package/package.json +4 -2
  60. package/typings/index.d.ts +60 -7
  61. package/typings/promiseBasedTypes.d.ts +772 -824
  62. package/typings/types.d.ts +866 -833
  63. package/docs/helpers/CDPBrowser.md +0 -2138
@@ -1,3 +1,5 @@
1
+ import { spawn } from 'child_process'
2
+ import net from 'net'
1
3
  import path from 'path'
2
4
  import fs from 'fs'
3
5
  import axios from 'axios'
@@ -7,7 +9,7 @@ import installCodeceptClient from './clientscripts/cdpBrowserClient.js'
7
9
  import xpathPolyfillSource from './clientscripts/xpathPolyfill.js'
8
10
  import Locator from '../locator.js'
9
11
  import store from '../store.js'
10
- import { xpathLocator, normalizePath, resolveUrl, toCamelCase, convertCssPropertiesToCamelCase, normalizeSpacesInString, fileExists, base64EncodeFile, getMimeType } from '../utils.js'
12
+ import { xpathLocator, normalizePath, resolveUrl, toCamelCase, convertCssPropertiesToCamelCase, normalizeSpacesInString, fileExists, base64EncodeFile, getMimeType, isFile, isWindows } from '../utils.js'
11
13
  import ElementNotFound from './errors/ElementNotFound.js'
12
14
  import MultipleElementsFound from './errors/MultipleElementsFound.js'
13
15
  import { includes as stringIncludes } from '../assert/include.js'
@@ -30,16 +32,16 @@ import { assembleApng, isPng } from './extras/apngAssembler.js'
30
32
  * @typedef CDPBrowserConfig
31
33
  * @type {object}
32
34
  * @prop {string} [url=http://localhost] - base url of website to be tested.
33
- * @prop {string} [endpoint=http://127.0.0.1:9222] - Chrome DevTools Protocol endpoint. Either an `http(s)://` address exposing `/json/version` (from which the `webSocketDebuggerUrl` is resolved) or a raw `ws(s)://` debugger URL.
34
- * @prop {object} [headers={}] - headers sent with the endpoint resolution request and the WebSocket handshake. Useful for authenticated remote browser providers.
35
- * @prop {string} [input=auto] - how synthetic user actions (click, fill, etc.) are dispatched by helpers built on top of this class. `auto` picks `cdp` when a real layout engine is detected and `synthetic` otherwise; can be pinned to `cdp` or `synthetic`.
36
- * @prop {string|boolean} [xpathPolyfill=auto] - whether to inject the bundled XPath polyfill before installing the in-page client. `auto` probes the page and only injects when `document.evaluate` is unavailable or broken; `true`/`false` force the behavior.
37
- * @prop {object} [capabilities={}] - pre-seed detected browser capabilities (`layout`, `xpath`, `screenshot`, `innerText`) to skip runtime probing. Values set here are never overwritten by `_probeCapabilities`/`_ensureClient`.
38
- * @prop {number} [waitForTimeout=5] - default wait* timeout in seconds, used by helpers built on top of this class.
39
- * @prop {number} [waitForAction=100] - only takes effect when set explicitly: a literal fixed pacing sleep (in milliseconds) after click, type, or other interactions, mirroring other browser helpers. Left unset, actions settle in an event-aware way instead — near-instant when nothing navigates, waiting for the navigation to actually finish (not a guessed fixed delay) when one does.
40
- * @prop {number} [pollInterval=25] - interval in milliseconds between retries while polling for a condition (e.g. page ready state, `waitFor*`). Distinct from `waitForAction`.
41
- * @prop {number} [getPageTimeout=30] - maximum time in seconds to wait for a page to finish loading after navigation or reload; also used as the CDP command timeout (in ms, x1000).
42
- * @prop {string} [waitForNavigation=load] - when to consider a navigation finished: `load`, `domcontentloaded`, or `networkidle`. Mirrors the Puppeteer helper's option name. `networkidle` waits for the CDP `networkIdle` lifecycle event, which on a busy page can lag `load` by a second or more — only opt in if the extra wait is actually needed.
35
+ * @prop {string} [endpoint=http://127.0.0.1:9222] - Chrome DevTools Protocol endpoint: an `http(s)://` address or a `ws(s)://` debugger URL.
36
+ * @prop {object} [headers={}] - headers sent when connecting to the endpoint, e.g. for authenticated remote browsers.
37
+ * @prop {string} [input=auto] - how actions are dispatched: `cdp` (real mouse and keyboard events) or `synthetic` (DOM events). `auto` picks `cdp` when the browser renders layout.
38
+ * @prop {string|boolean} [xpathPolyfill=auto] - inject an XPath polyfill for browsers with incomplete XPath support. `auto` detects when it is needed.
39
+ * @prop {object} [capabilities={}] - browser capabilities (`layout`, `xpath`, `screenshot`, `innerText`) to use instead of detecting them at runtime.
40
+ * @prop {number} [waitForTimeout=5] - default timeout for wait* actions, in seconds.
41
+ * @prop {number} [waitForAction] - fixed delay after each action, in milliseconds. When unset, actions wait only for the navigation they trigger.
42
+ * @prop {number} [pollInterval=25] - interval between checks while waiting, in milliseconds.
43
+ * @prop {number} [getPageTimeout=30] - maximum time to wait for a page to load, in seconds.
44
+ * @prop {string} [waitForNavigation=load] - when a navigation is considered finished: `load`, `domcontentloaded`, or `networkidle`.
43
45
  */
44
46
  const config = {}
45
47
 
@@ -83,6 +85,8 @@ const ACTION_SETTLE_GRACE_MS = 20
83
85
  * script evaluation, and simple in-page element interaction (installed lazily through the
84
86
  * `window.__codecept` client script). It does not launch a browser itself — point `endpoint` at an
85
87
  * already-running Chrome (or any CDP-compatible browser) started with `--remote-debugging-port`.
88
+ * Subclasses for browsers shipped as a standalone binary opt into launching and reaping their own
89
+ * server process through `_manageServer`.
86
90
  *
87
91
  * ## Example
88
92
  *
@@ -125,6 +129,12 @@ class CDPBrowser extends Helper {
125
129
  this.cdp = null
126
130
  this.sessionId = null
127
131
  this.targetId = null
132
+ this.mode = 'attach'
133
+ this.server = null
134
+ this.serverProcess = null
135
+ this.serverError = null
136
+ this.binaryPath = null
137
+ this._selfManagedResolved = false
128
138
  this.capabilities = { layout: null, xpath: null, screenshot: null, innerText: null, ...this.options.capabilities }
129
139
  this.withinCandidates = null
130
140
  this.requests = []
@@ -143,24 +153,8 @@ class CDPBrowser extends Helper {
143
153
  this._waitForActionExplicit = config?.waitForAction !== undefined
144
154
  }
145
155
 
146
- /**
147
- * No-op hook kept for interface parity with other browser helpers. Connecting to the CDP
148
- * endpoint is deferred to `_before`, since a fresh target/session is opened per test.
149
- */
150
156
  _init() {}
151
157
 
152
- /**
153
- * Resolves `options.endpoint` to a raw WebSocket debugger URL. If the configured endpoint is
154
- * an `http(s)://` address, this fetches `/json/version` from it and reads `webSocketDebuggerUrl`
155
- * from the response, matching the discovery flow exposed by Chrome's `--remote-debugging-port`.
156
- * A `ws(s)://` endpoint is returned unchanged.
157
- *
158
- * This is the subclass override point for helpers that connect through a different discovery
159
- * mechanism (e.g. a cloud browser provider with its own session-creation API).
160
- *
161
- * @returns {Promise<string>} a `ws(s)://` debugger URL ready to be passed to `CDPConnection`.
162
- * @protected
163
- */
164
158
  async _resolveEndpoint() {
165
159
  let endpoint = this.options.endpoint
166
160
  if (endpoint.startsWith('http')) {
@@ -171,32 +165,198 @@ class CDPBrowser extends Helper {
171
165
  }
172
166
 
173
167
  /**
174
- * Resolves the CDP endpoint and opens the underlying `CDPConnection`, storing it on `this.cdp`.
168
+ * Opts a subclass into managing its own browser server process. Called from a subclass
169
+ * constructor with the raw user config and a server descriptor:
170
+ *
171
+ * - `name` — binary name looked up on `PATH`, also used in messages
172
+ * - `envVar` — environment variable that may point at the binary
173
+ * - `args(port)` — arguments the binary is spawned with to serve CDP on `port`
174
+ * - `env` — extra environment variables for the spawned process
175
+ * - `releases` — URL shown when no binary can be resolved
175
176
  *
177
+ * An explicit `endpoint` in the user config always wins: the helper stays in ATTACH mode and
178
+ * never spawns or kills anything. Otherwise the helper becomes SELF-MANAGED and the default
179
+ * `endpoint` is cleared until `_resolveSelfManaged` sets the real one.
180
+ *
181
+ * @param {object} config - the config object the helper was constructed with.
182
+ * @param {object} server - the server descriptor described above.
176
183
  * @protected
177
184
  */
178
- async _connect() {
179
- const endpoint = await this._resolveEndpoint()
180
- this.cdp = new CDPConnection(endpoint, { headers: this.options.headers, timeout: this.options.getPageTimeout * 1000 })
181
- await this.cdp.connect()
185
+ _manageServer(config, server) {
186
+ if (config && config.endpoint) return
187
+ this.mode = 'self-managed'
188
+ this.options.endpoint = null
189
+ this.server = server
190
+ }
191
+
192
+ /**
193
+ * Resolves how to reach a SELF-MANAGED browser, trying, in order: spawn a binary
194
+ * (`binaryPath` config, then the descriptor's `envVar`, then its `name` on `PATH`) on
195
+ * `options.port` or a free port, courtesy-attach to `http://127.0.0.1:9222` if something already
196
+ * answers there (never killed by this helper), or throw a loud, actionable error. Sets
197
+ * `this.options.endpoint` as a side effect.
198
+ *
199
+ * A spawn failure (e.g. a bad binary) is delivered asynchronously by Node as an `error` event;
200
+ * it is recorded on `this.serverError` and surfaced as a rejection from `_waitForServer` instead
201
+ * of crashing the process as an uncaught exception.
202
+ *
203
+ * @protected
204
+ */
205
+ async _resolveSelfManaged() {
206
+ const { name, envVar, args, env, releases } = this.server
207
+ const helperName = this.constructor.name
208
+ const binaryPath = this._resolveBinary()
209
+ if (binaryPath) {
210
+ this.binaryPath = binaryPath
211
+ const port = this.options.port || (await this._findFreePort())
212
+ this.options.port = port
213
+ this.serverError = null
214
+ this.serverProcess = spawn(binaryPath, args(port), { stdio: 'ignore', env: { ...process.env, ...env } })
215
+ this.serverProcess.on('error', err => {
216
+ this.serverError = err
217
+ })
218
+ await this._waitForServer()
219
+ this.options.endpoint = `http://127.0.0.1:${port}`
220
+ return
221
+ }
222
+ if (await this._probeUp('http://127.0.0.1:9222/json/version')) {
223
+ this.debugSection(helperName, `no binaryPath/${envVar}/${name}-on-PATH found — courtesy-attaching to an already-running ${name} on 127.0.0.1:9222 (this helper will not manage or kill it)`)
224
+ this.options.endpoint = 'http://127.0.0.1:9222'
225
+ return
226
+ }
227
+ throw new Error(
228
+ [
229
+ `${helperName} has no endpoint configured, no binary could be resolved (checked config.binaryPath, ${envVar}, and PATH), and nothing answered http://127.0.0.1:9222/json/version.`,
230
+ `Start it yourself: ${name} ${args(9222).join(' ')}`,
231
+ `Or let this helper launch it: put a release binary on PATH, set ${envVar}=/path/to/${name}, or pass binaryPath in the config.`,
232
+ `Releases: ${releases}`,
233
+ ].join('\n '),
234
+ )
182
235
  }
183
236
 
184
237
  /**
185
- * Hook executed before each test. Ensures a live `CDPConnection` exists (connecting lazily on
186
- * first use, and reconnecting if a previous connection was closed), then creates a fresh
187
- * `about:blank` target and attaches to it with `Target.attachToTarget`, storing `this.targetId`
188
- * and `this.sessionId`. `Page` and `Runtime` domains are enabled on the new session, and engine
189
- * capabilities are probed here (against `about:blank`, uncontended) rather than only lazily on
190
- * the first real page — see `_probeCapabilities`.
238
+ * Resolves the binary to spawn, in priority order: `options.binaryPath`, then the server
239
+ * descriptor's environment variable, then its name on `PATH`. The `PATH` lookup walks the
240
+ * directories itself instead of shelling out to `which`, which does not exist on Windows: on
241
+ * Windows every `PATHEXT` suffix is tried, so a `.exe` on `PATH` is found too.
191
242
  *
192
- * Also resets `_navStartWaiters` and `_lastMainFrameNav`: both are scoped to a single
193
- * `sessionId`/`targetId`, which are about to change, so anything left over from the previous test
194
- * (e.g. an action-settle waiter still armed because its test threw between arming and settling)
195
- * can never legitimately resolve against the new session — better to drop it here than leave it
196
- * waiting for the rest of the run.
243
+ * @returns {string|null} an absolute or relative path to the binary, or null if none resolved.
244
+ * @protected
245
+ */
246
+ _resolveBinary() {
247
+ const { name, envVar } = this.server
248
+ if (this.options.binaryPath) return this.options.binaryPath
249
+ if (process.env[envVar]) return process.env[envVar]
250
+ const windows = isWindows()
251
+ const extensions = windows ? (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';') : ['']
252
+ for (const entry of (process.env.PATH || '').split(path.delimiter)) {
253
+ const dir = windows ? entry.replace(/^"|"$/g, '') : entry
254
+ if (!dir) continue
255
+ for (const extension of extensions) {
256
+ const candidate = path.join(dir, `${name}${extension}`)
257
+ if (!isFile(candidate)) continue
258
+ try {
259
+ fs.accessSync(candidate, fs.constants.X_OK)
260
+ return candidate
261
+ } catch (e) {
262
+ continue
263
+ }
264
+ }
265
+ }
266
+ return null
267
+ }
268
+
269
+ /**
270
+ * Picks a free TCP port on 127.0.0.1 by briefly listening on port 0 and reading back the
271
+ * OS-assigned port. Used when `options.port` isn't explicitly set, so multiple `run-workers`
272
+ * workers never collide on the same port.
197
273
  *
274
+ * @returns {Promise<number>} a free port.
198
275
  * @protected
199
276
  */
277
+ async _findFreePort() {
278
+ return new Promise((resolve, reject) => {
279
+ const srv = net.createServer()
280
+ srv.unref()
281
+ srv.on('error', reject)
282
+ srv.listen(0, '127.0.0.1', () => {
283
+ const { port } = srv.address()
284
+ srv.close(() => resolve(port))
285
+ })
286
+ })
287
+ }
288
+
289
+ /**
290
+ * Probes a `/json/version`-style URL with a short timeout, used for the courtesy-attach check.
291
+ *
292
+ * @param {string} url
293
+ * @returns {Promise<boolean>} true if the URL answered.
294
+ * @protected
295
+ */
296
+ async _probeUp(url) {
297
+ try {
298
+ await axios.get(url, { timeout: 1000 })
299
+ return true
300
+ } catch (e) {
301
+ return false
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Polls `http://127.0.0.1:<port>/json/version` until the spawned server responds,
307
+ * `this.serverError` is set by the process' `error` event, or `options.serverStartTimeout`
308
+ * elapses. The process typically comes up within tens of milliseconds — a 20ms retry interval
309
+ * keeps the wasted tail after the server is actually ready small, since this cost is paid once
310
+ * per run and counts directly toward real-world startup latency.
311
+ *
312
+ * @protected
313
+ */
314
+ async _waitForServer() {
315
+ const { name } = this.server
316
+ const timeout = this.options.serverStartTimeout || 15000
317
+ const deadline = Date.now() + timeout
318
+ while (Date.now() < deadline) {
319
+ if (this.serverError) {
320
+ throw new Error(`Failed to start ${name} at ${this.binaryPath}: ${this.serverError.message}`)
321
+ }
322
+ try {
323
+ await axios.get(`http://127.0.0.1:${this.options.port}/json/version`, { timeout: Math.min(1000, deadline - Date.now()) })
324
+ return
325
+ } catch (e) {
326
+ await new Promise(r => setTimeout(r, 20))
327
+ }
328
+ }
329
+ if (this.serverError) {
330
+ throw new Error(`Failed to start ${name} at ${this.binaryPath}: ${this.serverError.message}`)
331
+ }
332
+ throw new Error(`${name} did not start on port ${this.options.port} within ${timeout}ms`)
333
+ }
334
+
335
+ /**
336
+ * In SELF-MANAGED mode, resolves and spawns the browser server (or courtesy-attaches to an
337
+ * already-running one on :9222) exactly once via `_resolveSelfManaged`. Then resolves the CDP
338
+ * endpoint and opens the underlying `CDPConnection`, storing it on `this.cdp`.
339
+ *
340
+ * @protected
341
+ */
342
+ async _connect() {
343
+ if (this.server) {
344
+ if (this._selfManagedError) throw this._selfManagedError
345
+ if (!this._selfManagedResolved) {
346
+ this._selfManagedResolved = true
347
+ try {
348
+ await this._resolveSelfManaged()
349
+ } catch (err) {
350
+ this._selfManagedError = err
351
+ throw err
352
+ }
353
+ }
354
+ }
355
+ const endpoint = await this._resolveEndpoint()
356
+ this.cdp = new CDPConnection(endpoint, { headers: this.options.headers, timeout: this.options.getPageTimeout * 1000 })
357
+ await this.cdp.connect()
358
+ }
359
+
200
360
  async _before() {
201
361
  if (!this.cdp || !this.cdp.isConnected) await this._connect()
202
362
  this._navStartWaiters = []
@@ -211,33 +371,6 @@ class CDPBrowser extends Helper {
211
371
  await this._probeCapabilities()
212
372
  }
213
373
 
214
- /**
215
- * Lazily installs a single, persistent `Page.lifecycleEvent` listener on the underlying
216
- * `CDPConnection` and drains it into whichever `_waitForLoadEvent` calls are currently pending,
217
- * matched by `loaderId`. Installed once per helper instance (the connection outlives individual
218
- * tests), never removed — `CDPConnection` has no listener-removal API, so a single persistent
219
- * dispatcher (rather than one listener per navigation) is what keeps this leak-free.
220
- *
221
- * Also, for the main frame (`params.frameId === this.targetId`, which holds for a page target's
222
- * own top-level frame) only:
223
- * - Drains `_navStartWaiters` (armed by `_armActionSettle`, before an action, for `_waitForAction`'s
224
- * event-aware settle) on an `'init'` event — confirmed via a raw probe (against both Obscura and
225
- * Chrome, through the actual CLI path) to be the earliest signal CDP emits when a new top-level
226
- * navigation begins. Arming happens *before* the action is dispatched, not after: the same probe
227
- * found `'init'` can arrive while the action's own CDP round trip is still in flight, sometimes
228
- * only a millisecond or two after it started — a listener installed only once the action's
229
- * promise resolves can already be too late, not merely unlucky.
230
- * - Maintains `_lastMainFrameNav`, a rolling `{loaderId, events}` record of every lifecycle event
231
- * name seen for the current main-frame navigation (reset whenever `loaderId` changes). On a
232
- * fast/local navigation, the same raw probe found the *entire* sequence — `init` through
233
- * `networkIdle` — arriving as one batch while the triggering action's own round trip was still
234
- * in flight. Without this cache, `_waitForAction` would correctly detect that a navigation
235
- * started, then arm a *fresh* wait for the `load` event specifically — which, in that common
236
- * case, had already fired and will never fire again, paying the full grace-window-plus-poll cost
237
- * of `_waitForPageLoad` on every single navigating action instead of settling immediately.
238
- *
239
- * @protected
240
- */
241
374
  _ensureLifecycleListener() {
242
375
  if (this._lifecycleListenerInstalled) return
243
376
  this._lifecycleListenerInstalled = true
@@ -261,24 +394,6 @@ class CDPBrowser extends Helper {
261
394
  })
262
395
  }
263
396
 
264
- /**
265
- * Starts waiting for a `Page.lifecycleEvent` named `eventName` for the given `loaderId` on the
266
- * current session. `loaderId` (from the `Page.navigate` response) discriminates the awaited
267
- * navigation from any other in-flight or stale lifecycle events (e.g. the `about:blank` target
268
- * created in `_before`), which is essential since Chrome emits the target's initial `about:blank`
269
- * lifecycle sequence asynchronously, sometimes after this listener is already installed.
270
- *
271
- * Returns a `{promise, cancel}` pair rather than a bare promise: `_waitForPageLoad` races this
272
- * against a readyState poll, and whichever side loses must be actively torn down (not just have
273
- * its rejection swallowed) — an abandoned-but-still-pending wait would sit in `_pageLoadWaiters`
274
- * for the full timeout on every single navigation, for no purpose.
275
- *
276
- * @param {string} loaderId - the loader id of the navigation to wait for, from `Page.navigate`'s response.
277
- * @param {string} eventName - the `Page.lifecycleEvent` name to wait for (e.g. `load`, `DOMContentLoaded`, `networkIdle`).
278
- * @param {number} timeoutSec - maximum time to wait, in seconds.
279
- * @returns {{promise: Promise<void>, cancel: function}}
280
- * @protected
281
- */
282
397
  _waitForLoadEvent(loaderId, eventName, timeoutSec) {
283
398
  this._ensureLifecycleListener()
284
399
  let waiter
@@ -304,19 +419,6 @@ class CDPBrowser extends Helper {
304
419
  return { promise, cancel: () => waiter.cancel() }
305
420
  }
306
421
 
307
- /**
308
- * Arms the event-aware settle's navigation-start listener. Must be called *before* the action
309
- * that might trigger a navigation is dispatched, not after — see `_ensureLifecycleListener` for
310
- * why. Returns `null` when `options.waitForAction` was set explicitly, since `_waitForAction`
311
- * ignores the armed listener entirely in that case (a literal fixed sleep, as before this round).
312
- *
313
- * No timeout here: `_waitForAction` applies the grace window itself, starting from when *it*
314
- * runs (after the action's own dispatch already resolved), racing this already-armed listener
315
- * against a fresh timer instead of one that started ticking before the action even began.
316
- *
317
- * @returns {({promise: Promise<string|null>, cancel: function}|null)}
318
- * @protected
319
- */
320
422
  _armActionSettle() {
321
423
  if (this._waitForActionExplicit) return null
322
424
  this._ensureLifecycleListener()
@@ -328,30 +430,6 @@ class CDPBrowser extends Helper {
328
430
  return { promise, cancel: () => { this._navStartWaiters = this._navStartWaiters.filter(w => w !== waiter) } }
329
431
  }
330
432
 
331
- /**
332
- * Waits for a page to finish loading after `Page.navigate`/`Page.reload`, per `options.waitForNavigation`.
333
- *
334
- * Purely event-driven for the first `PAGE_LOAD_GRACE_MS`: only the push-based
335
- * `Page.lifecycleEvent` signal (matched by `loaderId`) is awaited, issuing zero `_evaluate` calls
336
- * — this matters because an `_evaluate` sent while the page's own JavaScript is still busy (e.g.
337
- * a real-world page doing post-load hydration/analytics work) can queue behind it for hundreds of
338
- * ms to multiple seconds, measured directly against a JS-heavy page. Only if the grace window
339
- * elapses without the event (an engine that doesn't emit it, or a genuinely slow navigation) does
340
- * the `document.readyState` poll (via `_poll`) start, racing the still-pending lifecycle wait —
341
- * both bounded by the same `options.getPageTimeout`, so a lifecycle-less engine costs at most
342
- * `PAGE_LOAD_GRACE_MS` more than the poll alone would have, never double the timeout. No
343
- * `loaderId` (e.g. from `Page.reload`, which returns none) skips straight to the poll.
344
- *
345
- * Whichever side ultimately loses is actively cancelled, not merely abandoned — an abandoned poll
346
- * or lifecycle wait would otherwise keep running (issuing readyState `_evaluate` calls every
347
- * `pollInterval`, or holding a `_pageLoadWaiters` entry) for up to the full timeout on every
348
- * navigation, competing for the same CDP connection with real work.
349
- *
350
- * @param {string|null} loaderId - loader id from the triggering `Page.navigate` response, if any.
351
- * @param {string} timeoutMessage - error message used if the readyState poll times out.
352
- * @returns {Promise<void>}
353
- * @protected
354
- */
355
433
  async _waitForPageLoad(loaderId, timeoutMessage) {
356
434
  const waitUntil = READY_STATE_EXPR_BY_WAIT_UNTIL[this.options.waitForNavigation] ? this.options.waitForNavigation : 'load'
357
435
  const readyStateCheck = () => this._evaluate(READY_STATE_EXPR_BY_WAIT_UNTIL[waitUntil]).catch(() => false)
@@ -387,13 +465,6 @@ class CDPBrowser extends Helper {
387
465
  }
388
466
  }
389
467
 
390
- /**
391
- * Hook executed after each test. Closes the target opened in `_before` via `Target.closeTarget`
392
- * and clears `this.targetId`/`this.sessionId`. The underlying `CDPConnection` is left open so it
393
- * can be reused by the next test.
394
- *
395
- * @protected
396
- */
397
468
  async _after() {
398
469
  if (!this.targetId) return
399
470
  await this.cdp.send('Target.closeTarget', { targetId: this.targetId }).catch(() => null)
@@ -403,26 +474,49 @@ class CDPBrowser extends Helper {
403
474
 
404
475
  /**
405
476
  * Hook executed after all tests are run. Closes the underlying `CDPConnection` (and its
406
- * WebSocket) and clears `this.cdp`. Must leave no open sockets or pending timers behind, so the
407
- * process can exit on its own.
477
+ * WebSocket) and clears `this.cdp`, then kills the server process spawned by
478
+ * `_resolveSelfManaged`, if any (`this.serverProcess` is never set when attaching). Must leave no
479
+ * open sockets, pending timers or child processes behind, so the process can exit on its own.
480
+ *
481
+ * The kill runs in a `finally` so the process is always reaped even if closing the CDP
482
+ * connection throws. It sends `SIGTERM` first and waits for the process to exit; a process that
483
+ * ignores `SIGTERM` is escalated to `SIGKILL` after 5s. The promise only resolves once the child
484
+ * has actually exited (confirmed via the `exit` event, not merely once `SIGKILL` was sent — the
485
+ * kernel needs a moment to reap it), with a final safety-net timeout so a stuck child can never
486
+ * keep the event loop alive even if that confirmation is somehow lost.
408
487
  *
409
488
  * @protected
410
489
  */
411
490
  async _finishTest() {
412
- if (this.cdp) await this.cdp.close()
413
- this.cdp = null
491
+ try {
492
+ if (this.cdp) await this.cdp.close()
493
+ this.cdp = null
494
+ } finally {
495
+ if (this.serverProcess) {
496
+ const proc = this.serverProcess
497
+ this.serverProcess = null
498
+ await new Promise(resolve => {
499
+ if (proc.exitCode !== null || proc.signalCode !== null) {
500
+ resolve()
501
+ return
502
+ }
503
+ let settled = false
504
+ const finish = () => {
505
+ if (settled) return
506
+ settled = true
507
+ clearTimeout(killTimer)
508
+ clearTimeout(safetyTimer)
509
+ resolve()
510
+ }
511
+ proc.once('exit', finish)
512
+ const killTimer = setTimeout(() => proc.kill('SIGKILL'), 5000)
513
+ const safetyTimer = setTimeout(finish, 5500)
514
+ proc.kill()
515
+ })
516
+ }
517
+ }
414
518
  }
415
519
 
416
- /**
417
- * Evaluates a JavaScript expression in the page attached to the current session via
418
- * `Runtime.evaluate`, awaiting any returned promise and returning the value by reference
419
- * (`returnByValue: true`). If the expression throws, the browser-side exception description
420
- * (or fallback text) is re-thrown as a JS `Error`.
421
- *
422
- * @param {string} expression - a JavaScript expression (or IIFE) to run in the page context.
423
- * @returns {Promise<any>} the evaluated value, or `undefined` if the expression has no result.
424
- * @protected
425
- */
426
520
  async _evaluate(expression) {
427
521
  const res = await this.cdp.send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true }, this.sessionId)
428
522
  if (res.exceptionDetails) {
@@ -432,39 +526,12 @@ class CDPBrowser extends Helper {
432
526
  return res.result ? res.result.value : undefined
433
527
  }
434
528
 
435
- /**
436
- * Ensures the in-page client (`window.__codecept`, installed from `cdpBrowserClient.js`) is
437
- * present on the current page, installing it (and the XPath polyfill, if needed) exactly once.
438
- * Safe to call repeatedly; it is a no-op once the client is detected.
439
- *
440
- * @protected
441
- */
442
529
  async _ensureClient() {
443
530
  const installed = await this._evaluate(`typeof window.__codecept !== 'undefined'`)
444
531
  if (installed) return
445
532
  await this._installClient()
446
533
  }
447
534
 
448
- /**
449
- * Installs the in-page client unconditionally — no `typeof window.__codecept` presence check.
450
- * Used by callers that already know, from a sentinel value returned alongside a failed action,
451
- * that the client is missing on the current page, so re-checking would just be a redundant
452
- * contended round trip.
453
- *
454
- * The 171KB XPath polyfill is only injected alongside the client when `needsXPath` is true (the
455
- * default, for callers without candidate information) *and* the engine actually needs it
456
- * (`capabilities.xpath === 'polyfill'`, cached from `_before`'s probe). Callers that know their
457
- * candidates never resolve to an `xpath` strategy (e.g. `_runSelected`, once it has inspected
458
- * `candidates`/`within`) can pass `false` to skip that inject — the client is still told, via the
459
- * `xpathNeedsPolyfill` flag baked in at install time, that the *engine* will eventually need it,
460
- * so a later call that does hit an xpath candidate gets a clean `'__NO_XPATH__'` miss signal
461
- * (from `window.__codecept.run`) instead of silently falling through to a broken native
462
- * `document.evaluate` — `_runSelected` reacts to that sentinel by injecting the polyfill and
463
- * retrying once, mirroring the `'__NO_CLIENT__'` handling right next to it.
464
- *
465
- * @param {boolean} [needsXPath=true]
466
- * @protected
467
- */
468
535
  async _installClient(needsXPath = true) {
469
536
  const enginePolyfillNeeded = await this._needsXPathPolyfill()
470
537
  if (needsXPath && enginePolyfillNeeded) {
@@ -473,36 +540,12 @@ class CDPBrowser extends Helper {
473
540
  await this._evaluate(`(${installCodeceptClient.toString()})(${JSON.stringify(enginePolyfillNeeded)})`)
474
541
  }
475
542
 
476
- /**
477
- * Whether any candidate strategy — in `candidates` itself, or in any of the `within` scoping
478
- * `layers` searched before it — is an `xpath` locator. Used to decide, before the client is even
479
- * installed, whether the XPath polyfill needs to be bundled into that install or can be deferred.
480
- *
481
- * @param {?Array<{type: string, value: string}>} candidates
482
- * @param {Array<Array<{type: string, value: string}>>} layers
483
- * @returns {boolean}
484
- * @protected
485
- */
486
543
  _candidatesNeedXPath(candidates, layers) {
487
544
  const hasXPath = arr => Array.isArray(arr) && arr.some(c => c && c.type === 'xpath')
488
545
  if (hasXPath(candidates)) return true
489
546
  return layers.some(hasXPath)
490
547
  }
491
548
 
492
- /**
493
- * Determines whether the bundled XPath polyfill must be injected before the in-page client is
494
- * installed. Honors an explicit `options.xpathPolyfill` boolean; otherwise reuses a previously
495
- * probed `capabilities.xpath`, or probes the page's native `document.evaluate`. The probe appends
496
- * two throwaway elements distinguished only by text content and asserts that a text-value XPath
497
- * predicate (`normalize-space(string(.))=...`, the basis of every fuzzy/clickable locator) resolves
498
- * to exactly the matching one — merely checking that `document.evaluate` runs without throwing is
499
- * not enough, since some engines execute a text-value predicate without actually filtering by it,
500
- * silently returning every candidate node instead of none or one. The result is cached on
501
- * `capabilities.xpath` (`'native'` or `'polyfill'`).
502
- *
503
- * @returns {Promise<boolean>} `true` if the polyfill should be injected.
504
- * @protected
505
- */
506
549
  async _needsXPathPolyfill() {
507
550
  if (this.options.xpathPolyfill === true) return true
508
551
  if (this.options.xpathPolyfill === false) return false
@@ -527,18 +570,6 @@ class CDPBrowser extends Helper {
527
570
  return !ok
528
571
  }
529
572
 
530
- /**
531
- * Determines whether `see`/`dontSee`/`waitForText` should read whole-page text through the
532
- * client's own visibility-aware `visibleText()` walker instead of the native
533
- * `document.body.innerText`. Probes once per page by appending a `display:none` element and a
534
- * `<script>` element, each with distinguishing text, and checking that native `innerText`
535
- * excludes both — some engines return an `innerText` that does not honor computed visibility or
536
- * exclude script/style content, even when `getComputedStyle`/layout are otherwise reliable. The
537
- * result is cached on `capabilities.innerText` (`'native'` or `'computed'`).
538
- *
539
- * @returns {Promise<boolean>} `true` if the `visibleText()` fallback should be used.
540
- * @protected
541
- */
542
573
  async _needsVisibleTextFallback() {
543
574
  if (this.capabilities.innerText) return this.capabilities.innerText === 'computed'
544
575
  const ok = await this._evaluate(`(function(){
@@ -562,27 +593,6 @@ class CDPBrowser extends Helper {
562
593
  return !ok
563
594
  }
564
595
 
565
- /**
566
- * Probes and caches capabilities that depend on the actual browser *engine* rather than any
567
- * particular page's content: `capabilities.layout` (via `getComputedStyle`), `capabilities.screenshot`
568
- * (inferred from `layout`), `capabilities.xpath` (via `_needsXPathPolyfill`), and
569
- * `capabilities.innerText` (via `_needsVisibleTextFallback`). Already-known capabilities
570
- * (pre-seeded through `options.capabilities`, or probed earlier) are never re-probed — so, across
571
- * a whole run, this issues a handful of `_evaluate` calls exactly once and is a no-op afterward.
572
- *
573
- * Called from `_before`, against the fresh `about:blank` target created there, specifically so
574
- * these probes run before any real navigation — measured directly (a full stall ledger against
575
- * `github.com`) that running them on the first *real* page instead can cost seconds each, since
576
- * every one is an `_evaluate` competing with that page's own JavaScript for the V8 isolate.
577
- * `about:blank` has no such competition. Also called (cheaply, already cached by then) from
578
- * `amOnPage`, so a helper that skips `_before` for some reason still probes correctly.
579
- *
580
- * The `xpath`/`innerText` probes determine *whether* their respective fallback is needed; they
581
- * do not install anything — injection stays deferred to `_ensureClient`'s reactive install and
582
- * `_textSource`'s own read, matching `amOnPage` no longer eagerly installing the client.
583
- *
584
- * @protected
585
- */
586
596
  async _probeCapabilities() {
587
597
  if (this.capabilities.layout === null) {
588
598
  const display = await this._evaluate(`getComputedStyle(document.documentElement).display`)
@@ -602,47 +612,10 @@ class CDPBrowser extends Helper {
602
612
  }
603
613
  }
604
614
 
605
- /**
606
- * Delegates a find-and-act call to `window.__codecept.run(candidates, action, payload)`. This is
607
- * the primary extension point used by helpers built on top of this class for element queries and
608
- * interactions.
609
- *
610
- * A per-call `context` locator, when given, is resolved and layered on top of any active
611
- * `within` block (searched inside it, not instead of it), so `context` narrows the search
612
- * without breaking out of a surrounding `within`.
613
- *
614
- * @param {Array<{type: 'css'|'xpath', value: string}>} candidates - locator strategies to try, in order, until one matches at least one element.
615
- * @param {string} action - name of the action to run against the matched elements (e.g. `count`, `click`, `fill`).
616
- * @param {object} [payload] - extra data the action needs (e.g. `{ value }` for `fill`).
617
- * @param {?CodeceptJS.LocatorOrString} [context=null] - element to search in, narrowing the candidates below it.
618
- * @returns {Promise<{found: number, result: any}>} number of matched elements and the action's result.
619
- * @protected
620
- */
621
615
  async _run(candidates, action, payload, context = null) {
622
616
  return this._runSelected(candidates, action, payload, this._selectionDescriptor(), context)
623
617
  }
624
618
 
625
- /**
626
- * Same as `_run`, but takes an explicit selection descriptor instead of reading one from
627
- * `store.currentStep`/`options.strict`. Used internally by `CDPElementHandle` to address one
628
- * specific element out of a candidate set by its 1-based index.
629
- *
630
- * The in-page client's presence is checked in the same round-trip as the action itself: the
631
- * evaluated expression resolves to a sentinel string when `window.__codecept` is missing (e.g.
632
- * right after a navigation the registered script didn't reach), in which case the client is
633
- * installed and the call is retried exactly once. Separately, if the client is already present
634
- * but reports (via its own `'__NO_XPATH__'` sentinel) that this call needs the XPath polyfill and
635
- * it was not bundled into that earlier install, the polyfill is injected and the call is retried
636
- * once more — see `_installClient`.
637
- *
638
- * @param {Array<{type: 'css'|'xpath', value: string}>} candidates
639
- * @param {string} action
640
- * @param {object|null} payload
641
- * @param {object|null} selection - `{index}` or `{strict: true}`, mirroring `_selectionDescriptor`.
642
- * @param {?CodeceptJS.LocatorOrString} [context=null]
643
- * @returns {Promise<{found: number, result: any}>}
644
- * @protected
645
- */
646
619
  async _runSelected(candidates, action, payload, selection, context = null) {
647
620
  const layers = []
648
621
  if (this.withinCandidates) layers.push(this.withinCandidates)
@@ -670,17 +643,6 @@ class CDPBrowser extends Helper {
670
643
  return res
671
644
  }
672
645
 
673
- /**
674
- * Builds the `{index, strict}` element-selection descriptor from the current step's options
675
- * (`store.currentStep.opts`) and `options.strict`, mirroring the semantics of
676
- * `lib/helper/extras/elementSelection.js` (used by Puppeteer/WebDriver): a per-step
677
- * `elementIndex` (numeric, or the `'first'`/`'last'` aliases) always takes precedence and
678
- * disables strict mode for that step; otherwise `exact`/`strictMode` per-step options
679
- * override `options.strict` to enable or cancel strict mode.
680
- *
681
- * @returns {object|null} descriptor with optional `index` and `strict` keys, or `null` when neither applies.
682
- * @protected
683
- */
684
646
  _selectionDescriptor() {
685
647
  const opts = store.currentStep?.opts
686
648
  let index = opts?.elementIndex
@@ -693,27 +655,10 @@ class CDPBrowser extends Helper {
693
655
  return strict ? { strict: true } : null
694
656
  }
695
657
 
696
- /**
697
- * A short, human-readable label built from `candidates`, used in `_run`'s elementIndex/strict
698
- * error messages when no locator string is otherwise available.
699
- *
700
- * @param {?Array<{type: 'css'|'xpath', value: string}>} candidates
701
- * @returns {string}
702
- * @protected
703
- */
704
658
  _candidatesLabel(candidates) {
705
659
  return (candidates || []).map(c => c.value).join(' | ')
706
660
  }
707
661
 
708
- /**
709
- * Starts a `within` block, scoping every subsequent `_run` call (and therefore every element
710
- * lookup performed by this helper) to the descendants of the element matched by `locator`.
711
- * Verifies the element exists (against the full document, i.e. unscoped) before narrowing.
712
- *
713
- * @param {CodeceptJS.LocatorOrString} locator - element located by CSS|XPath|strict locator.
714
- * @returns {Promise<void>}
715
- * @throws {ElementNotFound} if no element matches `locator`.
716
- */
717
662
  async _withinBegin(locator) {
718
663
  const candidates = this._candidates(locator)
719
664
  const { found } = await this._run(candidates, 'count')
@@ -721,27 +666,10 @@ class CDPBrowser extends Helper {
721
666
  this.withinCandidates = candidates
722
667
  }
723
668
 
724
- /**
725
- * Ends the current `within` block, restoring unscoped element lookups.
726
- *
727
- * @returns {Promise<void>}
728
- */
729
669
  async _withinEnd() {
730
670
  this.withinCandidates = null
731
671
  }
732
672
 
733
- /**
734
- * Repeatedly calls `fn` until it returns a truthy value or `timeoutSec` elapses, checking
735
- * immediately and waiting `options.pollInterval` milliseconds between subsequent attempts.
736
- *
737
- * @param {function} fn - the condition to poll; should resolve to a truthy value once satisfied.
738
- * @param {number} timeoutSec - maximum time to poll, in seconds.
739
- * @param {string} message - error message used when the timeout is reached.
740
- * @param {?{cancelled: boolean}} [cancelToken] - when `cancelled` becomes `true` (set by the caller from outside), polling stops early with an error instead of continuing to `timeoutSec`. Used by `_waitForPageLoad` to tear down the losing side of a race instead of leaving it running.
741
- * @returns {Promise<any>} the truthy value returned by `fn`.
742
- * @throws {Error} with `message` if `timeoutSec` elapses without `fn` returning a truthy value, or a cancellation error if `cancelToken.cancelled` is set first.
743
- * @protected
744
- */
745
673
  async _poll(fn, timeoutSec, message, cancelToken) {
746
674
  const deadline = Date.now() + timeoutSec * 1000
747
675
  while (Date.now() < deadline) {
@@ -754,43 +682,13 @@ class CDPBrowser extends Helper {
754
682
  throw new Error(message)
755
683
  }
756
684
 
757
- /**
758
- * Resolves a path against `options.url`. Absolute URLs (matching `scheme://`) are returned
759
- * unchanged; anything else is appended to `options.url` with its trailing slash stripped.
760
- *
761
- * @param {string} path - an absolute URL or a path relative to `options.url`.
762
- * @returns {string} the resolved, absolute URL.
763
- * @protected
764
- */
765
685
  _url(path) {
766
686
  if (/^\w+:\/\//.test(path)) return path
767
687
  return this.options.url.replace(/\/$/, '') + path
768
688
  }
769
689
 
770
690
  /**
771
- * Opens a web page in the current session.
772
- *
773
- * ```js
774
- * I.amOnPage('/'); // opens main page of website
775
- * I.amOnPage('https://github.com'); // opens github
776
- * I.amOnPage('/login'); // opens a login page
777
- * ```
778
- *
779
- * Navigates via `Page.navigate`, then waits (up to `options.getPageTimeout` seconds) for the page
780
- * to finish loading, preferring the push-based `Page.lifecycleEvent` signal (per
781
- * `options.waitForNavigation`) over polling `document.readyState`. Capabilities are (re-)probed
782
- * (a no-op after the first page, since they're cached for the helper's lifetime).
783
- *
784
- * The in-page client is deliberately *not* eagerly (re-)installed here — navigation discards any
785
- * previously injected script, but installing it is deferred to the first actual action after
786
- * this call, via `_runSelected`'s sentinel-and-retry. This keeps `amOnPage` itself down to the
787
- * navigate command plus the push-based wait: no `_evaluate` call is issued on this hot path,
788
- * which matters most right when the page's own JavaScript may still be busy (measured directly:
789
- * an `_evaluate` sent in that window can queue behind it for hundreds of ms to multiple seconds
790
- * on a JS-heavy real-world page, regardless of how small the evaluated expression is).
791
- *
792
- * @param {string} url - url path or global url.
793
- * @returns {Promise<void>}
691
+ * {{> amOnPage }}
794
692
  */
795
693
  async amOnPage(url) {
796
694
  const navRes = await this.cdp.send('Page.navigate', { url: this._url(url) }, this.sessionId)
@@ -799,16 +697,7 @@ class CDPBrowser extends Helper {
799
697
  }
800
698
 
801
699
  /**
802
- * Reloads the current page.
803
- *
804
- * ```js
805
- * I.refreshPage();
806
- * ```
807
- *
808
- * Triggers `Page.reload` and waits (up to `options.getPageTimeout` seconds) for
809
- * `document.readyState` to reach `'complete'`.
810
- *
811
- * @returns {Promise<void>}
700
+ * {{> refreshPage }}
812
701
  */
813
702
  async refreshPage() {
814
703
  await this.cdp.send('Page.reload', {}, this.sessionId)
@@ -816,22 +705,7 @@ class CDPBrowser extends Helper {
816
705
  }
817
706
 
818
707
  /**
819
- * Executes a JavaScript function in the browser context and returns its result.
820
- *
821
- * If a function is passed, it is serialized with `Function.prototype.toString()`, so it must
822
- * not reference variables from the outer (Node.js) scope — pass any needed data as arguments
823
- * instead. A string is evaluated as-is.
824
- *
825
- * ```js
826
- * let title = await I.executeScript(() => document.title);
827
- * let sum = await I.executeScript((a, b) => a + b, 2, 3);
828
- * ```
829
- *
830
- * If the function returns a promise, `executeScript` waits for it to resolve.
831
- *
832
- * @param {(string|function)} fn - a JavaScript function to be executed in the browser context, or a string expression.
833
- * @param {...any} args - arguments to pass into the function.
834
- * @returns {Promise<any>} the value returned (or resolved) by the function.
708
+ * {{> executeScript }}
835
709
  */
836
710
  async executeScript(fn, ...args) {
837
711
  const body = typeof fn === 'function' ? `(${fn.toString()})(...${JSON.stringify(args)})` : fn
@@ -839,62 +713,26 @@ class CDPBrowser extends Helper {
839
713
  }
840
714
 
841
715
  /**
842
- * Retrieves the page URL of the current page.
843
- *
844
- * ```js
845
- * let url = await I.grabCurrentUrl();
846
- * console.log(`Current URL is [${url}]`);
847
- * ```
848
- *
849
- * @returns {Promise<string>} current URL.
716
+ * {{> grabCurrentUrl }}
850
717
  */
851
718
  async grabCurrentUrl() {
852
719
  return this._evaluate('window.location.href')
853
720
  }
854
721
 
855
722
  /**
856
- * Retrieves a page title.
857
- *
858
- * ```js
859
- * let title = await I.grabTitle();
860
- * ```
861
- *
862
- * @returns {Promise<string>} title of the page.
723
+ * {{> grabTitle }}
863
724
  */
864
725
  async grabTitle() {
865
726
  return this._evaluate('document.title')
866
727
  }
867
728
 
868
729
  /**
869
- * Retrieves the source code of the current page.
870
- *
871
- * ```js
872
- * let pageSource = await I.grabSource();
873
- * ```
874
- *
875
- * @returns {Promise<string>} source code of the current page (the outer HTML of `<html>`).
730
+ * {{> grabSource }}
876
731
  */
877
732
  async grabSource() {
878
733
  return this._evaluate('document.documentElement.outerHTML')
879
734
  }
880
735
 
881
- /**
882
- * Builds the list of `{type, value}` candidates `_run` should try, in order, for a given
883
- * locator and `kind`. A strict locator (CSS/XPath/object form) resolves to a single candidate.
884
- * A fuzzy (plain-text) locator is expanded into a strategy-specific list of XPath expressions
885
- * mirroring the click/field/checkbox matching used by other browser helpers (matching by
886
- * visible text, label, name, placeholder, ARIA attributes, etc.), falling back to treating the
887
- * raw text as a CSS selector.
888
- *
889
- * A role locator (`{role, text, exact}`) resolves to a single `role`-type candidate, resolved
890
- * in-page by the client's implicit ARIA role mapping (native elements) plus explicit `role`
891
- * attributes, filtered by accessible name/text when `text` is given.
892
- *
893
- * @param {CodeceptJS.LocatorOrString} locator - element located by CSS|XPath|strict locator, or plain fuzzy text.
894
- * @param {'element'|'clickable'|'field'|'checkable'} [kind='element'] - matching strategy to use when `locator` is fuzzy.
895
- * @returns {Array<{type: 'css'|'xpath'|'role', value: (string|object)}>} candidates to pass to `_run`.
896
- * @protected
897
- */
898
736
  _candidates(locator, kind = 'element') {
899
737
  locator = new Locator(locator)
900
738
  if (locator.isShadow()) {
@@ -934,18 +772,6 @@ class CDPBrowser extends Helper {
934
772
  return [{ type: 'css', value: locator.value }]
935
773
  }
936
774
 
937
- /**
938
- * Resolves the text to search `see`/`dontSee`/`waitForText` against, when no explicit `context`
939
- * locator is given. An explicit `context` is always resolved through `_run`, so it is implicitly
940
- * scoped to the active `within` block, if any. Without a `context`, this reads the `within` root's
941
- * text when a `within` block is active, or the whole page's text otherwise — via native
942
- * `document.body.innerText`, or the client's `visibleText()` walker when
943
- * `_needsVisibleTextFallback` determines native `innerText` is not trustworthy.
944
- *
945
- * @param {?CodeceptJS.LocatorOrString} context
946
- * @returns {Promise<string>}
947
- * @protected
948
- */
949
775
  async _textSource(context) {
950
776
  if (context) return (await this._texts(this._candidates(context))).result?.join(' | ') || ''
951
777
  if (this.withinCandidates) return (await this._texts(null)).result?.join(' | ') || ''
@@ -956,32 +782,6 @@ class CDPBrowser extends Helper {
956
782
  return this._evaluate('document.body ? document.body.innerText : ""')
957
783
  }
958
784
 
959
- /**
960
- * Runs the in-page `containsText` check against the whole page (no `context`/`within` scoping —
961
- * those stay on `_textSource`'s per-element path, already small). Returns only `{found, snippet}`
962
- * instead of the full haystack: on a page with a large body, serializing that whole string across
963
- * the CDP wire (and, on engines where `capabilities.innerText` requires the `visibleText()`
964
- * walker, holding it in memory) is avoidable work `see`/`dontSee`/`waitForText` don't actually
965
- * need on their common, non-throwing path.
966
- *
967
- * Also folds the client's install into the very same round trip when it is still missing, instead
968
- * of a separate presence-check evaluate followed by an install evaluate before the check itself
969
- * can even run — mirroring `_runSelected`'s sentinel-retry design, but collapsed into one evaluate
970
- * since the install source itself is known and cacheable up front. That install is client-only,
971
- * never the 171KB XPath polyfill: `containsText` never calls `document.evaluate`, so bundling it
972
- * here would be pure waste for a scenario that never resolves an xpath locator. The client is
973
- * still told, via `installCodeceptClient`'s `xpathNeedsPolyfill` flag, whether the *engine*
974
- * (`capabilities.xpath`, cached by `_before`'s `about:blank` probe) will eventually need it, so a
975
- * later xpath-resolving action on the same page gets a clean `'__NO_XPATH__'` miss signal from
976
- * `window.__codecept.run` instead of silently hitting a broken native `document.evaluate` —
977
- * `_runSelected` reacts to that sentinel already. The bootstrap source is built once and reused
978
- * for the life of the instance, since whether the engine needs the polyfill never changes.
979
- *
980
- * @param {string} text
981
- * @param {{ignoreCase: boolean, useWalker: boolean}} opts
982
- * @returns {Promise<{found: boolean, snippet: (string|null)}>}
983
- * @protected
984
- */
985
785
  async _runTextCheck(text, opts) {
986
786
  if (!this._textCheckBootstrap) {
987
787
  const needsPolyfill = await this._needsXPathPolyfill()
@@ -991,19 +791,6 @@ class CDPBrowser extends Helper {
991
791
  return this._evaluate(expression)
992
792
  }
993
793
 
994
- /**
995
- * Shared implementation for `see`/`dontSee`. Without a `context` locator and outside any `within`
996
- * block, checks presence via `_runTextCheck`'s fast, boolean-only round trip; the full haystack is
997
- * only fetched (one extra, rare evaluate) when the assertion is about to fail, to build the same
998
- * `stringIncludes` error as before this optimization. With a `context` or inside `within`, this is
999
- * unchanged from before — already a small, per-element read, not the identified cost.
1000
- *
1001
- * @param {string} text
1002
- * @param {?CodeceptJS.LocatorOrString} context
1003
- * @param {boolean} negate
1004
- * @returns {Promise<void>}
1005
- * @protected
1006
- */
1007
794
  async _checkText(text, context, negate) {
1008
795
  const label = context ? `element ${new Locator(context).toString()}` : 'web page'
1009
796
  const ignoreCase = store.currentStep?.opts?.ignoreCase === true
@@ -1031,112 +818,56 @@ class CDPBrowser extends Helper {
1031
818
  }
1032
819
 
1033
820
  /**
1034
- * Checks that a page contains a visible text.
1035
- * Use context parameter to narrow down the search.
1036
- *
1037
- * ```js
1038
- * I.see('Welcome'); // text welcome on a page
1039
- * I.see('Welcome', '.content'); // text inside .content div
1040
- * I.see('Register', {css: 'form.register'}); // use strict locator
1041
- * ```
1042
- *
1043
- * @param {string} text expected on page.
1044
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text.
1045
- * @returns {Promise<void>}
821
+ * {{> see }}
1046
822
  */
1047
823
  async see(text, context = null) {
1048
824
  return this._checkText(text, context, false)
1049
825
  }
1050
826
 
1051
827
  /**
1052
- * Opposite to `see`. Checks that a text is not present on a page.
1053
- * Use context parameter to narrow down the search.
1054
- *
1055
- * ```js
1056
- * I.dontSee('Login'); // assume we are already logged in.
1057
- * I.dontSee('Login', '.nav'); // no login inside .nav element
1058
- * ```
1059
- *
1060
- * @param {string} text which is not present.
1061
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional) element located by CSS|XPath|strict locator in which to perform search.
1062
- * @returns {Promise<void>}
828
+ * {{> dontSee }}
1063
829
  */
1064
830
  async dontSee(text, context = null) {
1065
831
  return this._checkText(text, context, true)
1066
832
  }
1067
833
 
1068
834
  /**
1069
- * Checks that the current page contains the given string in its raw source code.
1070
- *
1071
- * ```js
1072
- * I.seeInSource('<h1>Green eggs &amp; ham</h1>');
1073
- * ```
1074
- *
1075
- * @param {string} text value to check.
1076
- * @returns {Promise<void>}
835
+ * {{> seeInSource }}
1077
836
  */
1078
837
  async seeInSource(text) {
1079
838
  return stringIncludes('HTML source of a page').assert(text, await this.grabSource())
1080
839
  }
1081
840
 
1082
841
  /**
1083
- * Checks that the current page does not contain the given string in its raw source code.
1084
- *
1085
- * @param {string} text value to check.
1086
- * @returns {Promise<void>}
842
+ * {{> dontSeeInSource }}
1087
843
  */
1088
844
  async dontSeeInSource(text) {
1089
845
  return stringIncludes('HTML source of a page').negate(text, await this.grabSource())
1090
846
  }
1091
847
 
1092
848
  /**
1093
- * Checks that current url contains a provided fragment.
1094
- *
1095
- * ```js
1096
- * I.seeInCurrentUrl('/register'); // we are on registration page
1097
- * ```
1098
- *
1099
- * @param {string} url a fragment to check
1100
- * @returns {Promise<void>}
849
+ * {{> seeInCurrentUrl }}
1101
850
  */
1102
851
  async seeInCurrentUrl(url) {
1103
852
  return stringIncludes('url').assert(url, await this.grabCurrentUrl())
1104
853
  }
1105
854
 
1106
855
  /**
1107
- * Checks that current url does not contain a provided fragment.
1108
- *
1109
- * @param {string} url value to check.
1110
- * @returns {Promise<void>}
856
+ * {{> dontSeeInCurrentUrl }}
1111
857
  */
1112
858
  async dontSeeInCurrentUrl(url) {
1113
859
  return stringIncludes('url').negate(url, await this.grabCurrentUrl())
1114
860
  }
1115
861
 
1116
862
  /**
1117
- * Checks that title contains text.
1118
- *
1119
- * ```js
1120
- * I.seeInTitle('Home Page');
1121
- * ```
1122
- *
1123
- * @param {string} text text value to check.
1124
- * @returns {Promise<void>}
863
+ * {{> seeInTitle }}
1125
864
  */
1126
865
  async seeInTitle(text) {
1127
866
  return stringIncludes('web page title').assert(text, await this.grabTitle())
1128
867
  }
1129
868
 
1130
869
  /**
1131
- * Checks that a given Element is present in the DOM.
1132
- * Element is located by CSS or XPath.
1133
- *
1134
- * ```js
1135
- * I.seeElementInDOM('#modal');
1136
- * ```
1137
- *
1138
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1139
- * @returns {Promise<void>}
870
+ * {{> seeElementInDOM }}
1140
871
  */
1141
872
  async seeElementInDOM(locator) {
1142
873
  const { found } = await this._run(this._candidates(locator), 'count')
@@ -1144,28 +875,13 @@ class CDPBrowser extends Helper {
1144
875
  }
1145
876
 
1146
877
  /**
1147
- * Opposite to `seeElementInDOM`. Checks that element is not on page.
1148
- *
1149
- * ```js
1150
- * I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
1151
- * ```
1152
- *
1153
- * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator.
1154
- * @returns {Promise<void>}
878
+ * {{> dontSeeElementInDOM }}
1155
879
  */
1156
880
  async dontSeeElementInDOM(locator) {
1157
881
  const { found } = await this._run(this._candidates(locator), 'count')
1158
882
  return empty(`elements of ${new Locator(locator).toString()}`).assert(found === 0 ? null : found)
1159
883
  }
1160
884
 
1161
- /**
1162
- * Throws if the current page has no real layout engine (`capabilities.layout === 'none'`),
1163
- * used to guard visibility-dependent assertions that cannot be evaluated without one.
1164
- *
1165
- * @param {string} action - name of the calling assertion, used in the error message.
1166
- * @throws {Error} if the page has no layout engine.
1167
- * @protected
1168
- */
1169
885
  _assertLayoutSupported(action) {
1170
886
  if (this.capabilities.layout === 'none') {
1171
887
  throw new Error(`${action} requires a layout engine which this browser does not provide. Use ${action}InDOM instead.`)
@@ -1173,16 +889,7 @@ class CDPBrowser extends Helper {
1173
889
  }
1174
890
 
1175
891
  /**
1176
- * Checks that a given Element is visible.
1177
- * Element is located by CSS or XPath.
1178
- *
1179
- * ```js
1180
- * I.seeElement('#modal');
1181
- * ```
1182
- *
1183
- * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator.
1184
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1185
- * @returns {Promise<void>}
892
+ * {{> seeElement }}
1186
893
  */
1187
894
  async seeElement(locator, context = null) {
1188
895
  this._assertLayoutSupported('seeElement')
@@ -1191,15 +898,7 @@ class CDPBrowser extends Helper {
1191
898
  }
1192
899
 
1193
900
  /**
1194
- * Opposite to `seeElement`. Checks that element is not visible.
1195
- *
1196
- * ```js
1197
- * I.dontSeeElement('.modal'); // modal is not shown
1198
- * ```
1199
- *
1200
- * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator.
1201
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1202
- * @returns {Promise<void>}
901
+ * {{> dontSeeElement }}
1203
902
  */
1204
903
  async dontSeeElement(locator, context = null) {
1205
904
  this._assertLayoutSupported('dontSeeElement')
@@ -1208,16 +907,7 @@ class CDPBrowser extends Helper {
1208
907
  }
1209
908
 
1210
909
  /**
1211
- * Verifies that the specified checkbox is checked.
1212
- *
1213
- * ```js
1214
- * I.seeCheckboxIsChecked('Agree');
1215
- * I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
1216
- * I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
1217
- * ```
1218
- *
1219
- * @param {CodeceptJS.LocatorOrString} locator located by label|name|CSS|XPath|strict locator.
1220
- * @returns {Promise<void>}
910
+ * {{> seeCheckboxIsChecked }}
1221
911
  */
1222
912
  async seeCheckboxIsChecked(locator) {
1223
913
  const res = await this._run(this._candidates(locator, 'checkable'), 'checked')
@@ -1226,15 +916,7 @@ class CDPBrowser extends Helper {
1226
916
  }
1227
917
 
1228
918
  /**
1229
- * Verifies that the specified checkbox is not checked.
1230
- *
1231
- * ```js
1232
- * I.dontSeeCheckboxIsChecked('#agree'); // located by ID
1233
- * I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
1234
- * ```
1235
- *
1236
- * @param {CodeceptJS.LocatorOrString} locator located by label|name|CSS|XPath|strict locator.
1237
- * @returns {Promise<void>}
919
+ * {{> dontSeeCheckboxIsChecked }}
1238
920
  */
1239
921
  async dontSeeCheckboxIsChecked(locator) {
1240
922
  const res = await this._run(this._candidates(locator, 'checkable'), 'checked')
@@ -1243,16 +925,7 @@ class CDPBrowser extends Helper {
1243
925
  }
1244
926
 
1245
927
  /**
1246
- * Retrieves a text from an element located by CSS or XPath and returns it to test.
1247
- * Resumes test execution, so **should be used inside async with `await`** operator.
1248
- *
1249
- * ```js
1250
- * let pin = await I.grabTextFrom('#pin');
1251
- * ```
1252
- * If multiple elements found returns first element.
1253
- *
1254
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1255
- * @returns {Promise<string>} text value
928
+ * {{> grabTextFrom }}
1256
929
  */
1257
930
  async grabTextFrom(locator) {
1258
931
  const res = await this._texts(this._candidates(locator))
@@ -1261,15 +934,7 @@ class CDPBrowser extends Helper {
1261
934
  }
1262
935
 
1263
936
  /**
1264
- * Retrieves all texts from elements located by CSS or XPath and returns it to test.
1265
- * Resumes test execution, so **should be used inside async with `await`** operator.
1266
- *
1267
- * ```js
1268
- * let pins = await I.grabTextFromAll('#pin li');
1269
- * ```
1270
- *
1271
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1272
- * @returns {Promise<string[]>} array of text values
937
+ * {{> grabTextFromAll }}
1273
938
  */
1274
939
  async grabTextFromAll(locator) {
1275
940
  const res = await this._texts(this._candidates(locator))
@@ -1277,17 +942,7 @@ class CDPBrowser extends Helper {
1277
942
  }
1278
943
 
1279
944
  /**
1280
- * Retrieves an array of `WebElement`s matching a locator (`lib/element/WebElement.js`,
1281
- * wrapping a `CDPElementHandle`). Element handles are re-resolved on demand by re-running
1282
- * `candidates` and picking the matching index, since `CDPBrowser` never keeps a persistent
1283
- * handle to a DOM node on the Node side.
1284
- *
1285
- * ```js
1286
- * const buttons = await I.grabWebElements({ role: 'button' });
1287
- * ```
1288
- *
1289
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1290
- * @returns {Promise<object[]>} array of WebElement instances.
945
+ * {{> grabWebElements }}
1291
946
  */
1292
947
  async grabWebElements(locator) {
1293
948
  const candidates = this._candidates(locator)
@@ -1296,15 +951,7 @@ class CDPBrowser extends Helper {
1296
951
  }
1297
952
 
1298
953
  /**
1299
- * Retrieves the first `WebElement` matching a locator.
1300
- *
1301
- * ```js
1302
- * const button = await I.grabWebElement({ role: 'button', text: 'Submit' });
1303
- * ```
1304
- *
1305
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1306
- * @returns {Promise<object>} a WebElement instance.
1307
- * @throws {ElementNotFound} if no element matches `locator`.
954
+ * {{> grabWebElement }}
1308
955
  */
1309
956
  async grabWebElement(locator) {
1310
957
  const elements = await this.grabWebElements(locator)
@@ -1312,31 +959,13 @@ class CDPBrowser extends Helper {
1312
959
  return elements[0]
1313
960
  }
1314
961
 
1315
- /**
1316
- * Resolves whether the `texts` action should read via the client's `visibleText()` walker
1317
- * (probed once via `_needsVisibleTextFallback` and cached on `capabilities.innerText`) instead
1318
- * of each element's native `innerText`, then runs it.
1319
- *
1320
- * @param {Array<{type: string, value: (string|object)}>} candidates
1321
- * @returns {Promise<{found: number, result: any}>}
1322
- * @protected
1323
- */
1324
962
  async _texts(candidates) {
1325
963
  const visible = await this._needsVisibleTextFallback()
1326
964
  return this._run(candidates, 'texts', { visible })
1327
965
  }
1328
966
 
1329
967
  /**
1330
- * Retrieves a value from a form element located by CSS or XPath and returns it to test.
1331
- * Resumes test execution, so **should be used inside async function with `await`** operator.
1332
- * If more than one element is found - value of first element is returned.
1333
- *
1334
- * ```js
1335
- * let email = await I.grabValueFrom('input[name=email]');
1336
- * ```
1337
- *
1338
- * @param {CodeceptJS.LocatorOrString} locator field located by label|name|CSS|XPath|strict locator.
1339
- * @returns {Promise<string>} attribute value
968
+ * {{> grabValueFrom }}
1340
969
  */
1341
970
  async grabValueFrom(locator) {
1342
971
  const res = await this._run(this._candidates(locator, 'field'), 'values')
@@ -1345,15 +974,7 @@ class CDPBrowser extends Helper {
1345
974
  }
1346
975
 
1347
976
  /**
1348
- * Retrieves an array of values from fields located by CSS or XPath and returns it to test.
1349
- * Resumes test execution, so **should be used inside async function with `await`** operator.
1350
- *
1351
- * ```js
1352
- * let inputs = await I.grabValueFromAll('//form/input');
1353
- * ```
1354
- *
1355
- * @param {CodeceptJS.LocatorOrString} locator field located by label|name|CSS|XPath|strict locator.
1356
- * @returns {Promise<string[]>} array of attribute values
977
+ * {{> grabValueFromAll }}
1357
978
  */
1358
979
  async grabValueFromAll(locator) {
1359
980
  const res = await this._run(this._candidates(locator, 'field'), 'values')
@@ -1361,17 +982,7 @@ class CDPBrowser extends Helper {
1361
982
  }
1362
983
 
1363
984
  /**
1364
- * Retrieves an attribute from an element located by CSS or XPath and returns it to test.
1365
- * Resumes test execution, so **should be used inside async with `await`** operator.
1366
- * If more than one element is found - attribute of first element is returned.
1367
- *
1368
- * ```js
1369
- * let hint = await I.grabAttributeFrom('#tooltip', 'title');
1370
- * ```
1371
- *
1372
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1373
- * @param {string} attr attribute name.
1374
- * @returns {Promise<string>} attribute value
985
+ * {{> grabAttributeFrom }}
1375
986
  */
1376
987
  async grabAttributeFrom(locator, attr) {
1377
988
  const res = await this._run(this._candidates(locator), 'attrs', { name: attr })
@@ -1380,16 +991,7 @@ class CDPBrowser extends Helper {
1380
991
  }
1381
992
 
1382
993
  /**
1383
- * Retrieves an array of attributes from elements located by CSS or XPath and returns it to test.
1384
- * Resumes test execution, so **should be used inside async with `await`** operator.
1385
- *
1386
- * ```js
1387
- * let hints = await I.grabAttributeFromAll('.tooltip', 'title');
1388
- * ```
1389
- *
1390
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1391
- * @param {string} attr attribute name.
1392
- * @returns {Promise<string[]>} array of attribute values
994
+ * {{> grabAttributeFromAll }}
1393
995
  */
1394
996
  async grabAttributeFromAll(locator, attr) {
1395
997
  const res = await this._run(this._candidates(locator), 'attrs', { name: attr })
@@ -1412,35 +1014,8 @@ class CDPBrowser extends Helper {
1412
1014
  return found
1413
1015
  }
1414
1016
 
1415
- /**
1416
- * Perform a click on a link or a button, given by a locator.
1417
- * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
1418
- * For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
1419
- * For images, the "alt" attribute and inner text of any parent links are searched.
1420
- *
1421
- * When `options.input` is `'cdp'`, the click is dispatched as real `Input.dispatchMouseEvent` mouse events
1422
- * (`mouseMoved` / `mousePressed` / `mouseReleased`) at the center of the element's bounding box, so it
1423
- * exercises the same input pipeline a real user would. Otherwise it delegates to `forceClick`. A matched
1424
- * element with a zero-size bounding box (e.g. `display: none`) has no valid coordinate to click and throws;
1425
- * use `forceClick` to dispatch a synthetic click on such elements instead.
1426
- *
1427
- * ```js
1428
- * // simple link
1429
- * I.click('Logout');
1430
- * // button of form
1431
- * I.click('Submit');
1432
- * // CSS button
1433
- * I.click('#form input[type=submit]');
1434
- * // XPath
1435
- * I.click('//form/*[@type=submit]');
1436
- * // using strict locator
1437
- * I.click({css: 'nav a.login'});
1438
- * ```
1439
- *
1440
- * @param {CodeceptJS.LocatorOrString} locator clickable link or button located by text, or any element located by CSS|XPath|strict locator.
1441
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1442
- * @returns {Promise<void>}
1443
- * @throws {Error} if the matched element has a zero-size bounding box.
1017
+ /**
1018
+ * {{> click }}
1444
1019
  */
1445
1020
  async click(locator, context = null) {
1446
1021
  if (this.options.input !== 'cdp') return this.forceClick(locator, context)
@@ -1460,30 +1035,7 @@ class CDPBrowser extends Helper {
1460
1035
  }
1461
1036
 
1462
1037
  /**
1463
- * Perform an emulated click on a link or a button, given by a locator.
1464
- * Unlike `click`, this always dispatches a synthetic in-page `el.click()` instead of sending native
1465
- * CDP input events. This works on hidden, animated or inactive elements as well.
1466
- *
1467
- * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
1468
- * For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
1469
- * For images, the "alt" attribute and inner text of any parent links are searched.
1470
- *
1471
- * ```js
1472
- * // simple link
1473
- * I.forceClick('Logout');
1474
- * // button of form
1475
- * I.forceClick('Submit');
1476
- * // CSS button
1477
- * I.forceClick('#form input[type=submit]');
1478
- * // XPath
1479
- * I.forceClick('//form/*[@type=submit]');
1480
- * // using strict locator
1481
- * I.forceClick({css: 'nav a.login'});
1482
- * ```
1483
- *
1484
- * @param {CodeceptJS.LocatorOrString} locator clickable link or button located by text, or any element located by CSS|XPath|strict locator.
1485
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1486
- * @returns {Promise<void>}
1038
+ * {{> forceClick }}
1487
1039
  */
1488
1040
  async forceClick(locator, context = null) {
1489
1041
  const armed = this._armActionSettle()
@@ -1492,37 +1044,6 @@ class CDPBrowser extends Helper {
1492
1044
  return this._waitForAction(armed)
1493
1045
  }
1494
1046
 
1495
- /**
1496
- * Settles after an interaction (click, key press, etc.) before the next step runs, using the
1497
- * listener `_armActionSettle` started *before* the interaction was dispatched (`armed`; a fresh
1498
- * one is armed here too, as a safety net, if a call site forgot to — but arming this late can
1499
- * only miss a navigation that already started during the action's own dispatch, exactly the race
1500
- * this design exists to avoid, so every call site should pass its own pre-armed `armed`, not rely
1501
- * on this fallback).
1502
- *
1503
- * If `options.waitForAction` was set explicitly in the config, honors it literally as a fixed
1504
- * pacing sleep, exactly as before this round — an explicit value is a deliberate choice
1505
- * (slow-motion debugging, a known-slow app) this never second-guesses.
1506
- *
1507
- * Otherwise, event-aware: races the armed listener against a *fresh* `ACTION_SETTLE_GRACE_MS`
1508
- * window (started now, not when it was armed — the action's own dispatch already ran concurrently
1509
- * with the arm, so this is genuinely bounded extra time, not a guess). If nothing declares a
1510
- * navigation, returns immediately once the window elapses — the common case for most actions
1511
- * (typing, toggling a checkbox, focusing a field) — instead of a fixed `options.waitForAction`
1512
- * (100ms by default) sleep on every single action regardless of whether anything is happening.
1513
- *
1514
- * If a navigation *did* start, `_lastMainFrameNav` (see `_ensureLifecycleListener`) is checked
1515
- * first: on a fast/local page, the entire lifecycle sequence through the target event has
1516
- * typically already arrived in the same batch that announced the navigation started, in which
1517
- * case this returns immediately. Only a navigation still genuinely in flight falls through to
1518
- * `_waitForPageLoad` (the same mechanism `amOnPage`/`refreshPage` use) — which waits for it to
1519
- * actually finish, rather than a fixed sleep that has no relationship to how long the navigation
1520
- * actually takes: strictly more correct for a slow navigation, not just faster for a fast one.
1521
- *
1522
- * @param {({promise: Promise<string|null>, cancel: function}|null)} [armed] - from `_armActionSettle`, called before the action.
1523
- * @returns {Promise<void>}
1524
- * @protected
1525
- */
1526
1047
  async _waitForAction(armed) {
1527
1048
  if (this._waitForActionExplicit) {
1528
1049
  return new Promise(r => setTimeout(r, this.options.waitForAction))
@@ -1547,24 +1068,7 @@ class CDPBrowser extends Helper {
1547
1068
  }
1548
1069
 
1549
1070
  /**
1550
- * Fills a text field or textarea, after clearing its value, with the given string.
1551
- * Field is located by name, label, CSS, or XPath.
1552
- *
1553
- * ```js
1554
- * // by label
1555
- * I.fillField('Email', 'hello@world.com');
1556
- * // by name
1557
- * I.fillField('password', secret('123456'));
1558
- * // by CSS
1559
- * I.fillField('form#login input[name=username]', 'John');
1560
- * // or by strict locator
1561
- * I.fillField({css: 'form#login input[name=username]'}, 'John');
1562
- * ```
1563
- *
1564
- * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
1565
- * @param {CodeceptJS.StringOrSecret} value text value to fill.
1566
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1567
- * @returns {Promise<void>}
1071
+ * {{> fillField }}
1568
1072
  */
1569
1073
  async fillField(field, value, context = null) {
1570
1074
  const res = await this._run(this._candidates(field, 'field'), 'fill', { value: String(value) }, context)
@@ -1572,19 +1076,7 @@ class CDPBrowser extends Helper {
1572
1076
  }
1573
1077
 
1574
1078
  /**
1575
- * Appends text to a input field or textarea.
1576
- * Field is located by name, label, CSS or XPath
1577
- *
1578
- * ```js
1579
- * I.appendField('#myTextField', 'appended');
1580
- * // typing secret
1581
- * I.appendField('password', secret('123456'));
1582
- * ```
1583
- *
1584
- * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator
1585
- * @param {string} value text value to append.
1586
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1587
- * @returns {Promise<void>}
1079
+ * {{> appendField }}
1588
1080
  */
1589
1081
  async appendField(field, value, context = null) {
1590
1082
  const res = await this._run(this._candidates(field, 'field'), 'append', { value: String(value) }, context)
@@ -1592,17 +1084,7 @@ class CDPBrowser extends Helper {
1592
1084
  }
1593
1085
 
1594
1086
  /**
1595
- * Clears a `<textarea>` or text `<input>` element's value.
1596
- *
1597
- * ```js
1598
- * I.clearField('Email');
1599
- * I.clearField('user[email]');
1600
- * I.clearField('#email');
1601
- * ```
1602
- *
1603
- * @param {CodeceptJS.LocatorOrString} field editable field located by label|name|CSS|XPath|strict locator.
1604
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1605
- * @returns {Promise<void>}
1087
+ * {{> clearField }}
1606
1088
  */
1607
1089
  async clearField(field, context = null) {
1608
1090
  const res = await this._run(this._candidates(field, 'field'), 'clear', null, context)
@@ -1610,23 +1092,7 @@ class CDPBrowser extends Helper {
1610
1092
  }
1611
1093
 
1612
1094
  /**
1613
- * Selects an option in a drop-down select.
1614
- * Field is searched by label | name | CSS | XPath.
1615
- * Option is selected by visible text or by value.
1616
- *
1617
- * ```js
1618
- * I.selectOption('Choose Plan', 'Monthly'); // select by label
1619
- * I.selectOption('subscription', 'Monthly'); // match option by text
1620
- * I.selectOption('subscription', '0'); // or by value
1621
- * I.selectOption('//form/select[@name=account]','Premium');
1622
- * I.selectOption('form select[name=account]', 'Premium');
1623
- * I.selectOption({css: 'form select[name=account]'}, 'Premium');
1624
- * ```
1625
- *
1626
- * @param {CodeceptJS.LocatorOrString} select field located by label|name|CSS|XPath|strict locator.
1627
- * @param {string|string[]} option visible text or value of option, or an array of them for a multi-select.
1628
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1629
- * @returns {Promise<void>}
1095
+ * {{> selectOption }}
1630
1096
  */
1631
1097
  async selectOption(select, option, context = null) {
1632
1098
  const value = Array.isArray(option) ? option.map(String) : String(option)
@@ -1639,18 +1105,7 @@ class CDPBrowser extends Helper {
1639
1105
  }
1640
1106
 
1641
1107
  /**
1642
- * Selects a checkbox or radio button.
1643
- * Element is located by label or name or CSS or XPath.
1644
- *
1645
- * ```js
1646
- * I.checkOption('#agree');
1647
- * I.checkOption('I Agree to Terms and Conditions');
1648
- * I.checkOption('agree', '//form');
1649
- * ```
1650
- *
1651
- * @param {CodeceptJS.LocatorOrString} field checkbox located by label | name | CSS | XPath | strict locator.
1652
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS | XPath | strict locator.
1653
- * @returns {Promise<void>}
1108
+ * {{> checkOption }}
1654
1109
  */
1655
1110
  async checkOption(field, context = null) {
1656
1111
  const res = await this._run(this._candidates(field, 'checkable'), 'check', null, context)
@@ -1658,18 +1113,7 @@ class CDPBrowser extends Helper {
1658
1113
  }
1659
1114
 
1660
1115
  /**
1661
- * Unselects a checkbox or radio button.
1662
- * Element is located by label or name or CSS or XPath.
1663
- *
1664
- * ```js
1665
- * I.uncheckOption('#agree');
1666
- * I.uncheckOption('I Agree to Terms and Conditions');
1667
- * I.uncheckOption('agree', '//form');
1668
- * ```
1669
- *
1670
- * @param {CodeceptJS.LocatorOrString} field checkbox located by label | name | CSS | XPath | strict locator.
1671
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS | XPath | strict locator.
1672
- * @returns {Promise<void>}
1116
+ * {{> uncheckOption }}
1673
1117
  */
1674
1118
  async uncheckOption(field, context = null) {
1675
1119
  const res = await this._run(this._candidates(field, 'checkable'), 'uncheck', null, context)
@@ -1677,27 +1121,7 @@ class CDPBrowser extends Helper {
1677
1121
  }
1678
1122
 
1679
1123
  /**
1680
- * Attaches a file to a file input field, or drops it onto a drag-and-drop dropzone element,
1681
- * resolved by label|name|CSS|XPath|strict locator. `pathToFile` is resolved relative to
1682
- * `codecept_dir` (matching Puppeteer/WebDriver). Since `CDPBrowser` never brings element handles
1683
- * back to Node, the resolved element is marked with a throwaway `data-codecept-upload` attribute
1684
- * in-page (respecting `context`/`within`/elementIndex exactly like every other action). A real
1685
- * `<input type="file">` is then addressed by that attribute through the CDP `DOM` domain, which
1686
- * `CDPBrowser` otherwise never uses, to call `DOM.setFileInputFiles`; any other element (a
1687
- * drag-and-drop dropzone) instead gets a synthetic `dragenter`/`dragover`/`drop` sequence with a
1688
- * `DataTransfer` built from the file's contents, entirely in-page. The marker is removed again in
1689
- * a `finally`.
1690
- *
1691
- * ```js
1692
- * I.attachFile('Avatar', 'data/avatar.jpg');
1693
- * I.attachFile('#file', 'data/avatar.jpg');
1694
- * I.attachFile('#dropzone', 'data/avatar.jpg');
1695
- * ```
1696
- *
1697
- * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
1698
- * @param {string} pathToFile path to file, relative to `codecept_dir`.
1699
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1700
- * @returns {Promise<void>}
1124
+ * {{> attachFile }}
1701
1125
  */
1702
1126
  async attachFile(field, pathToFile, context = null) {
1703
1127
  const file = path.join(store.codeceptDir, pathToFile)
@@ -1731,17 +1155,7 @@ class CDPBrowser extends Helper {
1731
1155
  }
1732
1156
 
1733
1157
  /**
1734
- * Waits for element to be present on page (by default waits for `options.waitForTimeout` seconds).
1735
- * Element can be located by CSS or XPath.
1736
- *
1737
- * ```js
1738
- * I.waitForElement('.btn.continue');
1739
- * I.waitForElement('.btn.continue', 5); // wait for 5 secs
1740
- * ```
1741
- *
1742
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
1743
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
1744
- * @returns {Promise<void>}
1158
+ * {{> waitForElement }}
1745
1159
  */
1746
1160
  async waitForElement(locator, sec = null) {
1747
1161
  const timeout = sec || this.options.waitForTimeout
@@ -1754,19 +1168,7 @@ class CDPBrowser extends Helper {
1754
1168
  }
1755
1169
 
1756
1170
  /**
1757
- * Waits for a text to appear (by default waits for `options.waitForTimeout` seconds).
1758
- * Element can be located by CSS or XPath.
1759
- * Narrow down search results by providing context.
1760
- *
1761
- * ```js
1762
- * I.waitForText('Thank you, form has been submitted');
1763
- * I.waitForText('Thank you, form has been submitted', 5, '#modal');
1764
- * ```
1765
- *
1766
- * @param {string} text to wait for.
1767
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
1768
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional) element located by CSS|XPath|strict locator.
1769
- * @returns {Promise<void>}
1171
+ * {{> waitForText }}
1770
1172
  */
1771
1173
  async waitForText(text, sec = null, context = null) {
1772
1174
  const timeout = sec || this.options.waitForTimeout
@@ -1802,15 +1204,7 @@ class CDPBrowser extends Helper {
1802
1204
  }
1803
1205
 
1804
1206
  /**
1805
- * Waiting for the part of the URL to match the expected. Useful for SPA to understand that page was changed.
1806
- *
1807
- * ```js
1808
- * I.waitInUrl('/info', 2);
1809
- * ```
1810
- *
1811
- * @param {string} urlPart value to check.
1812
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
1813
- * @returns {Promise<void>}
1207
+ * {{> waitInUrl }}
1814
1208
  */
1815
1209
  async waitInUrl(urlPart, sec = null) {
1816
1210
  const timeout = sec || this.options.waitForTimeout
@@ -1830,19 +1224,7 @@ class CDPBrowser extends Helper {
1830
1224
  }
1831
1225
 
1832
1226
  /**
1833
- * Waits for a function to return true (waits for `options.waitForTimeout` seconds by default).
1834
- * Running in browser context.
1835
- *
1836
- * ```js
1837
- * I.waitForFunction(() => window.requests == 0);
1838
- * I.waitForFunction(() => window.requests == 0, 5); // waits for 5 sec
1839
- * I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and wait for 5 sec
1840
- * ```
1841
- *
1842
- * @param {(string|function)} fn to be executed in browser context.
1843
- * @param {any[]|number} [argsOrSec] (optional) arguments for function or, if a number, seconds to wait.
1844
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
1845
- * @returns {Promise<void>}
1227
+ * {{> waitForFunction }}
1846
1228
  */
1847
1229
  async waitForFunction(fn, argsOrSec = null, sec = null) {
1848
1230
  let args = []
@@ -1858,22 +1240,7 @@ class CDPBrowser extends Helper {
1858
1240
  }
1859
1241
 
1860
1242
  /**
1861
- * Sets cookie(s).
1862
- *
1863
- * Can be a single cookie object or an array of cookies:
1864
- *
1865
- * ```js
1866
- * I.setCookie({name: 'auth', value: true});
1867
- *
1868
- * // as array
1869
- * I.setCookie([
1870
- * {name: 'auth', value: true},
1871
- * {name: 'agree', value: true}
1872
- * ]);
1873
- * ```
1874
- *
1875
- * @param {CodeceptJS.Cookie|Array<CodeceptJS.Cookie>} cookie a cookie object or array of cookie objects.
1876
- * @returns {Promise<void>}
1243
+ * {{> setCookie }}
1877
1244
  */
1878
1245
  async setCookie(cookie) {
1879
1246
  const cookies = Array.isArray(cookie) ? cookie : [cookie]
@@ -1901,17 +1268,7 @@ class CDPBrowser extends Helper {
1901
1268
  }
1902
1269
 
1903
1270
  /**
1904
- * Gets a cookie object by name.
1905
- * If none provided gets all cookies.
1906
- * Resumes test execution, so **should be used inside async function with `await`** operator.
1907
- *
1908
- * ```js
1909
- * let cookie = await I.grabCookie('auth');
1910
- * assert(cookie.value, '123456');
1911
- * ```
1912
- *
1913
- * @param {string|null} [name=null] cookie name.
1914
- * @returns {Promise<CodeceptJS.Cookie|Array<CodeceptJS.Cookie>>} a cookie object, or an array of all cookies when `name` is not provided.
1271
+ * {{> grabCookie }}
1915
1272
  */
1916
1273
  async grabCookie(name) {
1917
1274
  const cookies = await this.grabCookies()
@@ -1920,16 +1277,7 @@ class CDPBrowser extends Helper {
1920
1277
  }
1921
1278
 
1922
1279
  /**
1923
- * Clears a cookie by name,
1924
- * if none provided clears all cookies.
1925
- *
1926
- * ```js
1927
- * I.clearCookie();
1928
- * I.clearCookie('test');
1929
- * ```
1930
- *
1931
- * @param {string|null} [name=null] (optional, `null` by default) cookie name
1932
- * @returns {Promise<void>}
1280
+ * {{> clearCookie }}
1933
1281
  */
1934
1282
  async clearCookie(name) {
1935
1283
  const cookies = await this.grabCookies()
@@ -1942,17 +1290,7 @@ class CDPBrowser extends Helper {
1942
1290
  }
1943
1291
 
1944
1292
  /**
1945
- * Checks that the system clipboard contains the given text.
1946
- *
1947
- * ```js
1948
- * I.click('Copy to clipboard');
1949
- * I.seeInClipboard('https://codecept.io');
1950
- * ```
1951
- *
1952
- * Reading the clipboard requires a secure context (`https` or `localhost`).
1953
- *
1954
- * @param {string} text value to check.
1955
- * @returns {Promise<void>}
1293
+ * {{> seeInClipboard }}
1956
1294
  */
1957
1295
  async seeInClipboard(text) {
1958
1296
  const clipboard = await this.grabFromClipboard()
@@ -1960,17 +1298,7 @@ class CDPBrowser extends Helper {
1960
1298
  }
1961
1299
 
1962
1300
  /**
1963
- * Checks that the system clipboard is equal to the given text.
1964
- *
1965
- * ```js
1966
- * I.click('Copy to clipboard');
1967
- * I.seeClipboardEquals('https://codecept.io');
1968
- * ```
1969
- *
1970
- * Reading the clipboard requires a secure context (`https` or `localhost`).
1971
- *
1972
- * @param {string} text value to check.
1973
- * @returns {Promise<void>}
1301
+ * {{> seeClipboardEquals }}
1974
1302
  */
1975
1303
  async seeClipboardEquals(text) {
1976
1304
  const clipboard = await this.grabFromClipboard()
@@ -1978,14 +1306,7 @@ class CDPBrowser extends Helper {
1978
1306
  }
1979
1307
 
1980
1308
  /**
1981
- * Clears the system clipboard.
1982
- *
1983
- * ```js
1984
- * I.clearClipboard();
1985
- * I.seeClipboardEquals('');
1986
- * ```
1987
- *
1988
- * @returns {Promise<void>}
1309
+ * {{> clearClipboard }}
1989
1310
  */
1990
1311
  async clearClipboard() {
1991
1312
  await this._grantClipboardAccess()
@@ -1993,15 +1314,7 @@ class CDPBrowser extends Helper {
1993
1314
  }
1994
1315
 
1995
1316
  /**
1996
- * Grabs the text content of the system clipboard.
1997
- * Resumes test execution, so **should be used inside async function with `await`** operator.
1998
- *
1999
- * ```js
2000
- * I.click('Copy to clipboard');
2001
- * const url = await I.grabFromClipboard();
2002
- * ```
2003
- *
2004
- * @returns {Promise<string>} the system clipboard contents.
1317
+ * {{> grabFromClipboard }}
2005
1318
  */
2006
1319
  async grabFromClipboard() {
2007
1320
  await this._grantClipboardAccess()
@@ -2010,13 +1323,6 @@ class CDPBrowser extends Helper {
2010
1323
  return clipboard
2011
1324
  }
2012
1325
 
2013
- /**
2014
- * Brings the current target to front and grants it clipboard read/write access, so
2015
- * `navigator.clipboard` does not reject with a permission or focus error. Failures are ignored:
2016
- * a browser without `Browser.grantPermissions` surfaces its own error from the read instead.
2017
- *
2018
- * @protected
2019
- */
2020
1326
  async _grantClipboardAccess() {
2021
1327
  await this.cdp.send('Page.bringToFront', {}, this.sessionId).catch(() => null)
2022
1328
  const origin = await this._evaluate('window.location.origin').catch(() => null)
@@ -2033,7 +1339,7 @@ class CDPBrowser extends Helper {
2033
1339
  * ```
2034
1340
  *
2035
1341
  * @param {string} fileName file name to save.
2036
- * @returns {Promise<void>}
1342
+ * @returns {void} automatically synchronized promise through #recorder
2037
1343
  */
2038
1344
  async saveScreenshot(fileName) {
2039
1345
  if (this.capabilities.screenshot === false) {
@@ -2045,15 +1351,7 @@ class CDPBrowser extends Helper {
2045
1351
  }
2046
1352
 
2047
1353
  /**
2048
- * Saves a screenshot of a single element to the output folder.
2049
- *
2050
- * ```js
2051
- * I.saveElementScreenshot('#logo', 'logo.png');
2052
- * ```
2053
- *
2054
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2055
- * @param {string} fileName file name to save.
2056
- * @returns {Promise<void>}
1354
+ * {{> saveElementScreenshot }}
2057
1355
  */
2058
1356
  async saveElementScreenshot(locator, fileName) {
2059
1357
  if (this.capabilities.screenshot === false) {
@@ -2068,61 +1366,33 @@ class CDPBrowser extends Helper {
2068
1366
  }
2069
1367
 
2070
1368
  /**
2071
- * Pauses execution for a number of seconds.
2072
- *
2073
- * ```js
2074
- * I.wait(2); // waits 2 secs
2075
- * ```
2076
- *
2077
- * @param {number} sec number of seconds to wait.
2078
- * @returns {Promise<void>}
1369
+ * {{> wait }}
2079
1370
  */
2080
1371
  async wait(sec) {
2081
1372
  return new Promise(r => setTimeout(r, sec * 1000))
2082
1373
  }
2083
1374
 
2084
1375
  /**
2085
- * Checks that title does not contain text.
2086
- *
2087
- * @param {string} text value to check.
2088
- * @returns {Promise<void>}
1376
+ * {{> dontSeeInTitle }}
2089
1377
  */
2090
1378
  async dontSeeInTitle(text) {
2091
1379
  return stringIncludes('web page title').negate(text, await this.grabTitle())
2092
1380
  }
2093
1381
 
2094
1382
  /**
2095
- * Checks that current url is equal to provided one.
2096
- * Unlike `seeInCurrentUrl` performs a strict comparison.
2097
- *
2098
- * ```js
2099
- * I.seeCurrentUrlEquals('/register');
2100
- * ```
2101
- *
2102
- * @param {string} url value to check.
2103
- * @returns {Promise<void>}
1383
+ * {{> seeCurrentUrlEquals }}
2104
1384
  */
2105
1385
  async seeCurrentUrlEquals(url) {
2106
1386
  return urlEquals(this.options.url).assert(url, await this.grabCurrentUrl())
2107
1387
  }
2108
1388
 
2109
1389
  /**
2110
- * Checks that current url is not equal to provided one.
2111
- * Unlike `dontSeeInCurrentUrl` performs a strict comparison.
2112
- *
2113
- * @param {string} url value to check.
2114
- * @returns {Promise<void>}
1390
+ * {{> dontSeeCurrentUrlEquals }}
2115
1391
  */
2116
1392
  async dontSeeCurrentUrlEquals(url) {
2117
1393
  return urlEquals(this.options.url).negate(url, await this.grabCurrentUrl())
2118
1394
  }
2119
1395
 
2120
- /**
2121
- * Resolves the current page URL to a `pathname`, ignoring the origin, query string, and hash.
2122
- *
2123
- * @returns {Promise<string>} the pathname of the current page.
2124
- * @protected
2125
- */
2126
1396
  async _grabCurrentPath() {
2127
1397
  const currentUrl = await this.grabCurrentUrl()
2128
1398
  const baseUrl = this.options.url || 'http://localhost'
@@ -2130,39 +1400,21 @@ class CDPBrowser extends Helper {
2130
1400
  }
2131
1401
 
2132
1402
  /**
2133
- * Checks that current url path (ignoring query string and hash) equals to provided one.
2134
- *
2135
- * ```js
2136
- * I.seeCurrentPathEquals('/info');
2137
- * ```
2138
- *
2139
- * @param {string} path value to check.
2140
- * @returns {Promise<void>}
1403
+ * {{> seeCurrentPathEquals }}
2141
1404
  */
2142
1405
  async seeCurrentPathEquals(path) {
2143
1406
  return equals('url path').assert(normalizePath(path), normalizePath(await this._grabCurrentPath()))
2144
1407
  }
2145
1408
 
2146
1409
  /**
2147
- * Opposite to `seeCurrentPathEquals`.
2148
- *
2149
- * @param {string} path value to check.
2150
- * @returns {Promise<void>}
1410
+ * {{> dontSeeCurrentPathEquals }}
2151
1411
  */
2152
1412
  async dontSeeCurrentPathEquals(path) {
2153
1413
  return equals('url path').negate(normalizePath(path), normalizePath(await this._grabCurrentPath()))
2154
1414
  }
2155
1415
 
2156
1416
  /**
2157
- * Waits for the entire URL to match the expected (by default waits for `options.waitForTimeout` seconds).
2158
- *
2159
- * ```js
2160
- * I.waitUrlEquals('/info', 2);
2161
- * ```
2162
- *
2163
- * @param {string} urlPart value to check.
2164
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2165
- * @returns {Promise<void>}
1417
+ * {{> waitUrlEquals }}
2166
1418
  */
2167
1419
  async waitUrlEquals(urlPart, sec = null) {
2168
1420
  const timeout = sec || this.options.waitForTimeout
@@ -2183,15 +1435,16 @@ class CDPBrowser extends Helper {
2183
1435
  }
2184
1436
 
2185
1437
  /**
2186
- * Waits for current url path (ignoring query string and hash) to equal to the expected.
1438
+ * Waits for the current URL path to match the expected path.
1439
+ * Query strings and URL fragments are ignored.
2187
1440
  *
2188
1441
  * ```js
2189
- * I.waitCurrentPathEquals('/info', 2);
1442
+ * I.waitCurrentPathEquals('/info', 5);
2190
1443
  * ```
2191
1444
  *
2192
1445
  * @param {string} path value to check.
2193
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2194
- * @returns {Promise<void>}
1446
+ * @param {number} [sec] (optional, `waitForTimeout` by default) time in seconds to wait
1447
+ * @returns {void} automatically synchronized promise through #recorder
2195
1448
  */
2196
1449
  async waitCurrentPathEquals(path, sec = null) {
2197
1450
  const timeout = sec || this.options.waitForTimeout
@@ -2212,44 +1465,19 @@ class CDPBrowser extends Helper {
2212
1465
  }
2213
1466
 
2214
1467
  /**
2215
- * Checks that the given input field or textarea equals (contains) the given value.
2216
- * For fuzzy locators, the field is searched by label|name|CSS|XPath|strict locator.
2217
- *
2218
- * ```js
2219
- * I.seeInField('Username', 'davert');
2220
- * ```
2221
- *
2222
- * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
2223
- * @param {CodeceptJS.StringOrSecret} value value to check.
2224
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2225
- * @returns {Promise<void>}
1468
+ * {{> seeInField }}
2226
1469
  */
2227
1470
  async seeInField(field, value, context = null) {
2228
1471
  return this._seeInField('assert', field, value, context)
2229
1472
  }
2230
1473
 
2231
1474
  /**
2232
- * Opposite to `seeInField`.
2233
- *
2234
- * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
2235
- * @param {CodeceptJS.StringOrSecret} value value to check.
2236
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2237
- * @returns {Promise<void>}
1475
+ * {{> dontSeeInField }}
2238
1476
  */
2239
1477
  async dontSeeInField(field, value, context = null) {
2240
1478
  return this._seeInField('negate', field, value, context)
2241
1479
  }
2242
1480
 
2243
- /**
2244
- * Shared implementation for `seeInField`/`dontSeeInField`.
2245
- *
2246
- * @param {'assert'|'negate'} assertType
2247
- * @param {CodeceptJS.LocatorOrString} field
2248
- * @param {CodeceptJS.StringOrSecret} value
2249
- * @param {?CodeceptJS.LocatorOrString} [context=null]
2250
- * @returns {Promise<void>}
2251
- * @protected
2252
- */
2253
1481
  async _seeInField(assertType, field, value, context = null) {
2254
1482
  const locatorText = new Locator(field).toString()
2255
1483
  if (typeof value === 'boolean') {
@@ -2265,14 +1493,7 @@ class CDPBrowser extends Helper {
2265
1493
  }
2266
1494
 
2267
1495
  /**
2268
- * Grab number of visible elements by locator.
2269
- *
2270
- * ```js
2271
- * let numOfVisibleElements = await I.grabNumberOfVisibleElements('p');
2272
- * ```
2273
- *
2274
- * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator.
2275
- * @returns {Promise<number>} number of visible matched elements.
1496
+ * {{> grabNumberOfVisibleElements }}
2276
1497
  */
2277
1498
  async grabNumberOfVisibleElements(locator) {
2278
1499
  this._assertLayoutSupported('grabNumberOfVisibleElements')
@@ -2281,15 +1502,7 @@ class CDPBrowser extends Helper {
2281
1502
  }
2282
1503
 
2283
1504
  /**
2284
- * Asserts that an element appears a given number of times on the page, and that all matching elements are visible.
2285
- *
2286
- * ```js
2287
- * I.seeNumberOfVisibleElements('.buttons', 3);
2288
- * ```
2289
- *
2290
- * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator.
2291
- * @param {number} num expected number of elements.
2292
- * @returns {Promise<void>}
1505
+ * {{> seeNumberOfVisibleElements }}
2293
1506
  */
2294
1507
  async seeNumberOfVisibleElements(locator, num) {
2295
1508
  const found = await this.grabNumberOfVisibleElements(locator)
@@ -2297,39 +1510,21 @@ class CDPBrowser extends Helper {
2297
1510
  }
2298
1511
 
2299
1512
  /**
2300
- * Retrieves the current page scroll position.
2301
- *
2302
- * ```js
2303
- * let { x, y } = await I.grabPageScrollPosition();
2304
- * ```
2305
- *
2306
- * @returns {Promise<{x: number, y: number}>} scroll position.
1513
+ * {{> grabPageScrollPosition }}
2307
1514
  */
2308
1515
  async grabPageScrollPosition() {
2309
1516
  return this.executeScript(() => ({ x: window.pageXOffset, y: window.pageYOffset }))
2310
1517
  }
2311
1518
 
2312
1519
  /**
2313
- * Scrolls to the top of the page.
2314
- *
2315
- * ```js
2316
- * I.scrollPageToTop();
2317
- * ```
2318
- *
2319
- * @returns {Promise<void>}
1520
+ * {{> scrollPageToTop }}
2320
1521
  */
2321
1522
  scrollPageToTop() {
2322
1523
  return this.executeScript(() => window.scrollTo(0, 0))
2323
1524
  }
2324
1525
 
2325
1526
  /**
2326
- * Scrolls to the bottom of the page.
2327
- *
2328
- * ```js
2329
- * I.scrollPageToBottom();
2330
- * ```
2331
- *
2332
- * @returns {Promise<void>}
1527
+ * {{> scrollPageToBottom }}
2333
1528
  */
2334
1529
  scrollPageToBottom() {
2335
1530
  return this.executeScript(() => {
@@ -2340,17 +1535,7 @@ class CDPBrowser extends Helper {
2340
1535
  }
2341
1536
 
2342
1537
  /**
2343
- * Scrolls to the element matched by locator, or to given coordinates.
2344
- *
2345
- * ```js
2346
- * I.scrollTo('#submit');
2347
- * I.scrollTo(100, 200);
2348
- * ```
2349
- *
2350
- * @param {CodeceptJS.LocatorOrString|number} locator element to scroll to, or an X coordinate if no element.
2351
- * @param {number} [offsetX=0] X offset, or Y coordinate if `locator` is a number.
2352
- * @param {number} [offsetY=0] Y offset applied when scrolling to an element.
2353
- * @returns {Promise<void>}
1538
+ * {{> scrollTo }}
2354
1539
  */
2355
1540
  async scrollTo(locator, offsetX = 0, offsetY = 0) {
2356
1541
  if (typeof locator === 'number' && typeof offsetX === 'number') {
@@ -2370,16 +1555,7 @@ class CDPBrowser extends Helper {
2370
1555
  }
2371
1556
 
2372
1557
  /**
2373
- * Retrieves a CSS property from an element located by CSS or XPath.
2374
- * If more than one element is found - value of first element is returned.
2375
- *
2376
- * ```js
2377
- * const value = await I.grabCssPropertyFrom('h3', 'font-weight');
2378
- * ```
2379
- *
2380
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2381
- * @param {string} cssProperty CSS property name.
2382
- * @returns {Promise<string>} CSS value
1558
+ * {{> grabCssPropertyFrom }}
2383
1559
  */
2384
1560
  async grabCssPropertyFrom(locator, cssProperty) {
2385
1561
  const values = await this.grabCssPropertyFromAll(locator, cssProperty)
@@ -2388,15 +1564,7 @@ class CDPBrowser extends Helper {
2388
1564
  }
2389
1565
 
2390
1566
  /**
2391
- * Retrieves an array of CSS properties from elements located by CSS or XPath.
2392
- *
2393
- * ```js
2394
- * const values = await I.grabCssPropertyFromAll('h3', 'font-weight');
2395
- * ```
2396
- *
2397
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2398
- * @param {string} cssProperty CSS property name.
2399
- * @returns {Promise<string[]>} array of CSS values
1567
+ * {{> grabCssPropertyFromAll }}
2400
1568
  */
2401
1569
  async grabCssPropertyFromAll(locator, cssProperty) {
2402
1570
  const camelProperty = toCamelCase(cssProperty)
@@ -2406,15 +1574,7 @@ class CDPBrowser extends Helper {
2406
1574
  }
2407
1575
 
2408
1576
  /**
2409
- * Checks that all elements matched by locator have the given CSS properties.
2410
- *
2411
- * ```js
2412
- * I.seeCssPropertiesOnElements('h3', { 'font-weight': 'bold', display: 'block' });
2413
- * ```
2414
- *
2415
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2416
- * @param {object} cssProperties object with CSS properties and their values to check.
2417
- * @returns {Promise<void>}
1577
+ * {{> seeCssPropertiesOnElements }}
2418
1578
  */
2419
1579
  async seeCssPropertiesOnElements(locator, cssProperties) {
2420
1580
  const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties)
@@ -2432,16 +1592,7 @@ class CDPBrowser extends Helper {
2432
1592
  }
2433
1593
 
2434
1594
  /**
2435
- * Checks that all elements matched by locator have the given attribute values.
2436
- * An expected value is matched either as an exact match or as a regular expression against the actual value.
2437
- *
2438
- * ```js
2439
- * I.seeAttributesOnElements('//form', { method: 'post' });
2440
- * ```
2441
- *
2442
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2443
- * @param {object} attributes object with attribute names and expected values.
2444
- * @returns {Promise<void>}
1595
+ * {{> seeAttributesOnElements }}
2445
1596
  */
2446
1597
  async seeAttributesOnElements(locator, attributes) {
2447
1598
  const attrs = Object.keys(attributes)
@@ -2460,14 +1611,7 @@ class CDPBrowser extends Helper {
2460
1611
  }
2461
1612
 
2462
1613
  /**
2463
- * Focuses a given element.
2464
- *
2465
- * ```js
2466
- * I.focus('#name');
2467
- * ```
2468
- *
2469
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2470
- * @returns {Promise<void>}
1614
+ * {{> focus }}
2471
1615
  */
2472
1616
  async focus(locator) {
2473
1617
  const armed = this._armActionSettle()
@@ -2477,14 +1621,7 @@ class CDPBrowser extends Helper {
2477
1621
  }
2478
1622
 
2479
1623
  /**
2480
- * Removes focus from a given element.
2481
- *
2482
- * ```js
2483
- * I.blur('#name');
2484
- * ```
2485
- *
2486
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2487
- * @returns {Promise<void>}
1624
+ * {{> blur }}
2488
1625
  */
2489
1626
  async blur(locator) {
2490
1627
  const armed = this._armActionSettle()
@@ -2494,25 +1631,7 @@ class CDPBrowser extends Helper {
2494
1631
  }
2495
1632
 
2496
1633
  /**
2497
- * Types characters into the currently focused element (as set by `click`, `focus`, etc). Each
2498
- * character dispatches a real `keydown` → `keypress` → (value mutated) → `input` → `keyup`
2499
- * sequence, and mutates a `contenteditable` host's `textContent` instead of `.value`, so this
2500
- * works on rich-text/contenteditable targets as well as `input`/`textarea`. Mirrors Puppeteer's
2501
- * `type(text, options)` semantics.
2502
- *
2503
- * Without a `delay`, every character is dispatched in a single round-trip to the page. With a
2504
- * `delay`, characters are dispatched one round-trip at a time so the requested pause actually
2505
- * elapses between key presses.
2506
- *
2507
- * ```js
2508
- * I.click('Name');
2509
- * I.type('CodeceptJS');
2510
- * I.type(['C', 'o', 'd', 'e']);
2511
- * ```
2512
- *
2513
- * @param {string|string[]} keys characters to type, either as a string or an array of characters.
2514
- * @param {number} [delay] (optional) delay in milliseconds between key presses.
2515
- * @returns {Promise<void>}
1634
+ * {{> type }}
2516
1635
  */
2517
1636
  async type(keys, delay = null) {
2518
1637
  await checkFocusBeforeType(this)
@@ -2561,9 +1680,7 @@ class CDPBrowser extends Helper {
2561
1680
  }
2562
1681
 
2563
1682
  /**
2564
- * Presses a key or key combination on the currently focused element.
2565
- * Under `options.strict`, a modifier+editing-key combination (e.g. `Ctrl+A`) dispatched with no
2566
- * element focused throws `NonFocusedType`, mirroring `focusCheck.js`'s behavior on other helpers.
1683
+ * Presses a key or a key combination on the focused element.
2567
1684
  *
2568
1685
  * ```js
2569
1686
  * I.pressKey('Enter');
@@ -2571,7 +1688,7 @@ class CDPBrowser extends Helper {
2571
1688
  * ```
2572
1689
  *
2573
1690
  * @param {string|string[]} key a key or an array of keys to combine (modifiers first).
2574
- * @returns {Promise<void>}
1691
+ * @returns {void} automatically synchronized promise through #recorder
2575
1692
  */
2576
1693
  async pressKey(key) {
2577
1694
  const originalKey = Array.isArray(key) ? key : [key]
@@ -2597,15 +1714,7 @@ class CDPBrowser extends Helper {
2597
1714
  }
2598
1715
 
2599
1716
  /**
2600
- * Resizes the browser viewport.
2601
- *
2602
- * ```js
2603
- * I.resizeWindow(1024, 768);
2604
- * ```
2605
- *
2606
- * @param {number|'maximize'} width window width, or `'maximize'`.
2607
- * @param {number} [height] window height.
2608
- * @returns {Promise<void>}
1717
+ * {{> resizeWindow }}
2609
1718
  */
2610
1719
  async resizeWindow(width, height) {
2611
1720
  if (width === 'maximize') {
@@ -2617,15 +1726,7 @@ class CDPBrowser extends Helper {
2617
1726
  }
2618
1727
 
2619
1728
  /**
2620
- * Performs a double-click on an element matched by locator.
2621
- *
2622
- * ```js
2623
- * I.doubleClick('Edit');
2624
- * ```
2625
- *
2626
- * @param {CodeceptJS.LocatorOrString} locator clickable element located by text, or any element located by CSS|XPath|strict locator.
2627
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default, currently ignored by this helper).
2628
- * @returns {Promise<void>}
1729
+ * {{> doubleClick }}
2629
1730
  */
2630
1731
  async doubleClick(locator, context = null) {
2631
1732
  const armed = this._armActionSettle()
@@ -2635,15 +1736,7 @@ class CDPBrowser extends Helper {
2635
1736
  }
2636
1737
 
2637
1738
  /**
2638
- * Performs a right-click on an element matched by locator.
2639
- *
2640
- * ```js
2641
- * I.rightClick('Menu');
2642
- * ```
2643
- *
2644
- * @param {CodeceptJS.LocatorOrString} locator clickable element located by text, or any element located by CSS|XPath|strict locator.
2645
- * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default, currently ignored by this helper).
2646
- * @returns {Promise<void>}
1739
+ * {{> rightClick }}
2647
1740
  */
2648
1741
  async rightClick(locator, context = null) {
2649
1742
  const armed = this._armActionSettle()
@@ -2653,18 +1746,18 @@ class CDPBrowser extends Helper {
2653
1746
  }
2654
1747
 
2655
1748
  /**
2656
- * Clicks at global page coordinates, or at coordinates relative to an element.
2657
- * Dispatches a real CDP mouse click and therefore requires a real layout engine.
1749
+ * Clicks at page coordinates, or at coordinates relative to an element.
1750
+ * Requires a browser that renders layout.
2658
1751
  *
2659
1752
  * ```js
2660
- * I.clickXY(100, 200); // global coordinates
1753
+ * I.clickXY(100, 200); // page coordinates
2661
1754
  * I.clickXY('#area', 50, 30); // relative to #area
2662
1755
  * ```
2663
1756
  *
2664
- * @param {CodeceptJS.LocatorOrString|number} locator element to click relative to, or a global X coordinate.
2665
- * @param {number} [x] X coordinate relative to element, or global Y coordinate if `locator` is a number.
2666
- * @param {number} [y] Y coordinate relative to element.
2667
- * @returns {Promise<void>}
1757
+ * @param {CodeceptJS.LocatorOrString|number} locator element to click relative to, or the X page coordinate.
1758
+ * @param {number} [x] X coordinate relative to the element, or the Y page coordinate if `locator` is a number.
1759
+ * @param {number} [y] Y coordinate relative to the element.
1760
+ * @returns {void} automatically synchronized promise through #recorder
2668
1761
  */
2669
1762
  async clickXY(locator, x, y) {
2670
1763
  this._assertLayoutSupported('clickXY')
@@ -2689,15 +1782,7 @@ class CDPBrowser extends Helper {
2689
1782
  }
2690
1783
 
2691
1784
  /**
2692
- * Waits for an element to become visible (by default waits for `options.waitForTimeout` seconds).
2693
- *
2694
- * ```js
2695
- * I.waitForVisible('#popup', 5);
2696
- * ```
2697
- *
2698
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2699
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2700
- * @returns {Promise<void>}
1785
+ * {{> waitForVisible }}
2701
1786
  */
2702
1787
  async waitForVisible(locator, sec = null) {
2703
1788
  this._assertLayoutSupported('waitForVisible')
@@ -2711,15 +1796,7 @@ class CDPBrowser extends Helper {
2711
1796
  }
2712
1797
 
2713
1798
  /**
2714
- * Waits for an element to become invisible (by default waits for `options.waitForTimeout` seconds).
2715
- *
2716
- * ```js
2717
- * I.waitForInvisible('#popup', 5);
2718
- * ```
2719
- *
2720
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2721
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2722
- * @returns {Promise<void>}
1799
+ * {{> waitForInvisible }}
2723
1800
  */
2724
1801
  async waitForInvisible(locator, sec = null) {
2725
1802
  this._assertLayoutSupported('waitForInvisible')
@@ -2733,26 +1810,14 @@ class CDPBrowser extends Helper {
2733
1810
  }
2734
1811
 
2735
1812
  /**
2736
- * Waits for an element to be hidden. Alias of `waitForInvisible`.
2737
- *
2738
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2739
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2740
- * @returns {Promise<void>}
1813
+ * {{> waitToHide }}
2741
1814
  */
2742
1815
  async waitToHide(locator, sec = null) {
2743
1816
  return this.waitForInvisible(locator, sec)
2744
1817
  }
2745
1818
 
2746
1819
  /**
2747
- * Waits for an element to be removed from the DOM (by default waits for `options.waitForTimeout` seconds).
2748
- *
2749
- * ```js
2750
- * I.waitForDetached('#popup', 5);
2751
- * ```
2752
- *
2753
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2754
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2755
- * @returns {Promise<void>}
1820
+ * {{> waitForDetached }}
2756
1821
  */
2757
1822
  async waitForDetached(locator, sec = null) {
2758
1823
  const timeout = sec || this.options.waitForTimeout
@@ -2765,10 +1830,7 @@ class CDPBrowser extends Helper {
2765
1830
  }
2766
1831
 
2767
1832
  /**
2768
- * Checks that a cookie with the given name is set.
2769
- *
2770
- * @param {string} name cookie name.
2771
- * @returns {Promise<void>}
1833
+ * {{> seeCookie }}
2772
1834
  */
2773
1835
  async seeCookie(name) {
2774
1836
  const cookies = await this.grabCookies()
@@ -2776,10 +1838,7 @@ class CDPBrowser extends Helper {
2776
1838
  }
2777
1839
 
2778
1840
  /**
2779
- * Checks that a cookie with the given name is not set.
2780
- *
2781
- * @param {string} name cookie name.
2782
- * @returns {Promise<void>}
1841
+ * {{> dontSeeCookie }}
2783
1842
  */
2784
1843
  async dontSeeCookie(name) {
2785
1844
  const cookies = await this.grabCookies()
@@ -2787,15 +1846,7 @@ class CDPBrowser extends Helper {
2787
1846
  }
2788
1847
 
2789
1848
  /**
2790
- * Waits for a cookie with the given name to be set (by default waits for `options.waitForTimeout` seconds).
2791
- *
2792
- * ```js
2793
- * I.waitForCookie('auth', 5);
2794
- * ```
2795
- *
2796
- * @param {string} name cookie name.
2797
- * @param {number} [sec] (optional, `options.waitForTimeout` by default) time in seconds to wait
2798
- * @returns {Promise<void>}
1849
+ * {{> waitForCookie }}
2799
1850
  */
2800
1851
  async waitForCookie(name, sec = null) {
2801
1852
  const timeout = sec || this.options.waitForTimeout
@@ -2803,15 +1854,7 @@ class CDPBrowser extends Helper {
2803
1854
  }
2804
1855
 
2805
1856
  /**
2806
- * Retrieves the inner HTML from an element located by CSS or XPath.
2807
- * If more than one element is found - HTML of first element is returned.
2808
- *
2809
- * ```js
2810
- * let postHTML = await I.grabHTMLFrom('#post');
2811
- * ```
2812
- *
2813
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2814
- * @returns {Promise<string>} HTML code for an element
1857
+ * {{> grabHTMLFrom }}
2815
1858
  */
2816
1859
  async grabHTMLFrom(locator) {
2817
1860
  const html = await this.grabHTMLFromAll(locator)
@@ -2820,14 +1863,7 @@ class CDPBrowser extends Helper {
2820
1863
  }
2821
1864
 
2822
1865
  /**
2823
- * Retrieves the inner HTML from elements located by CSS or XPath.
2824
- *
2825
- * ```js
2826
- * let postHTMLs = await I.grabHTMLFromAll('.post');
2827
- * ```
2828
- *
2829
- * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator.
2830
- * @returns {Promise<string[]>} HTML code for matched elements
1866
+ * {{> grabHTMLFromAll }}
2831
1867
  */
2832
1868
  async grabHTMLFromAll(locator) {
2833
1869
  const res = await this._run(this._candidates(locator), 'innerHtml')
@@ -2835,18 +1871,7 @@ class CDPBrowser extends Helper {
2835
1871
  }
2836
1872
 
2837
1873
  /**
2838
- * Executes an asynchronous script (callback-style, in the same way `window.setTimeout` works)
2839
- * in the browser context and returns the value passed to `done`.
2840
- *
2841
- * ```js
2842
- * const val = await I.executeAsyncScript(function(val, done) {
2843
- * setTimeout(() => done(val + 1), 100)
2844
- * }, 5)
2845
- * ```
2846
- *
2847
- * @param {function} fn - an asynchronous function to be executed in the browser context; its last argument is a `done` callback.
2848
- * @param {...any} args - arguments to pass into the function (before `done`).
2849
- * @returns {Promise<any>} the value passed to `done`.
1874
+ * {{> executeAsyncScript }}
2850
1875
  */
2851
1876
  async executeAsyncScript(fn, ...args) {
2852
1877
  const fnBody = typeof fn === 'function' ? fn.toString() : fn
@@ -2854,19 +1879,7 @@ class CDPBrowser extends Helper {
2854
1879
  }
2855
1880
 
2856
1881
  /**
2857
- * Starts recording network traffic via CDP's `Network.requestWillBeSent`/`responseReceived`
2858
- * events, in the same shape (`{url, method, requestHeaders, requestPostData, response}` per
2859
- * request, `response` a promise of `{url(), status(), statusText(), body()}`) the shared
2860
- * `lib/helper/network` actions expect from Puppeteer/Playwright. The CDP listeners are
2861
- * installed once (lazily) and left in place afterwards, since `CDPConnection` has no listener
2862
- * removal and `this.cdp` is reused across tests; they filter by `this.sessionId`, so only the
2863
- * currently active test/page's requests are recorded.
2864
- *
2865
- * ```js
2866
- * I.startRecordingTraffic();
2867
- * ```
2868
- *
2869
- * @returns {Promise<void>}
1882
+ * {{> startRecordingTraffic }}
2870
1883
  */
2871
1884
  async startRecordingTraffic() {
2872
1885
  this.flushNetworkTraffics()
@@ -2881,12 +1894,6 @@ class CDPBrowser extends Helper {
2881
1894
  this.cdp.on('Network.loadingFailed', (params, sessionId) => this._onTrafficLoadingFailed(params, sessionId))
2882
1895
  }
2883
1896
 
2884
- /**
2885
- * `Network.requestWillBeSent` handler, pushed into `this.requests` when it belongs to the
2886
- * currently active session and recording is on.
2887
- *
2888
- * @protected
2889
- */
2890
1897
  _onTrafficRequest(params, sessionId) {
2891
1898
  if (!this.recording || sessionId !== this.sessionId) return
2892
1899
  let resolveResponse
@@ -2911,12 +1918,6 @@ class CDPBrowser extends Helper {
2911
1918
  })
2912
1919
  }
2913
1920
 
2914
- /**
2915
- * `Network.responseReceived` handler, resolving the matching pending `response` promise pushed
2916
- * by `_onTrafficRequest` with a Puppeteer-`HTTPResponse`-like object.
2917
- *
2918
- * @protected
2919
- */
2920
1921
  _onTrafficResponse(params, sessionId) {
2921
1922
  if (sessionId !== this.sessionId) return
2922
1923
  const resolve = this._pendingTrafficResponses.get(params.requestId)
@@ -2938,13 +1939,6 @@ class CDPBrowser extends Helper {
2938
1939
  })
2939
1940
  }
2940
1941
 
2941
- /**
2942
- * `Network.loadingFailed` handler, resolving a still-pending `response` promise to `null`
2943
- * (matching Puppeteer's `request.response()` for a failed request) so `grabRecordedNetworkTraffics`
2944
- * never awaits a promise that would otherwise never settle.
2945
- *
2946
- * @protected
2947
- */
2948
1942
  _onTrafficLoadingFailed(params, sessionId) {
2949
1943
  if (sessionId !== this.sessionId) return
2950
1944
  const resolve = this._pendingTrafficResponses.get(params.requestId)
@@ -2975,14 +1969,7 @@ class CDPBrowser extends Helper {
2975
1969
  }
2976
1970
 
2977
1971
  /**
2978
- * Stops recording network traffic started by `startRecordingTraffic`. Already-recorded requests
2979
- * in `this.requests` are kept; only new requests stop being appended.
2980
- *
2981
- * ```js
2982
- * I.stopRecordingTraffic();
2983
- * ```
2984
- *
2985
- * @returns {void}
1972
+ * {{> stopRecordingTraffic }}
2986
1973
  */
2987
1974
  stopRecordingTraffic() {
2988
1975
  this.recording = false
@@ -2996,20 +1983,15 @@ class CDPBrowser extends Helper {
2996
1983
  }
2997
1984
 
2998
1985
  /**
2999
- * Starts recording a CDP `Page.startScreencast` session for the current test's target: frames
3000
- * arrive as `Page.screencastFrame` events, are acknowledged immediately (`Page.screencastFrameAck`,
3001
- * required or the browser stops sending more), and buffered in `this._screencastFrames`. The
3002
- * underlying `Page.screencastFrame` listener is installed once (lazily) and left in place, like
3003
- * `startRecordingTraffic`'s listeners, since `CDPConnection` has no listener-removal API; it
3004
- * filters by `this.sessionId` so only the currently active test's frames are buffered. Call
3005
- * `stopScreencast` to end the capture and assemble the buffered frames into an APNG.
1986
+ * Starts recording a video of the page. Stop it with `stopScreencast`.
1987
+ * Usually enabled through the `screencast` plugin rather than called directly.
3006
1988
  *
3007
1989
  * ```js
3008
1990
  * I.startScreencast();
3009
1991
  * ```
3010
1992
  *
3011
- * @param {object} [options] {maxWidth: number, maxHeight: number, quality: number, everyNthFrame: number} — CDP `Page.startScreencast` pass-throughs. `format` is always `'png'`.
3012
- * @returns {Promise<void>}
1993
+ * @param {object} [options] `{ maxWidth, maxHeight, quality, everyNthFrame }`
1994
+ * @returns {void} automatically synchronized promise through #recorder
3013
1995
  */
3014
1996
  async startScreencast(options = {}) {
3015
1997
  if (!this._screencastListenerInstalled) {
@@ -3026,14 +2008,6 @@ class CDPBrowser extends Helper {
3026
2008
  await this.cdp.send('Page.startScreencast', params, this.sessionId)
3027
2009
  }
3028
2010
 
3029
- /**
3030
- * `Page.screencastFrame` handler: ignores frames from a session other than the currently active
3031
- * one (stale frames from a previous test, since the listener is never removed), acknowledges the
3032
- * frame so the browser keeps sending more, and buffers `{data, timestamp}` for `stopScreencast`
3033
- * to assemble.
3034
- *
3035
- * @protected
3036
- */
3037
2011
  _onScreencastFrame(params, sessionId) {
3038
2012
  if (!this._screencastActive || sessionId !== this.sessionId) return
3039
2013
  this._screencastFrames.push({ data: params.data, timestamp: params.metadata && params.metadata.timestamp })
@@ -3041,23 +2015,14 @@ class CDPBrowser extends Helper {
3041
2015
  }
3042
2016
 
3043
2017
  /**
3044
- * Stops the screencast started by `startScreencast` and assembles the buffered frames into a
3045
- * single APNG (Animated PNG) file, returned as a Buffer. Frame delays are derived from the CDP
3046
- * frame metadata's `timestamp` deltas (frame arrival is activity-driven — Obscura and Chrome both
3047
- * only emit a frame on damage — so this reproduces the actual pacing of what happened, not a
3048
- * fixed frame rate); the last frame is held for `options.lastFrameDelayMs` (default 1000ms) since
3049
- * it has no "next" frame to derive a delay from. Every frame is checked for the PNG signature
3050
- * before assembly — CDP's `format: 'png'` is honored by both Chrome and Obscura (verified
3051
- * directly), but if some other engine ever sends a different format regardless, this reports it
3052
- * via `debugSection` and returns `null` instead of muxing a broken file. Returns `null` if no
3053
- * frames were captured (screencast never started, or stopped immediately after starting).
2018
+ * Stops the recording started by `startScreencast` and returns it as an animated PNG.
3054
2019
  *
3055
2020
  * ```js
3056
- * const apngBuffer = await I.stopScreencast();
2021
+ * const video = await I.stopScreencast();
3057
2022
  * ```
3058
2023
  *
3059
- * @param {object} [options] {lastFrameDelayMs: number} — hold time in milliseconds for the final frame (default 1000).
3060
- * @returns {Promise<object>} a Buffer with the assembled APNG, or null if there was nothing to assemble.
2024
+ * @param {object} [options] `{ lastFrameDelayMs }`: how long the last frame is shown, in milliseconds (1000 by default).
2025
+ * @returns {Promise<Buffer|null>} APNG data, or `null` if no frames were recorded.
3061
2026
  */
3062
2027
  async stopScreencast(options = {}) {
3063
2028
  this._screencastActive = false