codeceptjs 4.1.0 → 4.2.0-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 (41) hide show
  1. package/docs/alternative-browsers.md +153 -0
  2. package/docs/basics.md +9 -1
  3. package/docs/configuration.md +2 -0
  4. package/docs/helpers/CDPBrowser.md +2138 -0
  5. package/docs/helpers/Kitesurf.md +118 -0
  6. package/docs/helpers/Obscura.md +210 -0
  7. package/docs/migration-4.md +3 -1
  8. package/docs/parallel.md +10 -0
  9. package/docs/plugins/screencast.md +18 -13
  10. package/docs/plugins.md +1 -1
  11. package/lib/command/info.js +11 -3
  12. package/lib/command/workers/runTests.js +14 -20
  13. package/lib/container.js +6 -0
  14. package/lib/data/context.js +4 -0
  15. package/lib/element/WebElement.js +5 -0
  16. package/lib/helper/Appium.js +14 -2
  17. package/lib/helper/CDPBrowser.js +3004 -0
  18. package/lib/helper/Kitesurf.js +139 -0
  19. package/lib/helper/Obscura.js +344 -0
  20. package/lib/helper/Playwright.js +30 -3
  21. package/lib/helper/Puppeteer.js +43 -16
  22. package/lib/helper/WebDriver.js +43 -8
  23. package/lib/helper/clientscripts/cdpBrowserClient.js +486 -0
  24. package/lib/helper/clientscripts/xpathPolyfill.js +31 -0
  25. package/lib/helper/extras/CDPConnection.js +92 -0
  26. package/lib/helper/extras/CDPElementHandle.js +27 -0
  27. package/lib/helper/extras/apngAssembler.js +156 -0
  28. package/lib/html.js +9 -2
  29. package/lib/listener/retryEnhancer.js +2 -1
  30. package/lib/listener/steps.js +8 -0
  31. package/lib/mocha/hooks.js +10 -0
  32. package/lib/parser.js +14 -2
  33. package/lib/plugin/junitReporter.js +17 -1
  34. package/lib/plugin/screencast.js +116 -24
  35. package/lib/step/base.js +15 -3
  36. package/lib/utils/loaderCheck.js +6 -0
  37. package/lib/utils.js +1 -1
  38. package/lib/workers.js +17 -0
  39. package/package.json +4 -1
  40. package/typings/promiseBasedTypes.d.ts +1833 -0
  41. package/typings/types.d.ts +1840 -0
@@ -1186,6 +1186,1573 @@ declare namespace CodeceptJS {
1186
1186
  */
1187
1187
  waitForText(text: string, sec?: number, context?: CodeceptJS.LocatorOrString): void;
1188
1188
  }
1189
+ /**
1190
+ * ## Configuration
1191
+ *
1192
+ * This helper should be configured in codecept.conf.js
1193
+ * @property [url = http://localhost] - base url of website to be tested.
1194
+ * @property [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.
1195
+ * @property [headers = {}] - headers sent with the endpoint resolution request and the WebSocket handshake. Useful for authenticated remote browser providers.
1196
+ * @property [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`.
1197
+ * @property [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.
1198
+ * @property [capabilities = {}] - pre-seed detected browser capabilities (`layout`, `xpath`, `screenshot`, `innerText`) to skip runtime probing. Values set here are never overwritten by `_probeCapabilities`/`_ensureClient`.
1199
+ * @property [waitForTimeout = 5] - default wait* timeout in seconds, used by helpers built on top of this class.
1200
+ * @property [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.
1201
+ * @property [pollInterval = 25] - interval in milliseconds between retries while polling for a condition (e.g. page ready state, `waitFor*`). Distinct from `waitForAction`.
1202
+ * @property [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).
1203
+ * @property [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.
1204
+ */
1205
+ type CDPBrowserConfig = {
1206
+ url?: string;
1207
+ endpoint?: string;
1208
+ headers?: any;
1209
+ input?: string;
1210
+ xpathPolyfill?: string | boolean;
1211
+ capabilities?: any;
1212
+ waitForTimeout?: number;
1213
+ waitForAction?: number;
1214
+ pollInterval?: number;
1215
+ getPageTimeout?: number;
1216
+ waitForNavigation?: string;
1217
+ };
1218
+ /**
1219
+ * CDPBrowser drives a browser directly over the raw Chrome DevTools Protocol, without depending
1220
+ * on Puppeteer, Playwright, or WebDriver. It opens its own WebSocket connection (via `CDPConnection`),
1221
+ * creates and attaches to a fresh target per test, and evaluates expressions through `Runtime.evaluate`.
1222
+ *
1223
+ * It is intended as the minimal, dependency-light base class for helpers that only need navigation,
1224
+ * script evaluation, and simple in-page element interaction (installed lazily through the
1225
+ * `window.__codecept` client script). It does not launch a browser itself — point `endpoint` at an
1226
+ * already-running Chrome (or any CDP-compatible browser) started with `--remote-debugging-port`.
1227
+ *
1228
+ * ## Example
1229
+ *
1230
+ * ```js
1231
+ * // inside codecept.conf.js
1232
+ * {
1233
+ * helpers: {
1234
+ * CDPBrowser: {
1235
+ * url: 'http://localhost',
1236
+ * endpoint: 'http://127.0.0.1:9222',
1237
+ * }
1238
+ * }
1239
+ * }
1240
+ * ```
1241
+ *
1242
+ * <!-- configuration -->
1243
+ *
1244
+ * ## Methods
1245
+ */
1246
+ class CDPBrowser {
1247
+ constructor(config: CDPBrowserConfig);
1248
+ /**
1249
+ * No-op hook kept for interface parity with other browser helpers. Connecting to the CDP
1250
+ * endpoint is deferred to `_before`, since a fresh target/session is opened per test.
1251
+ */
1252
+ _init(): void;
1253
+ /**
1254
+ * Resolves `options.endpoint` to a raw WebSocket debugger URL. If the configured endpoint is
1255
+ * an `http(s)://` address, this fetches `/json/version` from it and reads `webSocketDebuggerUrl`
1256
+ * from the response, matching the discovery flow exposed by Chrome's `--remote-debugging-port`.
1257
+ * A `ws(s)://` endpoint is returned unchanged.
1258
+ *
1259
+ * This is the subclass override point for helpers that connect through a different discovery
1260
+ * mechanism (e.g. a cloud browser provider with its own session-creation API).
1261
+ * @returns a `ws(s)://` debugger URL ready to be passed to `CDPConnection`.
1262
+ */
1263
+ protected _resolveEndpoint(): Promise<string>;
1264
+ /**
1265
+ * Resolves the CDP endpoint and opens the underlying `CDPConnection`, storing it on `this.cdp`.
1266
+ */
1267
+ protected _connect(): void;
1268
+ /**
1269
+ * Hook executed before each test. Ensures a live `CDPConnection` exists (connecting lazily on
1270
+ * first use, and reconnecting if a previous connection was closed), then creates a fresh
1271
+ * `about:blank` target and attaches to it with `Target.attachToTarget`, storing `this.targetId`
1272
+ * and `this.sessionId`. `Page` and `Runtime` domains are enabled on the new session, and engine
1273
+ * capabilities are probed here (against `about:blank`, uncontended) rather than only lazily on
1274
+ * the first real page — see `_probeCapabilities`.
1275
+ *
1276
+ * Also resets `_navStartWaiters` and `_lastMainFrameNav`: both are scoped to a single
1277
+ * `sessionId`/`targetId`, which are about to change, so anything left over from the previous test
1278
+ * (e.g. an action-settle waiter still armed because its test threw between arming and settling)
1279
+ * can never legitimately resolve against the new session — better to drop it here than leave it
1280
+ * waiting for the rest of the run.
1281
+ */
1282
+ protected _before(): void;
1283
+ /**
1284
+ * Lazily installs a single, persistent `Page.lifecycleEvent` listener on the underlying
1285
+ * `CDPConnection` and drains it into whichever `_waitForLoadEvent` calls are currently pending,
1286
+ * matched by `loaderId`. Installed once per helper instance (the connection outlives individual
1287
+ * tests), never removed — `CDPConnection` has no listener-removal API, so a single persistent
1288
+ * dispatcher (rather than one listener per navigation) is what keeps this leak-free.
1289
+ *
1290
+ * Also, for the main frame (`params.frameId === this.targetId`, which holds for a page target's
1291
+ * own top-level frame) only:
1292
+ * - Drains `_navStartWaiters` (armed by `_armActionSettle`, before an action, for `_waitForAction`'s
1293
+ * event-aware settle) on an `'init'` event — confirmed via a raw probe (against both Obscura and
1294
+ * Chrome, through the actual CLI path) to be the earliest signal CDP emits when a new top-level
1295
+ * navigation begins. Arming happens *before* the action is dispatched, not after: the same probe
1296
+ * found `'init'` can arrive while the action's own CDP round trip is still in flight, sometimes
1297
+ * only a millisecond or two after it started — a listener installed only once the action's
1298
+ * promise resolves can already be too late, not merely unlucky.
1299
+ * - Maintains `_lastMainFrameNav`, a rolling `{loaderId, events}` record of every lifecycle event
1300
+ * name seen for the current main-frame navigation (reset whenever `loaderId` changes). On a
1301
+ * fast/local navigation, the same raw probe found the *entire* sequence — `init` through
1302
+ * `networkIdle` — arriving as one batch while the triggering action's own round trip was still
1303
+ * in flight. Without this cache, `_waitForAction` would correctly detect that a navigation
1304
+ * started, then arm a *fresh* wait for the `load` event specifically — which, in that common
1305
+ * case, had already fired and will never fire again, paying the full grace-window-plus-poll cost
1306
+ * of `_waitForPageLoad` on every single navigating action instead of settling immediately.
1307
+ */
1308
+ protected _ensureLifecycleListener(): void;
1309
+ /**
1310
+ * Starts waiting for a `Page.lifecycleEvent` named `eventName` for the given `loaderId` on the
1311
+ * current session. `loaderId` (from the `Page.navigate` response) discriminates the awaited
1312
+ * navigation from any other in-flight or stale lifecycle events (e.g. the `about:blank` target
1313
+ * created in `_before`), which is essential since Chrome emits the target's initial `about:blank`
1314
+ * lifecycle sequence asynchronously, sometimes after this listener is already installed.
1315
+ *
1316
+ * Returns a `{promise, cancel}` pair rather than a bare promise: `_waitForPageLoad` races this
1317
+ * against a readyState poll, and whichever side loses must be actively torn down (not just have
1318
+ * its rejection swallowed) — an abandoned-but-still-pending wait would sit in `_pageLoadWaiters`
1319
+ * for the full timeout on every single navigation, for no purpose.
1320
+ * @param loaderId - the loader id of the navigation to wait for, from `Page.navigate`'s response.
1321
+ * @param eventName - the `Page.lifecycleEvent` name to wait for (e.g. `load`, `DOMContentLoaded`, `networkIdle`).
1322
+ * @param timeoutSec - maximum time to wait, in seconds.
1323
+ */
1324
+ protected _waitForLoadEvent(loaderId: string, eventName: string, timeoutSec: number): any;
1325
+ /**
1326
+ * Arms the event-aware settle's navigation-start listener. Must be called *before* the action
1327
+ * that might trigger a navigation is dispatched, not after — see `_ensureLifecycleListener` for
1328
+ * why. Returns `null` when `options.waitForAction` was set explicitly, since `_waitForAction`
1329
+ * ignores the armed listener entirely in that case (a literal fixed sleep, as before this round).
1330
+ *
1331
+ * No timeout here: `_waitForAction` applies the grace window itself, starting from when *it*
1332
+ * runs (after the action's own dispatch already resolved), racing this already-armed listener
1333
+ * against a fresh timer instead of one that started ticking before the action even began.
1334
+ */
1335
+ protected _armActionSettle(): any | null;
1336
+ /**
1337
+ * Waits for a page to finish loading after `Page.navigate`/`Page.reload`, per `options.waitForNavigation`.
1338
+ *
1339
+ * Purely event-driven for the first `PAGE_LOAD_GRACE_MS`: only the push-based
1340
+ * `Page.lifecycleEvent` signal (matched by `loaderId`) is awaited, issuing zero `_evaluate` calls
1341
+ * — this matters because an `_evaluate` sent while the page's own JavaScript is still busy (e.g.
1342
+ * a real-world page doing post-load hydration/analytics work) can queue behind it for hundreds of
1343
+ * ms to multiple seconds, measured directly against a JS-heavy page. Only if the grace window
1344
+ * elapses without the event (an engine that doesn't emit it, or a genuinely slow navigation) does
1345
+ * the `document.readyState` poll (via `_poll`) start, racing the still-pending lifecycle wait —
1346
+ * both bounded by the same `options.getPageTimeout`, so a lifecycle-less engine costs at most
1347
+ * `PAGE_LOAD_GRACE_MS` more than the poll alone would have, never double the timeout. No
1348
+ * `loaderId` (e.g. from `Page.reload`, which returns none) skips straight to the poll.
1349
+ *
1350
+ * Whichever side ultimately loses is actively cancelled, not merely abandoned — an abandoned poll
1351
+ * or lifecycle wait would otherwise keep running (issuing readyState `_evaluate` calls every
1352
+ * `pollInterval`, or holding a `_pageLoadWaiters` entry) for up to the full timeout on every
1353
+ * navigation, competing for the same CDP connection with real work.
1354
+ * @param loaderId - loader id from the triggering `Page.navigate` response, if any.
1355
+ * @param timeoutMessage - error message used if the readyState poll times out.
1356
+ */
1357
+ protected _waitForPageLoad(loaderId: string | null, timeoutMessage: string): Promise<void>;
1358
+ /**
1359
+ * Hook executed after each test. Closes the target opened in `_before` via `Target.closeTarget`
1360
+ * and clears `this.targetId`/`this.sessionId`. The underlying `CDPConnection` is left open so it
1361
+ * can be reused by the next test.
1362
+ */
1363
+ protected _after(): void;
1364
+ /**
1365
+ * Hook executed after all tests are run. Closes the underlying `CDPConnection` (and its
1366
+ * WebSocket) and clears `this.cdp`. Must leave no open sockets or pending timers behind, so the
1367
+ * process can exit on its own.
1368
+ */
1369
+ protected _finishTest(): void;
1370
+ /**
1371
+ * Evaluates a JavaScript expression in the page attached to the current session via
1372
+ * `Runtime.evaluate`, awaiting any returned promise and returning the value by reference
1373
+ * (`returnByValue: true`). If the expression throws, the browser-side exception description
1374
+ * (or fallback text) is re-thrown as a JS `Error`.
1375
+ * @param expression - a JavaScript expression (or IIFE) to run in the page context.
1376
+ * @returns the evaluated value, or `undefined` if the expression has no result.
1377
+ */
1378
+ protected _evaluate(expression: string): Promise<any>;
1379
+ /**
1380
+ * Ensures the in-page client (`window.__codecept`, installed from `cdpBrowserClient.js`) is
1381
+ * present on the current page, installing it (and the XPath polyfill, if needed) exactly once.
1382
+ * Safe to call repeatedly; it is a no-op once the client is detected.
1383
+ */
1384
+ protected _ensureClient(): void;
1385
+ /**
1386
+ * Installs the in-page client unconditionally — no `typeof window.__codecept` presence check.
1387
+ * Used by callers that already know, from a sentinel value returned alongside a failed action,
1388
+ * that the client is missing on the current page, so re-checking would just be a redundant
1389
+ * contended round trip.
1390
+ *
1391
+ * The 171KB XPath polyfill is only injected alongside the client when `needsXPath` is true (the
1392
+ * default, for callers without candidate information) *and* the engine actually needs it
1393
+ * (`capabilities.xpath === 'polyfill'`, cached from `_before`'s probe). Callers that know their
1394
+ * candidates never resolve to an `xpath` strategy (e.g. `_runSelected`, once it has inspected
1395
+ * `candidates`/`within`) can pass `false` to skip that inject — the client is still told, via the
1396
+ * `xpathNeedsPolyfill` flag baked in at install time, that the *engine* will eventually need it,
1397
+ * so a later call that does hit an xpath candidate gets a clean `'__NO_XPATH__'` miss signal
1398
+ * (from `window.__codecept.run`) instead of silently falling through to a broken native
1399
+ * `document.evaluate` — `_runSelected` reacts to that sentinel by injecting the polyfill and
1400
+ * retrying once, mirroring the `'__NO_CLIENT__'` handling right next to it.
1401
+ */
1402
+ protected _installClient(needsXPath?: boolean): void;
1403
+ /**
1404
+ * Whether any candidate strategy — in `candidates` itself, or in any of the `within` scoping
1405
+ * `layers` searched before it — is an `xpath` locator. Used to decide, before the client is even
1406
+ * installed, whether the XPath polyfill needs to be bundled into that install or can be deferred.
1407
+ */
1408
+ protected _candidatesNeedXPath(candidates: { type: string; value: string; }[], layers: { type: string; value: string; }[][]): boolean;
1409
+ /**
1410
+ * Determines whether the bundled XPath polyfill must be injected before the in-page client is
1411
+ * installed. Honors an explicit `options.xpathPolyfill` boolean; otherwise reuses a previously
1412
+ * probed `capabilities.xpath`, or probes the page's native `document.evaluate`. The probe appends
1413
+ * two throwaway elements distinguished only by text content and asserts that a text-value XPath
1414
+ * predicate (`normalize-space(string(.))=...`, the basis of every fuzzy/clickable locator) resolves
1415
+ * to exactly the matching one — merely checking that `document.evaluate` runs without throwing is
1416
+ * not enough, since some engines execute a text-value predicate without actually filtering by it,
1417
+ * silently returning every candidate node instead of none or one. The result is cached on
1418
+ * `capabilities.xpath` (`'native'` or `'polyfill'`).
1419
+ * @returns `true` if the polyfill should be injected.
1420
+ */
1421
+ protected _needsXPathPolyfill(): Promise<boolean>;
1422
+ /**
1423
+ * Determines whether `see`/`dontSee`/`waitForText` should read whole-page text through the
1424
+ * client's own visibility-aware `visibleText()` walker instead of the native
1425
+ * `document.body.innerText`. Probes once per page by appending a `display:none` element and a
1426
+ * `<script>` element, each with distinguishing text, and checking that native `innerText`
1427
+ * excludes both — some engines return an `innerText` that does not honor computed visibility or
1428
+ * exclude script/style content, even when `getComputedStyle`/layout are otherwise reliable. The
1429
+ * result is cached on `capabilities.innerText` (`'native'` or `'computed'`).
1430
+ * @returns `true` if the `visibleText()` fallback should be used.
1431
+ */
1432
+ protected _needsVisibleTextFallback(): Promise<boolean>;
1433
+ /**
1434
+ * Probes and caches capabilities that depend on the actual browser *engine* rather than any
1435
+ * particular page's content: `capabilities.layout` (via `getComputedStyle`), `capabilities.screenshot`
1436
+ * (inferred from `layout`), `capabilities.xpath` (via `_needsXPathPolyfill`), and
1437
+ * `capabilities.innerText` (via `_needsVisibleTextFallback`). Already-known capabilities
1438
+ * (pre-seeded through `options.capabilities`, or probed earlier) are never re-probed — so, across
1439
+ * a whole run, this issues a handful of `_evaluate` calls exactly once and is a no-op afterward.
1440
+ *
1441
+ * Called from `_before`, against the fresh `about:blank` target created there, specifically so
1442
+ * these probes run before any real navigation — measured directly (a full stall ledger against
1443
+ * `github.com`) that running them on the first *real* page instead can cost seconds each, since
1444
+ * every one is an `_evaluate` competing with that page's own JavaScript for the V8 isolate.
1445
+ * `about:blank` has no such competition. Also called (cheaply, already cached by then) from
1446
+ * `amOnPage`, so a helper that skips `_before` for some reason still probes correctly.
1447
+ *
1448
+ * The `xpath`/`innerText` probes determine *whether* their respective fallback is needed; they
1449
+ * do not install anything — injection stays deferred to `_ensureClient`'s reactive install and
1450
+ * `_textSource`'s own read, matching `amOnPage` no longer eagerly installing the client.
1451
+ */
1452
+ protected _probeCapabilities(): void;
1453
+ /**
1454
+ * Delegates a find-and-act call to `window.__codecept.run(candidates, action, payload)`. This is
1455
+ * the primary extension point used by helpers built on top of this class for element queries and
1456
+ * interactions.
1457
+ *
1458
+ * A per-call `context` locator, when given, is resolved and layered on top of any active
1459
+ * `within` block (searched inside it, not instead of it), so `context` narrows the search
1460
+ * without breaking out of a surrounding `within`.
1461
+ * @param candidates - locator strategies to try, in order, until one matches at least one element.
1462
+ * @param action - name of the action to run against the matched elements (e.g. `count`, `click`, `fill`).
1463
+ * @param [payload] - extra data the action needs (e.g. `{ value }` for `fill`).
1464
+ * @param [context = null] - element to search in, narrowing the candidates below it.
1465
+ * @returns number of matched elements and the action's result.
1466
+ */
1467
+ protected _run(candidates: { type: 'css' | 'xpath'; value: string; }[], action: string, payload?: any, context?: CodeceptJS.LocatorOrString): Promise<{ found: number; result: any; }>;
1468
+ /**
1469
+ * Same as `_run`, but takes an explicit selection descriptor instead of reading one from
1470
+ * `store.currentStep`/`options.strict`. Used internally by `CDPElementHandle` to address one
1471
+ * specific element out of a candidate set by its 1-based index.
1472
+ *
1473
+ * The in-page client's presence is checked in the same round-trip as the action itself: the
1474
+ * evaluated expression resolves to a sentinel string when `window.__codecept` is missing (e.g.
1475
+ * right after a navigation the registered script didn't reach), in which case the client is
1476
+ * installed and the call is retried exactly once. Separately, if the client is already present
1477
+ * but reports (via its own `'__NO_XPATH__'` sentinel) that this call needs the XPath polyfill and
1478
+ * it was not bundled into that earlier install, the polyfill is injected and the call is retried
1479
+ * once more — see `_installClient`.
1480
+ * @param selection - `{index}` or `{strict: true}`, mirroring `_selectionDescriptor`.
1481
+ */
1482
+ protected _runSelected(candidates: { type: 'css' | 'xpath'; value: string; }[], action: string, payload: any | null, selection: any | null, context?: CodeceptJS.LocatorOrString): Promise<{ found: number; result: any; }>;
1483
+ /**
1484
+ * Builds the `{index, strict}` element-selection descriptor from the current step's options
1485
+ * (`store.currentStep.opts`) and `options.strict`, mirroring the semantics of
1486
+ * `lib/helper/extras/elementSelection.js` (used by Puppeteer/WebDriver): a per-step
1487
+ * `elementIndex` (numeric, or the `'first'`/`'last'` aliases) always takes precedence and
1488
+ * disables strict mode for that step; otherwise `exact`/`strictMode` per-step options
1489
+ * override `options.strict` to enable or cancel strict mode.
1490
+ * @returns descriptor with optional `index` and `strict` keys, or `null` when neither applies.
1491
+ */
1492
+ protected _selectionDescriptor(): any | null;
1493
+ /**
1494
+ * A short, human-readable label built from `candidates`, used in `_run`'s elementIndex/strict
1495
+ * error messages when no locator string is otherwise available.
1496
+ */
1497
+ protected _candidatesLabel(candidates: { type: 'css' | 'xpath'; value: string; }[]): string;
1498
+ /**
1499
+ * Starts a `within` block, scoping every subsequent `_run` call (and therefore every element
1500
+ * lookup performed by this helper) to the descendants of the element matched by `locator`.
1501
+ * Verifies the element exists (against the full document, i.e. unscoped) before narrowing.
1502
+ * @param locator - element located by CSS|XPath|strict locator.
1503
+ */
1504
+ _withinBegin(locator: CodeceptJS.LocatorOrString): Promise<void>;
1505
+ /**
1506
+ * Ends the current `within` block, restoring unscoped element lookups.
1507
+ */
1508
+ _withinEnd(): Promise<void>;
1509
+ /**
1510
+ * Repeatedly calls `fn` until it returns a truthy value or `timeoutSec` elapses, checking
1511
+ * immediately and waiting `options.pollInterval` milliseconds between subsequent attempts.
1512
+ * @param fn - the condition to poll; should resolve to a truthy value once satisfied.
1513
+ * @param timeoutSec - maximum time to poll, in seconds.
1514
+ * @param message - error message used when the timeout is reached.
1515
+ * @param [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.
1516
+ * @returns the truthy value returned by `fn`.
1517
+ */
1518
+ protected _poll(fn: (...params: any[]) => any, timeoutSec: number, message: string, cancelToken?: any): Promise<any>;
1519
+ /**
1520
+ * Resolves a path against `options.url`. Absolute URLs (matching `scheme://`) are returned
1521
+ * unchanged; anything else is appended to `options.url` with its trailing slash stripped.
1522
+ * @param path - an absolute URL or a path relative to `options.url`.
1523
+ * @returns the resolved, absolute URL.
1524
+ */
1525
+ protected _url(path: string): string;
1526
+ /**
1527
+ * Opens a web page in the current session.
1528
+ *
1529
+ * ```js
1530
+ * I.amOnPage('/'); // opens main page of website
1531
+ * I.amOnPage('https://github.com'); // opens github
1532
+ * I.amOnPage('/login'); // opens a login page
1533
+ * ```
1534
+ *
1535
+ * Navigates via `Page.navigate`, then waits (up to `options.getPageTimeout` seconds) for the page
1536
+ * to finish loading, preferring the push-based `Page.lifecycleEvent` signal (per
1537
+ * `options.waitForNavigation`) over polling `document.readyState`. Capabilities are (re-)probed
1538
+ * (a no-op after the first page, since they're cached for the helper's lifetime).
1539
+ *
1540
+ * The in-page client is deliberately *not* eagerly (re-)installed here — navigation discards any
1541
+ * previously injected script, but installing it is deferred to the first actual action after
1542
+ * this call, via `_runSelected`'s sentinel-and-retry. This keeps `amOnPage` itself down to the
1543
+ * navigate command plus the push-based wait: no `_evaluate` call is issued on this hot path,
1544
+ * which matters most right when the page's own JavaScript may still be busy (measured directly:
1545
+ * an `_evaluate` sent in that window can queue behind it for hundreds of ms to multiple seconds
1546
+ * on a JS-heavy real-world page, regardless of how small the evaluated expression is).
1547
+ * @param url - url path or global url.
1548
+ */
1549
+ amOnPage(url: string): Promise<void>;
1550
+ /**
1551
+ * Reloads the current page.
1552
+ *
1553
+ * ```js
1554
+ * I.refreshPage();
1555
+ * ```
1556
+ *
1557
+ * Triggers `Page.reload` and waits (up to `options.getPageTimeout` seconds) for
1558
+ * `document.readyState` to reach `'complete'`.
1559
+ */
1560
+ refreshPage(): Promise<void>;
1561
+ /**
1562
+ * Executes a JavaScript function in the browser context and returns its result.
1563
+ *
1564
+ * If a function is passed, it is serialized with `Function.prototype.toString()`, so it must
1565
+ * not reference variables from the outer (Node.js) scope — pass any needed data as arguments
1566
+ * instead. A string is evaluated as-is.
1567
+ *
1568
+ * ```js
1569
+ * let title = await I.executeScript(() => document.title);
1570
+ * let sum = await I.executeScript((a, b) => a + b, 2, 3);
1571
+ * ```
1572
+ *
1573
+ * If the function returns a promise, `executeScript` waits for it to resolve.
1574
+ * @param fn - a JavaScript function to be executed in the browser context, or a string expression.
1575
+ * @param args - arguments to pass into the function.
1576
+ * @returns the value returned (or resolved) by the function.
1577
+ */
1578
+ executeScript(fn: string | ((...params: any[]) => any), ...args: any[]): Promise<any>;
1579
+ /**
1580
+ * Retrieves the page URL of the current page.
1581
+ *
1582
+ * ```js
1583
+ * let url = await I.grabCurrentUrl();
1584
+ * console.log(`Current URL is [${url}]`);
1585
+ * ```
1586
+ * @returns current URL.
1587
+ */
1588
+ grabCurrentUrl(): Promise<string>;
1589
+ /**
1590
+ * Retrieves a page title.
1591
+ *
1592
+ * ```js
1593
+ * let title = await I.grabTitle();
1594
+ * ```
1595
+ * @returns title of the page.
1596
+ */
1597
+ grabTitle(): Promise<string>;
1598
+ /**
1599
+ * Retrieves the source code of the current page.
1600
+ *
1601
+ * ```js
1602
+ * let pageSource = await I.grabSource();
1603
+ * ```
1604
+ * @returns source code of the current page (the outer HTML of `<html>`).
1605
+ */
1606
+ grabSource(): Promise<string>;
1607
+ /**
1608
+ * Builds the list of `{type, value}` candidates `_run` should try, in order, for a given
1609
+ * locator and `kind`. A strict locator (CSS/XPath/object form) resolves to a single candidate.
1610
+ * A fuzzy (plain-text) locator is expanded into a strategy-specific list of XPath expressions
1611
+ * mirroring the click/field/checkbox matching used by other browser helpers (matching by
1612
+ * visible text, label, name, placeholder, ARIA attributes, etc.), falling back to treating the
1613
+ * raw text as a CSS selector.
1614
+ *
1615
+ * A role locator (`{role, text, exact}`) resolves to a single `role`-type candidate, resolved
1616
+ * in-page by the client's implicit ARIA role mapping (native elements) plus explicit `role`
1617
+ * attributes, filtered by accessible name/text when `text` is given.
1618
+ * @param locator - element located by CSS|XPath|strict locator, or plain fuzzy text.
1619
+ * @param [kind = 'element'] - matching strategy to use when `locator` is fuzzy.
1620
+ * @returns candidates to pass to `_run`.
1621
+ */
1622
+ protected _candidates(locator: CodeceptJS.LocatorOrString, kind?: 'element' | 'clickable' | 'field' | 'checkable'): { type: 'css' | 'xpath' | 'role'; value: string | object; }[];
1623
+ /**
1624
+ * Resolves the text to search `see`/`dontSee`/`waitForText` against, when no explicit `context`
1625
+ * locator is given. An explicit `context` is always resolved through `_run`, so it is implicitly
1626
+ * scoped to the active `within` block, if any. Without a `context`, this reads the `within` root's
1627
+ * text when a `within` block is active, or the whole page's text otherwise — via native
1628
+ * `document.body.innerText`, or the client's `visibleText()` walker when
1629
+ * `_needsVisibleTextFallback` determines native `innerText` is not trustworthy.
1630
+ */
1631
+ protected _textSource(context: CodeceptJS.LocatorOrString): Promise<string>;
1632
+ /**
1633
+ * Runs the in-page `containsText` check against the whole page (no `context`/`within` scoping —
1634
+ * those stay on `_textSource`'s per-element path, already small). Returns only `{found, snippet}`
1635
+ * instead of the full haystack: on a page with a large body, serializing that whole string across
1636
+ * the CDP wire (and, on engines where `capabilities.innerText` requires the `visibleText()`
1637
+ * walker, holding it in memory) is avoidable work `see`/`dontSee`/`waitForText` don't actually
1638
+ * need on their common, non-throwing path.
1639
+ *
1640
+ * Also folds the client's install into the very same round trip when it is still missing, instead
1641
+ * of a separate presence-check evaluate followed by an install evaluate before the check itself
1642
+ * can even run — mirroring `_runSelected`'s sentinel-retry design, but collapsed into one evaluate
1643
+ * since the install source itself is known and cacheable up front. That install is client-only,
1644
+ * never the 171KB XPath polyfill: `containsText` never calls `document.evaluate`, so bundling it
1645
+ * here would be pure waste for a scenario that never resolves an xpath locator. The client is
1646
+ * still told, via `installCodeceptClient`'s `xpathNeedsPolyfill` flag, whether the *engine*
1647
+ * (`capabilities.xpath`, cached by `_before`'s `about:blank` probe) will eventually need it, so a
1648
+ * later xpath-resolving action on the same page gets a clean `'__NO_XPATH__'` miss signal from
1649
+ * `window.__codecept.run` instead of silently hitting a broken native `document.evaluate` —
1650
+ * `_runSelected` reacts to that sentinel already. The bootstrap source is built once and reused
1651
+ * for the life of the instance, since whether the engine needs the polyfill never changes.
1652
+ */
1653
+ protected _runTextCheck(text: string, opts: any): Promise<{ found: boolean; snippet: string | null; }>;
1654
+ /**
1655
+ * Shared implementation for `see`/`dontSee`. Without a `context` locator and outside any `within`
1656
+ * block, checks presence via `_runTextCheck`'s fast, boolean-only round trip; the full haystack is
1657
+ * only fetched (one extra, rare evaluate) when the assertion is about to fail, to build the same
1658
+ * `stringIncludes` error as before this optimization. With a `context` or inside `within`, this is
1659
+ * unchanged from before — already a small, per-element read, not the identified cost.
1660
+ */
1661
+ protected _checkText(text: string, context: CodeceptJS.LocatorOrString, negate: boolean): Promise<void>;
1662
+ /**
1663
+ * Checks that a page contains a visible text.
1664
+ * Use context parameter to narrow down the search.
1665
+ *
1666
+ * ```js
1667
+ * I.see('Welcome'); // text welcome on a page
1668
+ * I.see('Welcome', '.content'); // text inside .content div
1669
+ * I.see('Register', {css: 'form.register'}); // use strict locator
1670
+ * ```
1671
+ * @param text - expected on page.
1672
+ * @param [context = null] - (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text.
1673
+ */
1674
+ see(text: string, context?: CodeceptJS.LocatorOrString): Promise<void>;
1675
+ /**
1676
+ * Opposite to `see`. Checks that a text is not present on a page.
1677
+ * Use context parameter to narrow down the search.
1678
+ *
1679
+ * ```js
1680
+ * I.dontSee('Login'); // assume we are already logged in.
1681
+ * I.dontSee('Login', '.nav'); // no login inside .nav element
1682
+ * ```
1683
+ * @param text - which is not present.
1684
+ * @param [context = null] - (optional) element located by CSS|XPath|strict locator in which to perform search.
1685
+ */
1686
+ dontSee(text: string, context?: CodeceptJS.LocatorOrString): Promise<void>;
1687
+ /**
1688
+ * Checks that the current page contains the given string in its raw source code.
1689
+ *
1690
+ * ```js
1691
+ * I.seeInSource('<h1>Green eggs &amp; ham</h1>');
1692
+ * ```
1693
+ * @param text - value to check.
1694
+ */
1695
+ seeInSource(text: string): Promise<void>;
1696
+ /**
1697
+ * Checks that the current page does not contain the given string in its raw source code.
1698
+ * @param text - value to check.
1699
+ */
1700
+ dontSeeInSource(text: string): Promise<void>;
1701
+ /**
1702
+ * Checks that current url contains a provided fragment.
1703
+ *
1704
+ * ```js
1705
+ * I.seeInCurrentUrl('/register'); // we are on registration page
1706
+ * ```
1707
+ * @param url - a fragment to check
1708
+ */
1709
+ seeInCurrentUrl(url: string): Promise<void>;
1710
+ /**
1711
+ * Checks that current url does not contain a provided fragment.
1712
+ * @param url - value to check.
1713
+ */
1714
+ dontSeeInCurrentUrl(url: string): Promise<void>;
1715
+ /**
1716
+ * Checks that title contains text.
1717
+ *
1718
+ * ```js
1719
+ * I.seeInTitle('Home Page');
1720
+ * ```
1721
+ * @param text - text value to check.
1722
+ */
1723
+ seeInTitle(text: string): Promise<void>;
1724
+ /**
1725
+ * Checks that a given Element is present in the DOM.
1726
+ * Element is located by CSS or XPath.
1727
+ *
1728
+ * ```js
1729
+ * I.seeElementInDOM('#modal');
1730
+ * ```
1731
+ * @param locator - element located by CSS|XPath|strict locator.
1732
+ */
1733
+ seeElementInDOM(locator: CodeceptJS.LocatorOrString): Promise<void>;
1734
+ /**
1735
+ * Opposite to `seeElementInDOM`. Checks that element is not on page.
1736
+ *
1737
+ * ```js
1738
+ * I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
1739
+ * ```
1740
+ * @param locator - located by CSS|XPath|strict locator.
1741
+ */
1742
+ dontSeeElementInDOM(locator: CodeceptJS.LocatorOrString): Promise<void>;
1743
+ /**
1744
+ * Throws if the current page has no real layout engine (`capabilities.layout === 'none'`),
1745
+ * used to guard visibility-dependent assertions that cannot be evaluated without one.
1746
+ * @param action - name of the calling assertion, used in the error message.
1747
+ */
1748
+ protected _assertLayoutSupported(action: string): void;
1749
+ /**
1750
+ * Checks that a given Element is visible.
1751
+ * Element is located by CSS or XPath.
1752
+ *
1753
+ * ```js
1754
+ * I.seeElement('#modal');
1755
+ * ```
1756
+ * @param locator - located by CSS|XPath|strict locator.
1757
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1758
+ */
1759
+ seeElement(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
1760
+ /**
1761
+ * Opposite to `seeElement`. Checks that element is not visible.
1762
+ *
1763
+ * ```js
1764
+ * I.dontSeeElement('.modal'); // modal is not shown
1765
+ * ```
1766
+ * @param locator - located by CSS|XPath|strict locator.
1767
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1768
+ */
1769
+ dontSeeElement(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
1770
+ /**
1771
+ * Verifies that the specified checkbox is checked.
1772
+ *
1773
+ * ```js
1774
+ * I.seeCheckboxIsChecked('Agree');
1775
+ * I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
1776
+ * I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
1777
+ * ```
1778
+ * @param locator - located by label|name|CSS|XPath|strict locator.
1779
+ */
1780
+ seeCheckboxIsChecked(locator: CodeceptJS.LocatorOrString): Promise<void>;
1781
+ /**
1782
+ * Verifies that the specified checkbox is not checked.
1783
+ *
1784
+ * ```js
1785
+ * I.dontSeeCheckboxIsChecked('#agree'); // located by ID
1786
+ * I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
1787
+ * ```
1788
+ * @param locator - located by label|name|CSS|XPath|strict locator.
1789
+ */
1790
+ dontSeeCheckboxIsChecked(locator: CodeceptJS.LocatorOrString): Promise<void>;
1791
+ /**
1792
+ * Retrieves a text from an element located by CSS or XPath and returns it to test.
1793
+ * Resumes test execution, so **should be used inside async with `await`** operator.
1794
+ *
1795
+ * ```js
1796
+ * let pin = await I.grabTextFrom('#pin');
1797
+ * ```
1798
+ * If multiple elements found returns first element.
1799
+ * @param locator - element located by CSS|XPath|strict locator.
1800
+ * @returns text value
1801
+ */
1802
+ grabTextFrom(locator: CodeceptJS.LocatorOrString): Promise<string>;
1803
+ /**
1804
+ * Retrieves all texts from elements located by CSS or XPath and returns it to test.
1805
+ * Resumes test execution, so **should be used inside async with `await`** operator.
1806
+ *
1807
+ * ```js
1808
+ * let pins = await I.grabTextFromAll('#pin li');
1809
+ * ```
1810
+ * @param locator - element located by CSS|XPath|strict locator.
1811
+ * @returns array of text values
1812
+ */
1813
+ grabTextFromAll(locator: CodeceptJS.LocatorOrString): Promise<string[]>;
1814
+ /**
1815
+ * Retrieves an array of `WebElement`s matching a locator (`lib/element/WebElement.js`,
1816
+ * wrapping a `CDPElementHandle`). Element handles are re-resolved on demand by re-running
1817
+ * `candidates` and picking the matching index, since `CDPBrowser` never keeps a persistent
1818
+ * handle to a DOM node on the Node side.
1819
+ *
1820
+ * ```js
1821
+ * const buttons = await I.grabWebElements({ role: 'button' });
1822
+ * ```
1823
+ * @param locator - element located by CSS|XPath|strict locator.
1824
+ * @returns array of WebElement instances.
1825
+ */
1826
+ grabWebElements(locator: CodeceptJS.LocatorOrString): Promise<object[]>;
1827
+ /**
1828
+ * Retrieves the first `WebElement` matching a locator.
1829
+ *
1830
+ * ```js
1831
+ * const button = await I.grabWebElement({ role: 'button', text: 'Submit' });
1832
+ * ```
1833
+ * @param locator - element located by CSS|XPath|strict locator.
1834
+ * @returns a WebElement instance.
1835
+ */
1836
+ grabWebElement(locator: CodeceptJS.LocatorOrString): Promise<object>;
1837
+ /**
1838
+ * Resolves whether the `texts` action should read via the client's `visibleText()` walker
1839
+ * (probed once via `_needsVisibleTextFallback` and cached on `capabilities.innerText`) instead
1840
+ * of each element's native `innerText`, then runs it.
1841
+ */
1842
+ protected _texts(candidates: { type: string; value: string | object; }[]): Promise<{ found: number; result: any; }>;
1843
+ /**
1844
+ * Retrieves a value from a form element located by CSS or XPath and returns it to test.
1845
+ * Resumes test execution, so **should be used inside async function with `await`** operator.
1846
+ * If more than one element is found - value of first element is returned.
1847
+ *
1848
+ * ```js
1849
+ * let email = await I.grabValueFrom('input[name=email]');
1850
+ * ```
1851
+ * @param locator - field located by label|name|CSS|XPath|strict locator.
1852
+ * @returns attribute value
1853
+ */
1854
+ grabValueFrom(locator: CodeceptJS.LocatorOrString): Promise<string>;
1855
+ /**
1856
+ * Retrieves an array of values from fields located by CSS or XPath and returns it to test.
1857
+ * Resumes test execution, so **should be used inside async function with `await`** operator.
1858
+ *
1859
+ * ```js
1860
+ * let inputs = await I.grabValueFromAll('//form/input');
1861
+ * ```
1862
+ * @param locator - field located by label|name|CSS|XPath|strict locator.
1863
+ * @returns array of attribute values
1864
+ */
1865
+ grabValueFromAll(locator: CodeceptJS.LocatorOrString): Promise<string[]>;
1866
+ /**
1867
+ * Retrieves an attribute from an element located by CSS or XPath and returns it to test.
1868
+ * Resumes test execution, so **should be used inside async with `await`** operator.
1869
+ * If more than one element is found - attribute of first element is returned.
1870
+ *
1871
+ * ```js
1872
+ * let hint = await I.grabAttributeFrom('#tooltip', 'title');
1873
+ * ```
1874
+ * @param locator - element located by CSS|XPath|strict locator.
1875
+ * @param attr - attribute name.
1876
+ * @returns attribute value
1877
+ */
1878
+ grabAttributeFrom(locator: CodeceptJS.LocatorOrString, attr: string): Promise<string>;
1879
+ /**
1880
+ * Retrieves an array of attributes from elements located by CSS or XPath and returns it to test.
1881
+ * Resumes test execution, so **should be used inside async with `await`** operator.
1882
+ *
1883
+ * ```js
1884
+ * let hints = await I.grabAttributeFromAll('.tooltip', 'title');
1885
+ * ```
1886
+ * @param locator - element located by CSS|XPath|strict locator.
1887
+ * @param attr - attribute name.
1888
+ * @returns array of attribute values
1889
+ */
1890
+ grabAttributeFromAll(locator: CodeceptJS.LocatorOrString, attr: string): Promise<string[]>;
1891
+ /**
1892
+ * Grab number of elements by locator.
1893
+ * Resumes test execution, so **should be used inside async function with `await`** operator.
1894
+ *
1895
+ * ```js
1896
+ * let numOfElements = await I.grabNumberOfElements('p');
1897
+ * ```
1898
+ * @param locator - located by CSS|XPath|strict locator.
1899
+ * @returns number of matched elements.
1900
+ */
1901
+ grabNumberOfElements(locator: CodeceptJS.LocatorOrString): Promise<number>;
1902
+ /**
1903
+ * Perform a click on a link or a button, given by a locator.
1904
+ * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
1905
+ * For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
1906
+ * For images, the "alt" attribute and inner text of any parent links are searched.
1907
+ *
1908
+ * When `options.input` is `'cdp'`, the click is dispatched as real `Input.dispatchMouseEvent` mouse events
1909
+ * (`mouseMoved` / `mousePressed` / `mouseReleased`) at the center of the element's bounding box, so it
1910
+ * exercises the same input pipeline a real user would. Otherwise it delegates to `forceClick`. A matched
1911
+ * element with a zero-size bounding box (e.g. `display: none`) has no valid coordinate to click and throws;
1912
+ * use `forceClick` to dispatch a synthetic click on such elements instead.
1913
+ *
1914
+ * ```js
1915
+ * // simple link
1916
+ * I.click('Logout');
1917
+ * // button of form
1918
+ * I.click('Submit');
1919
+ * // CSS button
1920
+ * I.click('#form input[type=submit]');
1921
+ * // XPath
1922
+ * I.click('//form/*[@type=submit]');
1923
+ * // using strict locator
1924
+ * I.click({css: 'nav a.login'});
1925
+ * ```
1926
+ * @param locator - clickable link or button located by text, or any element located by CSS|XPath|strict locator.
1927
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1928
+ */
1929
+ click(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
1930
+ /**
1931
+ * Perform an emulated click on a link or a button, given by a locator.
1932
+ * Unlike `click`, this always dispatches a synthetic in-page `el.click()` instead of sending native
1933
+ * CDP input events. This works on hidden, animated or inactive elements as well.
1934
+ *
1935
+ * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
1936
+ * For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
1937
+ * For images, the "alt" attribute and inner text of any parent links are searched.
1938
+ *
1939
+ * ```js
1940
+ * // simple link
1941
+ * I.forceClick('Logout');
1942
+ * // button of form
1943
+ * I.forceClick('Submit');
1944
+ * // CSS button
1945
+ * I.forceClick('#form input[type=submit]');
1946
+ * // XPath
1947
+ * I.forceClick('//form/*[@type=submit]');
1948
+ * // using strict locator
1949
+ * I.forceClick({css: 'nav a.login'});
1950
+ * ```
1951
+ * @param locator - clickable link or button located by text, or any element located by CSS|XPath|strict locator.
1952
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
1953
+ */
1954
+ forceClick(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
1955
+ /**
1956
+ * Settles after an interaction (click, key press, etc.) before the next step runs, using the
1957
+ * listener `_armActionSettle` started *before* the interaction was dispatched (`armed`; a fresh
1958
+ * one is armed here too, as a safety net, if a call site forgot to — but arming this late can
1959
+ * only miss a navigation that already started during the action's own dispatch, exactly the race
1960
+ * this design exists to avoid, so every call site should pass its own pre-armed `armed`, not rely
1961
+ * on this fallback).
1962
+ *
1963
+ * If `options.waitForAction` was set explicitly in the config, honors it literally as a fixed
1964
+ * pacing sleep, exactly as before this round — an explicit value is a deliberate choice
1965
+ * (slow-motion debugging, a known-slow app) this never second-guesses.
1966
+ *
1967
+ * Otherwise, event-aware: races the armed listener against a *fresh* `ACTION_SETTLE_GRACE_MS`
1968
+ * window (started now, not when it was armed — the action's own dispatch already ran concurrently
1969
+ * with the arm, so this is genuinely bounded extra time, not a guess). If nothing declares a
1970
+ * navigation, returns immediately once the window elapses — the common case for most actions
1971
+ * (typing, toggling a checkbox, focusing a field) — instead of a fixed `options.waitForAction`
1972
+ * (100ms by default) sleep on every single action regardless of whether anything is happening.
1973
+ *
1974
+ * If a navigation *did* start, `_lastMainFrameNav` (see `_ensureLifecycleListener`) is checked
1975
+ * first: on a fast/local page, the entire lifecycle sequence through the target event has
1976
+ * typically already arrived in the same batch that announced the navigation started, in which
1977
+ * case this returns immediately. Only a navigation still genuinely in flight falls through to
1978
+ * `_waitForPageLoad` (the same mechanism `amOnPage`/`refreshPage` use) — which waits for it to
1979
+ * actually finish, rather than a fixed sleep that has no relationship to how long the navigation
1980
+ * actually takes: strictly more correct for a slow navigation, not just faster for a fast one.
1981
+ * @param [armed] - from `_armActionSettle`, called before the action.
1982
+ */
1983
+ protected _waitForAction(armed?: any | null): Promise<void>;
1984
+ /**
1985
+ * Fills a text field or textarea, after clearing its value, with the given string.
1986
+ * Field is located by name, label, CSS, or XPath.
1987
+ *
1988
+ * ```js
1989
+ * // by label
1990
+ * I.fillField('Email', 'hello@world.com');
1991
+ * // by name
1992
+ * I.fillField('password', secret('123456'));
1993
+ * // by CSS
1994
+ * I.fillField('form#login input[name=username]', 'John');
1995
+ * // or by strict locator
1996
+ * I.fillField({css: 'form#login input[name=username]'}, 'John');
1997
+ * ```
1998
+ * @param field - located by label|name|CSS|XPath|strict locator.
1999
+ * @param value - text value to fill.
2000
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2001
+ */
2002
+ fillField(field: CodeceptJS.LocatorOrString, value: CodeceptJS.StringOrSecret, context?: CodeceptJS.LocatorOrString): Promise<void>;
2003
+ /**
2004
+ * Appends text to a input field or textarea.
2005
+ * Field is located by name, label, CSS or XPath
2006
+ *
2007
+ * ```js
2008
+ * I.appendField('#myTextField', 'appended');
2009
+ * // typing secret
2010
+ * I.appendField('password', secret('123456'));
2011
+ * ```
2012
+ * @param field - located by label|name|CSS|XPath|strict locator
2013
+ * @param value - text value to append.
2014
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2015
+ */
2016
+ appendField(field: CodeceptJS.LocatorOrString, value: string, context?: CodeceptJS.LocatorOrString): Promise<void>;
2017
+ /**
2018
+ * Clears a `<textarea>` or text `<input>` element's value.
2019
+ *
2020
+ * ```js
2021
+ * I.clearField('Email');
2022
+ * I.clearField('user[email]');
2023
+ * I.clearField('#email');
2024
+ * ```
2025
+ * @param field - editable field located by label|name|CSS|XPath|strict locator.
2026
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2027
+ */
2028
+ clearField(field: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
2029
+ /**
2030
+ * Selects an option in a drop-down select.
2031
+ * Field is searched by label | name | CSS | XPath.
2032
+ * Option is selected by visible text or by value.
2033
+ *
2034
+ * ```js
2035
+ * I.selectOption('Choose Plan', 'Monthly'); // select by label
2036
+ * I.selectOption('subscription', 'Monthly'); // match option by text
2037
+ * I.selectOption('subscription', '0'); // or by value
2038
+ * I.selectOption('//form/select[@name=account]','Premium');
2039
+ * I.selectOption('form select[name=account]', 'Premium');
2040
+ * I.selectOption({css: 'form select[name=account]'}, 'Premium');
2041
+ * ```
2042
+ * @param select - field located by label|name|CSS|XPath|strict locator.
2043
+ * @param option - visible text or value of option, or an array of them for a multi-select.
2044
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2045
+ */
2046
+ selectOption(select: CodeceptJS.LocatorOrString, option: string | string[], context?: CodeceptJS.LocatorOrString): Promise<void>;
2047
+ /**
2048
+ * Selects a checkbox or radio button.
2049
+ * Element is located by label or name or CSS or XPath.
2050
+ *
2051
+ * ```js
2052
+ * I.checkOption('#agree');
2053
+ * I.checkOption('I Agree to Terms and Conditions');
2054
+ * I.checkOption('agree', '//form');
2055
+ * ```
2056
+ * @param field - checkbox located by label | name | CSS | XPath | strict locator.
2057
+ * @param [context = null] - (optional, `null` by default) element located by CSS | XPath | strict locator.
2058
+ */
2059
+ checkOption(field: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
2060
+ /**
2061
+ * Unselects a checkbox or radio button.
2062
+ * Element is located by label or name or CSS or XPath.
2063
+ *
2064
+ * ```js
2065
+ * I.uncheckOption('#agree');
2066
+ * I.uncheckOption('I Agree to Terms and Conditions');
2067
+ * I.uncheckOption('agree', '//form');
2068
+ * ```
2069
+ * @param field - checkbox located by label | name | CSS | XPath | strict locator.
2070
+ * @param [context = null] - (optional, `null` by default) element located by CSS | XPath | strict locator.
2071
+ */
2072
+ uncheckOption(field: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
2073
+ /**
2074
+ * Attaches a file to a file input field, or drops it onto a drag-and-drop dropzone element,
2075
+ * resolved by label|name|CSS|XPath|strict locator. `pathToFile` is resolved relative to
2076
+ * `codecept_dir` (matching Puppeteer/WebDriver). Since `CDPBrowser` never brings element handles
2077
+ * back to Node, the resolved element is marked with a throwaway `data-codecept-upload` attribute
2078
+ * in-page (respecting `context`/`within`/elementIndex exactly like every other action). A real
2079
+ * `<input type="file">` is then addressed by that attribute through the CDP `DOM` domain, which
2080
+ * `CDPBrowser` otherwise never uses, to call `DOM.setFileInputFiles`; any other element (a
2081
+ * drag-and-drop dropzone) instead gets a synthetic `dragenter`/`dragover`/`drop` sequence with a
2082
+ * `DataTransfer` built from the file's contents, entirely in-page. The marker is removed again in
2083
+ * a `finally`.
2084
+ *
2085
+ * ```js
2086
+ * I.attachFile('Avatar', 'data/avatar.jpg');
2087
+ * I.attachFile('#file', 'data/avatar.jpg');
2088
+ * I.attachFile('#dropzone', 'data/avatar.jpg');
2089
+ * ```
2090
+ * @param field - located by label|name|CSS|XPath|strict locator.
2091
+ * @param pathToFile - path to file, relative to `codecept_dir`.
2092
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2093
+ */
2094
+ attachFile(field: CodeceptJS.LocatorOrString, pathToFile: string, context?: CodeceptJS.LocatorOrString): Promise<void>;
2095
+ /**
2096
+ * Waits for element to be present on page (by default waits for `options.waitForTimeout` seconds).
2097
+ * Element can be located by CSS or XPath.
2098
+ *
2099
+ * ```js
2100
+ * I.waitForElement('.btn.continue');
2101
+ * I.waitForElement('.btn.continue', 5); // wait for 5 secs
2102
+ * ```
2103
+ * @param locator - element located by CSS|XPath|strict locator.
2104
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2105
+ */
2106
+ waitForElement(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<void>;
2107
+ /**
2108
+ * Waits for a text to appear (by default waits for `options.waitForTimeout` seconds).
2109
+ * Element can be located by CSS or XPath.
2110
+ * Narrow down search results by providing context.
2111
+ *
2112
+ * ```js
2113
+ * I.waitForText('Thank you, form has been submitted');
2114
+ * I.waitForText('Thank you, form has been submitted', 5, '#modal');
2115
+ * ```
2116
+ * @param text - to wait for.
2117
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2118
+ * @param [context = null] - (optional) element located by CSS|XPath|strict locator.
2119
+ */
2120
+ waitForText(text: string, sec?: number, context?: CodeceptJS.LocatorOrString): Promise<void>;
2121
+ /**
2122
+ * Waiting for the part of the URL to match the expected. Useful for SPA to understand that page was changed.
2123
+ *
2124
+ * ```js
2125
+ * I.waitInUrl('/info', 2);
2126
+ * ```
2127
+ * @param urlPart - value to check.
2128
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2129
+ */
2130
+ waitInUrl(urlPart: string, sec?: number): Promise<void>;
2131
+ /**
2132
+ * Waits for a function to return true (waits for `options.waitForTimeout` seconds by default).
2133
+ * Running in browser context.
2134
+ *
2135
+ * ```js
2136
+ * I.waitForFunction(() => window.requests == 0);
2137
+ * I.waitForFunction(() => window.requests == 0, 5); // waits for 5 sec
2138
+ * I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and wait for 5 sec
2139
+ * ```
2140
+ * @param fn - to be executed in browser context.
2141
+ * @param [argsOrSec = null] - (optional) arguments for function or, if a number, seconds to wait.
2142
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2143
+ */
2144
+ waitForFunction(fn: string | ((...params: any[]) => any), argsOrSec?: any[] | number, sec?: number): Promise<void>;
2145
+ /**
2146
+ * Sets cookie(s).
2147
+ *
2148
+ * Can be a single cookie object or an array of cookies:
2149
+ *
2150
+ * ```js
2151
+ * I.setCookie({name: 'auth', value: true});
2152
+ *
2153
+ * // as array
2154
+ * I.setCookie([
2155
+ * {name: 'auth', value: true},
2156
+ * {name: 'agree', value: true}
2157
+ * ]);
2158
+ * ```
2159
+ * @param cookie - a cookie object or array of cookie objects.
2160
+ */
2161
+ setCookie(cookie: CodeceptJS.Cookie | CodeceptJS.Cookie[]): Promise<void>;
2162
+ /**
2163
+ * Retrieves all cookies visible to the current page.
2164
+ * Resumes test execution, so **should be used inside async function with `await`** operator.
2165
+ *
2166
+ * ```js
2167
+ * let cookies = await I.grabCookies();
2168
+ * ```
2169
+ * @returns array of cookie objects.
2170
+ */
2171
+ grabCookies(): Promise<CodeceptJS.Cookie[]>;
2172
+ /**
2173
+ * Gets a cookie object by name.
2174
+ * If none provided gets all cookies.
2175
+ * Resumes test execution, so **should be used inside async function with `await`** operator.
2176
+ *
2177
+ * ```js
2178
+ * let cookie = await I.grabCookie('auth');
2179
+ * assert(cookie.value, '123456');
2180
+ * ```
2181
+ * @param [name = null] - cookie name.
2182
+ * @returns a cookie object, or an array of all cookies when `name` is not provided.
2183
+ */
2184
+ grabCookie(name?: string | null): Promise<CodeceptJS.Cookie | CodeceptJS.Cookie[]>;
2185
+ /**
2186
+ * Clears a cookie by name,
2187
+ * if none provided clears all cookies.
2188
+ *
2189
+ * ```js
2190
+ * I.clearCookie();
2191
+ * I.clearCookie('test');
2192
+ * ```
2193
+ * @param [name = null] - (optional, `null` by default) cookie name
2194
+ */
2195
+ clearCookie(name?: string | null): Promise<void>;
2196
+ /**
2197
+ * Saves a screenshot to the output folder (set in codecept.conf.ts or codecept.conf.js).
2198
+ * Filename is relative to the output folder.
2199
+ *
2200
+ * ```js
2201
+ * I.saveScreenshot('debug.png');
2202
+ * ```
2203
+ * @param fileName - file name to save.
2204
+ */
2205
+ saveScreenshot(fileName: string): Promise<void>;
2206
+ /**
2207
+ * Saves a screenshot of a single element to the output folder.
2208
+ *
2209
+ * ```js
2210
+ * I.saveElementScreenshot('#logo', 'logo.png');
2211
+ * ```
2212
+ * @param locator - element located by CSS|XPath|strict locator.
2213
+ * @param fileName - file name to save.
2214
+ */
2215
+ saveElementScreenshot(locator: CodeceptJS.LocatorOrString, fileName: string): Promise<void>;
2216
+ /**
2217
+ * Pauses execution for a number of seconds.
2218
+ *
2219
+ * ```js
2220
+ * I.wait(2); // waits 2 secs
2221
+ * ```
2222
+ * @param sec - number of seconds to wait.
2223
+ */
2224
+ wait(sec: number): Promise<void>;
2225
+ /**
2226
+ * Checks that title does not contain text.
2227
+ * @param text - value to check.
2228
+ */
2229
+ dontSeeInTitle(text: string): Promise<void>;
2230
+ /**
2231
+ * Checks that current url is equal to provided one.
2232
+ * Unlike `seeInCurrentUrl` performs a strict comparison.
2233
+ *
2234
+ * ```js
2235
+ * I.seeCurrentUrlEquals('/register');
2236
+ * ```
2237
+ * @param url - value to check.
2238
+ */
2239
+ seeCurrentUrlEquals(url: string): Promise<void>;
2240
+ /**
2241
+ * Checks that current url is not equal to provided one.
2242
+ * Unlike `dontSeeInCurrentUrl` performs a strict comparison.
2243
+ * @param url - value to check.
2244
+ */
2245
+ dontSeeCurrentUrlEquals(url: string): Promise<void>;
2246
+ /**
2247
+ * Resolves the current page URL to a `pathname`, ignoring the origin, query string, and hash.
2248
+ * @returns the pathname of the current page.
2249
+ */
2250
+ protected _grabCurrentPath(): Promise<string>;
2251
+ /**
2252
+ * Checks that current url path (ignoring query string and hash) equals to provided one.
2253
+ *
2254
+ * ```js
2255
+ * I.seeCurrentPathEquals('/info');
2256
+ * ```
2257
+ * @param path - value to check.
2258
+ */
2259
+ seeCurrentPathEquals(path: string): Promise<void>;
2260
+ /**
2261
+ * Opposite to `seeCurrentPathEquals`.
2262
+ * @param path - value to check.
2263
+ */
2264
+ dontSeeCurrentPathEquals(path: string): Promise<void>;
2265
+ /**
2266
+ * Waits for the entire URL to match the expected (by default waits for `options.waitForTimeout` seconds).
2267
+ *
2268
+ * ```js
2269
+ * I.waitUrlEquals('/info', 2);
2270
+ * ```
2271
+ * @param urlPart - value to check.
2272
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2273
+ */
2274
+ waitUrlEquals(urlPart: string, sec?: number): Promise<void>;
2275
+ /**
2276
+ * Waits for current url path (ignoring query string and hash) to equal to the expected.
2277
+ *
2278
+ * ```js
2279
+ * I.waitCurrentPathEquals('/info', 2);
2280
+ * ```
2281
+ * @param path - value to check.
2282
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2283
+ */
2284
+ waitCurrentPathEquals(path: string, sec?: number): Promise<void>;
2285
+ /**
2286
+ * Checks that the given input field or textarea equals (contains) the given value.
2287
+ * For fuzzy locators, the field is searched by label|name|CSS|XPath|strict locator.
2288
+ *
2289
+ * ```js
2290
+ * I.seeInField('Username', 'davert');
2291
+ * ```
2292
+ * @param field - located by label|name|CSS|XPath|strict locator.
2293
+ * @param value - value to check.
2294
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2295
+ */
2296
+ seeInField(field: CodeceptJS.LocatorOrString, value: CodeceptJS.StringOrSecret, context?: CodeceptJS.LocatorOrString): Promise<void>;
2297
+ /**
2298
+ * Opposite to `seeInField`.
2299
+ * @param field - located by label|name|CSS|XPath|strict locator.
2300
+ * @param value - value to check.
2301
+ * @param [context = null] - (optional, `null` by default) element to search in CSS|XPath|Strict locator.
2302
+ */
2303
+ dontSeeInField(field: CodeceptJS.LocatorOrString, value: CodeceptJS.StringOrSecret, context?: CodeceptJS.LocatorOrString): Promise<void>;
2304
+ /**
2305
+ * Shared implementation for `seeInField`/`dontSeeInField`.
2306
+ */
2307
+ protected _seeInField(assertType: 'assert' | 'negate', field: CodeceptJS.LocatorOrString, value: CodeceptJS.StringOrSecret, context?: CodeceptJS.LocatorOrString): Promise<void>;
2308
+ /**
2309
+ * Grab number of visible elements by locator.
2310
+ *
2311
+ * ```js
2312
+ * let numOfVisibleElements = await I.grabNumberOfVisibleElements('p');
2313
+ * ```
2314
+ * @param locator - located by CSS|XPath|strict locator.
2315
+ * @returns number of visible matched elements.
2316
+ */
2317
+ grabNumberOfVisibleElements(locator: CodeceptJS.LocatorOrString): Promise<number>;
2318
+ /**
2319
+ * Asserts that an element appears a given number of times on the page, and that all matching elements are visible.
2320
+ *
2321
+ * ```js
2322
+ * I.seeNumberOfVisibleElements('.buttons', 3);
2323
+ * ```
2324
+ * @param locator - located by CSS|XPath|strict locator.
2325
+ * @param num - expected number of elements.
2326
+ */
2327
+ seeNumberOfVisibleElements(locator: CodeceptJS.LocatorOrString, num: number): Promise<void>;
2328
+ /**
2329
+ * Retrieves the current page scroll position.
2330
+ *
2331
+ * ```js
2332
+ * let { x, y } = await I.grabPageScrollPosition();
2333
+ * ```
2334
+ * @returns scroll position.
2335
+ */
2336
+ grabPageScrollPosition(): Promise<{ x: number; y: number; }>;
2337
+ /**
2338
+ * Scrolls to the top of the page.
2339
+ *
2340
+ * ```js
2341
+ * I.scrollPageToTop();
2342
+ * ```
2343
+ */
2344
+ scrollPageToTop(): Promise<void>;
2345
+ /**
2346
+ * Scrolls to the bottom of the page.
2347
+ *
2348
+ * ```js
2349
+ * I.scrollPageToBottom();
2350
+ * ```
2351
+ */
2352
+ scrollPageToBottom(): Promise<void>;
2353
+ /**
2354
+ * Scrolls to the element matched by locator, or to given coordinates.
2355
+ *
2356
+ * ```js
2357
+ * I.scrollTo('#submit');
2358
+ * I.scrollTo(100, 200);
2359
+ * ```
2360
+ * @param locator - element to scroll to, or an X coordinate if no element.
2361
+ * @param [offsetX = 0] - X offset, or Y coordinate if `locator` is a number.
2362
+ * @param [offsetY = 0] - Y offset applied when scrolling to an element.
2363
+ */
2364
+ scrollTo(locator: CodeceptJS.LocatorOrString | number, offsetX?: number, offsetY?: number): Promise<void>;
2365
+ /**
2366
+ * Retrieves a CSS property from an element located by CSS or XPath.
2367
+ * If more than one element is found - value of first element is returned.
2368
+ *
2369
+ * ```js
2370
+ * const value = await I.grabCssPropertyFrom('h3', 'font-weight');
2371
+ * ```
2372
+ * @param locator - element located by CSS|XPath|strict locator.
2373
+ * @param cssProperty - CSS property name.
2374
+ * @returns CSS value
2375
+ */
2376
+ grabCssPropertyFrom(locator: CodeceptJS.LocatorOrString, cssProperty: string): Promise<string>;
2377
+ /**
2378
+ * Retrieves an array of CSS properties from elements located by CSS or XPath.
2379
+ *
2380
+ * ```js
2381
+ * const values = await I.grabCssPropertyFromAll('h3', 'font-weight');
2382
+ * ```
2383
+ * @param locator - element located by CSS|XPath|strict locator.
2384
+ * @param cssProperty - CSS property name.
2385
+ * @returns array of CSS values
2386
+ */
2387
+ grabCssPropertyFromAll(locator: CodeceptJS.LocatorOrString, cssProperty: string): Promise<string[]>;
2388
+ /**
2389
+ * Checks that all elements matched by locator have the given CSS properties.
2390
+ *
2391
+ * ```js
2392
+ * I.seeCssPropertiesOnElements('h3', { 'font-weight': 'bold', display: 'block' });
2393
+ * ```
2394
+ * @param locator - element located by CSS|XPath|strict locator.
2395
+ * @param cssProperties - object with CSS properties and their values to check.
2396
+ */
2397
+ seeCssPropertiesOnElements(locator: CodeceptJS.LocatorOrString, cssProperties: any): Promise<void>;
2398
+ /**
2399
+ * Checks that all elements matched by locator have the given attribute values.
2400
+ * An expected value is matched either as an exact match or as a regular expression against the actual value.
2401
+ *
2402
+ * ```js
2403
+ * I.seeAttributesOnElements('//form', { method: 'post' });
2404
+ * ```
2405
+ * @param locator - element located by CSS|XPath|strict locator.
2406
+ * @param attributes - object with attribute names and expected values.
2407
+ */
2408
+ seeAttributesOnElements(locator: CodeceptJS.LocatorOrString, attributes: any): Promise<void>;
2409
+ /**
2410
+ * Focuses a given element.
2411
+ *
2412
+ * ```js
2413
+ * I.focus('#name');
2414
+ * ```
2415
+ * @param locator - element located by CSS|XPath|strict locator.
2416
+ */
2417
+ focus(locator: CodeceptJS.LocatorOrString): Promise<void>;
2418
+ /**
2419
+ * Removes focus from a given element.
2420
+ *
2421
+ * ```js
2422
+ * I.blur('#name');
2423
+ * ```
2424
+ * @param locator - element located by CSS|XPath|strict locator.
2425
+ */
2426
+ blur(locator: CodeceptJS.LocatorOrString): Promise<void>;
2427
+ /**
2428
+ * Types characters into the currently focused element (as set by `click`, `focus`, etc). Each
2429
+ * character dispatches a real `keydown` → `keypress` → (value mutated) → `input` → `keyup`
2430
+ * sequence, and mutates a `contenteditable` host's `textContent` instead of `.value`, so this
2431
+ * works on rich-text/contenteditable targets as well as `input`/`textarea`. Mirrors Puppeteer's
2432
+ * `type(text, options)` semantics.
2433
+ *
2434
+ * Without a `delay`, every character is dispatched in a single round-trip to the page. With a
2435
+ * `delay`, characters are dispatched one round-trip at a time so the requested pause actually
2436
+ * elapses between key presses.
2437
+ *
2438
+ * ```js
2439
+ * I.click('Name');
2440
+ * I.type('CodeceptJS');
2441
+ * I.type(['C', 'o', 'd', 'e']);
2442
+ * ```
2443
+ * @param keys - characters to type, either as a string or an array of characters.
2444
+ * @param [delay = null] - (optional) delay in milliseconds between key presses.
2445
+ */
2446
+ type(keys: string | string[], delay?: number): Promise<void>;
2447
+ /**
2448
+ * Presses a key or key combination on the currently focused element.
2449
+ * Under `options.strict`, a modifier+editing-key combination (e.g. `Ctrl+A`) dispatched with no
2450
+ * element focused throws `NonFocusedType`, mirroring `focusCheck.js`'s behavior on other helpers.
2451
+ *
2452
+ * ```js
2453
+ * I.pressKey('Enter');
2454
+ * I.pressKey(['Control', 'a']);
2455
+ * ```
2456
+ * @param key - a key or an array of keys to combine (modifiers first).
2457
+ */
2458
+ pressKey(key: string | string[]): Promise<void>;
2459
+ /**
2460
+ * Resizes the browser viewport.
2461
+ *
2462
+ * ```js
2463
+ * I.resizeWindow(1024, 768);
2464
+ * ```
2465
+ * @param width - window width, or `'maximize'`.
2466
+ * @param [height] - window height.
2467
+ */
2468
+ resizeWindow(width: number | 'maximize', height?: number): Promise<void>;
2469
+ /**
2470
+ * Performs a double-click on an element matched by locator.
2471
+ *
2472
+ * ```js
2473
+ * I.doubleClick('Edit');
2474
+ * ```
2475
+ * @param locator - clickable element located by text, or any element located by CSS|XPath|strict locator.
2476
+ * @param [context = null] - (optional, `null` by default, currently ignored by this helper).
2477
+ */
2478
+ doubleClick(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
2479
+ /**
2480
+ * Performs a right-click on an element matched by locator.
2481
+ *
2482
+ * ```js
2483
+ * I.rightClick('Menu');
2484
+ * ```
2485
+ * @param locator - clickable element located by text, or any element located by CSS|XPath|strict locator.
2486
+ * @param [context = null] - (optional, `null` by default, currently ignored by this helper).
2487
+ */
2488
+ rightClick(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): Promise<void>;
2489
+ /**
2490
+ * Clicks at global page coordinates, or at coordinates relative to an element.
2491
+ * Dispatches a real CDP mouse click and therefore requires a real layout engine.
2492
+ *
2493
+ * ```js
2494
+ * I.clickXY(100, 200); // global coordinates
2495
+ * I.clickXY('#area', 50, 30); // relative to #area
2496
+ * ```
2497
+ * @param locator - element to click relative to, or a global X coordinate.
2498
+ * @param [x] - X coordinate relative to element, or global Y coordinate if `locator` is a number.
2499
+ * @param [y] - Y coordinate relative to element.
2500
+ */
2501
+ clickXY(locator: CodeceptJS.LocatorOrString | number, x?: number, y?: number): Promise<void>;
2502
+ /**
2503
+ * Waits for an element to become visible (by default waits for `options.waitForTimeout` seconds).
2504
+ *
2505
+ * ```js
2506
+ * I.waitForVisible('#popup', 5);
2507
+ * ```
2508
+ * @param locator - element located by CSS|XPath|strict locator.
2509
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2510
+ */
2511
+ waitForVisible(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<void>;
2512
+ /**
2513
+ * Waits for an element to become invisible (by default waits for `options.waitForTimeout` seconds).
2514
+ *
2515
+ * ```js
2516
+ * I.waitForInvisible('#popup', 5);
2517
+ * ```
2518
+ * @param locator - element located by CSS|XPath|strict locator.
2519
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2520
+ */
2521
+ waitForInvisible(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<void>;
2522
+ /**
2523
+ * Waits for an element to be hidden. Alias of `waitForInvisible`.
2524
+ * @param locator - element located by CSS|XPath|strict locator.
2525
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2526
+ */
2527
+ waitToHide(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<void>;
2528
+ /**
2529
+ * Waits for an element to be removed from the DOM (by default waits for `options.waitForTimeout` seconds).
2530
+ *
2531
+ * ```js
2532
+ * I.waitForDetached('#popup', 5);
2533
+ * ```
2534
+ * @param locator - element located by CSS|XPath|strict locator.
2535
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2536
+ */
2537
+ waitForDetached(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<void>;
2538
+ /**
2539
+ * Checks that a cookie with the given name is set.
2540
+ * @param name - cookie name.
2541
+ */
2542
+ seeCookie(name: string): Promise<void>;
2543
+ /**
2544
+ * Checks that a cookie with the given name is not set.
2545
+ * @param name - cookie name.
2546
+ */
2547
+ dontSeeCookie(name: string): Promise<void>;
2548
+ /**
2549
+ * Waits for a cookie with the given name to be set (by default waits for `options.waitForTimeout` seconds).
2550
+ *
2551
+ * ```js
2552
+ * I.waitForCookie('auth', 5);
2553
+ * ```
2554
+ * @param name - cookie name.
2555
+ * @param [sec = null] - (optional, `options.waitForTimeout` by default) time in seconds to wait
2556
+ */
2557
+ waitForCookie(name: string, sec?: number): Promise<void>;
2558
+ /**
2559
+ * Retrieves the inner HTML from an element located by CSS or XPath.
2560
+ * If more than one element is found - HTML of first element is returned.
2561
+ *
2562
+ * ```js
2563
+ * let postHTML = await I.grabHTMLFrom('#post');
2564
+ * ```
2565
+ * @param locator - element located by CSS|XPath|strict locator.
2566
+ * @returns HTML code for an element
2567
+ */
2568
+ grabHTMLFrom(locator: CodeceptJS.LocatorOrString): Promise<string>;
2569
+ /**
2570
+ * Retrieves the inner HTML from elements located by CSS or XPath.
2571
+ *
2572
+ * ```js
2573
+ * let postHTMLs = await I.grabHTMLFromAll('.post');
2574
+ * ```
2575
+ * @param locator - element located by CSS|XPath|strict locator.
2576
+ * @returns HTML code for matched elements
2577
+ */
2578
+ grabHTMLFromAll(locator: CodeceptJS.LocatorOrString): Promise<string[]>;
2579
+ /**
2580
+ * Executes an asynchronous script (callback-style, in the same way `window.setTimeout` works)
2581
+ * in the browser context and returns the value passed to `done`.
2582
+ *
2583
+ * ```js
2584
+ * const val = await I.executeAsyncScript(function(val, done) {
2585
+ * setTimeout(() => done(val + 1), 100)
2586
+ * }, 5)
2587
+ * ```
2588
+ * @param fn - an asynchronous function to be executed in the browser context; its last argument is a `done` callback.
2589
+ * @param args - arguments to pass into the function (before `done`).
2590
+ * @returns the value passed to `done`.
2591
+ */
2592
+ executeAsyncScript(fn: (...params: any[]) => any, ...args: any[]): Promise<any>;
2593
+ /**
2594
+ * Starts recording network traffic via CDP's `Network.requestWillBeSent`/`responseReceived`
2595
+ * events, in the same shape (`{url, method, requestHeaders, requestPostData, response}` per
2596
+ * request, `response` a promise of `{url(), status(), statusText(), body()}`) the shared
2597
+ * `lib/helper/network` actions expect from Puppeteer/Playwright. The CDP listeners are
2598
+ * installed once (lazily) and left in place afterwards, since `CDPConnection` has no listener
2599
+ * removal and `this.cdp` is reused across tests; they filter by `this.sessionId`, so only the
2600
+ * currently active test/page's requests are recorded.
2601
+ *
2602
+ * ```js
2603
+ * I.startRecordingTraffic();
2604
+ * ```
2605
+ */
2606
+ startRecordingTraffic(): Promise<void>;
2607
+ /**
2608
+ * `Network.requestWillBeSent` handler, pushed into `this.requests` when it belongs to the
2609
+ * currently active session and recording is on.
2610
+ */
2611
+ protected _onTrafficRequest(): void;
2612
+ /**
2613
+ * `Network.responseReceived` handler, resolving the matching pending `response` promise pushed
2614
+ * by `_onTrafficRequest` with a Puppeteer-`HTTPResponse`-like object.
2615
+ */
2616
+ protected _onTrafficResponse(): void;
2617
+ /**
2618
+ * `Network.loadingFailed` handler, resolving a still-pending `response` promise to `null`
2619
+ * (matching Puppeteer's `request.response()` for a failed request) so `grabRecordedNetworkTraffics`
2620
+ * never awaits a promise that would otherwise never settle.
2621
+ */
2622
+ protected _onTrafficLoadingFailed(): void;
2623
+ /**
2624
+ * Grab the recording network traffics
2625
+ *
2626
+ * ```js
2627
+ * const traffics = await I.grabRecordedNetworkTraffics();
2628
+ * expect(traffics[0].url).to.equal('https://reqres.in/api/comments/1');
2629
+ * expect(traffics[0].response.status).to.equal(200);
2630
+ * expect(traffics[0].response.body).to.contain({ name: 'this was mocked' });
2631
+ * ```
2632
+ * @returns recorded network traffics
2633
+ */
2634
+ grabRecordedNetworkTraffics(): any[];
2635
+ /**
2636
+ * Verifies that a certain request is part of network traffic.
2637
+ *
2638
+ * ```js
2639
+ * // checking the request url contains certain query strings
2640
+ * I.amOnPage('https://openai.com/blog/chatgpt');
2641
+ * I.startRecordingTraffic();
2642
+ * await I.seeTraffic({
2643
+ * name: 'sentry event',
2644
+ * url: 'https://images.openai.com/blob/cf717bdb-0c8c-428a-b82b-3c3add87a600',
2645
+ * parameters: {
2646
+ * width: '1919',
2647
+ * height: '1138',
2648
+ * },
2649
+ * });
2650
+ * ```
2651
+ *
2652
+ * ```js
2653
+ * // checking the request url contains certain post data
2654
+ * I.amOnPage('https://openai.com/blog/chatgpt');
2655
+ * I.startRecordingTraffic();
2656
+ * await I.seeTraffic({
2657
+ * name: 'event',
2658
+ * url: 'https://cloudflareinsights.com/cdn-cgi/rum',
2659
+ * requestPostData: {
2660
+ * st: 2,
2661
+ * },
2662
+ * });
2663
+ * ```
2664
+ * @param opts - options when checking the traffic network.
2665
+ * @param opts.name - A name of that request. Can be any value. Only relevant to have a more meaningful error message in case of fail.
2666
+ * @param opts.url - Expected URL of request in network traffic
2667
+ * @param [opts.parameters] - Expected parameters of that request in network traffic
2668
+ * @param [opts.requestPostData] - Expected that request contains post data in network traffic
2669
+ * @param [opts.timeout] - Timeout to wait for request in seconds. Default is 10 seconds.
2670
+ * @returns automatically synchronized promise through #recorder
2671
+ */
2672
+ seeTraffic(opts: {
2673
+ name: string;
2674
+ url: string;
2675
+ parameters?: any;
2676
+ requestPostData?: any;
2677
+ timeout?: number;
2678
+ }): void;
2679
+ /**
2680
+ * Verifies that a certain request is not part of network traffic.
2681
+ *
2682
+ * Examples:
2683
+ *
2684
+ * ```js
2685
+ * I.dontSeeTraffic({ name: 'Unexpected API Call', url: 'https://api.example.com' });
2686
+ * I.dontSeeTraffic({ name: 'Unexpected API Call of "user" endpoint', url: /api.example.com.*user/ });
2687
+ * ```
2688
+ * @param opts - options when checking the traffic network.
2689
+ * @param opts.name - A name of that request. Can be any value. Only relevant to have a more meaningful error message in case of fail.
2690
+ * @param opts.url - Expected URL of request in network traffic. Can be a string or a regular expression.
2691
+ * @returns automatically synchronized promise through #recorder
2692
+ */
2693
+ dontSeeTraffic(opts: {
2694
+ name: string;
2695
+ url: string | RegExp;
2696
+ }): void;
2697
+ /**
2698
+ * Stops recording network traffic started by `startRecordingTraffic`. Already-recorded requests
2699
+ * in `this.requests` are kept; only new requests stop being appended.
2700
+ *
2701
+ * ```js
2702
+ * I.stopRecordingTraffic();
2703
+ * ```
2704
+ */
2705
+ stopRecordingTraffic(): void;
2706
+ /**
2707
+ * Resets all recorded network requests.
2708
+ *
2709
+ * ```js
2710
+ * I.flushNetworkTraffics();
2711
+ * ```
2712
+ */
2713
+ flushNetworkTraffics(): void;
2714
+ /**
2715
+ * Starts recording a CDP `Page.startScreencast` session for the current test's target: frames
2716
+ * arrive as `Page.screencastFrame` events, are acknowledged immediately (`Page.screencastFrameAck`,
2717
+ * required or the browser stops sending more), and buffered in `this._screencastFrames`. The
2718
+ * underlying `Page.screencastFrame` listener is installed once (lazily) and left in place, like
2719
+ * `startRecordingTraffic`'s listeners, since `CDPConnection` has no listener-removal API; it
2720
+ * filters by `this.sessionId` so only the currently active test's frames are buffered. Call
2721
+ * `stopScreencast` to end the capture and assemble the buffered frames into an APNG.
2722
+ *
2723
+ * ```js
2724
+ * I.startScreencast();
2725
+ * ```
2726
+ * @param [options] - {maxWidth: number, maxHeight: number, quality: number, everyNthFrame: number} — CDP `Page.startScreencast` pass-throughs. `format` is always `'png'`.
2727
+ */
2728
+ startScreencast(options?: any): Promise<void>;
2729
+ /**
2730
+ * `Page.screencastFrame` handler: ignores frames from a session other than the currently active
2731
+ * one (stale frames from a previous test, since the listener is never removed), acknowledges the
2732
+ * frame so the browser keeps sending more, and buffers `{data, timestamp}` for `stopScreencast`
2733
+ * to assemble.
2734
+ */
2735
+ protected _onScreencastFrame(): void;
2736
+ /**
2737
+ * Stops the screencast started by `startScreencast` and assembles the buffered frames into a
2738
+ * single APNG (Animated PNG) file, returned as a Buffer. Frame delays are derived from the CDP
2739
+ * frame metadata's `timestamp` deltas (frame arrival is activity-driven — Obscura and Chrome both
2740
+ * only emit a frame on damage — so this reproduces the actual pacing of what happened, not a
2741
+ * fixed frame rate); the last frame is held for `options.lastFrameDelayMs` (default 1000ms) since
2742
+ * it has no "next" frame to derive a delay from. Every frame is checked for the PNG signature
2743
+ * before assembly — CDP's `format: 'png'` is honored by both Chrome and Obscura (verified
2744
+ * directly), but if some other engine ever sends a different format regardless, this reports it
2745
+ * via `debugSection` and returns `null` instead of muxing a broken file. Returns `null` if no
2746
+ * frames were captured (screencast never started, or stopped immediately after starting).
2747
+ *
2748
+ * ```js
2749
+ * const apngBuffer = await I.stopScreencast();
2750
+ * ```
2751
+ * @param [options] - {lastFrameDelayMs: number} — hold time in milliseconds for the final frame (default 1000).
2752
+ * @returns a Buffer with the assembled APNG, or null if there was nothing to assemble.
2753
+ */
2754
+ stopScreencast(options?: any): Promise<object>;
2755
+ }
1189
2756
  /**
1190
2757
  * Helper for testing filesystem.
1191
2758
  * Can be easily used to check file structures:
@@ -1761,6 +3328,279 @@ declare namespace CodeceptJS {
1761
3328
  */
1762
3329
  seeResponseMatchesJsonSchema(fnOrSchema: any): void;
1763
3330
  }
3331
+ /**
3332
+ * ## Configuration
3333
+ *
3334
+ * This helper should be configured in codecept.conf.js. It accepts everything `CDPBrowser`
3335
+ * accepts (see its config table), plus:
3336
+ * @property [url = http://localhost] - base URL for tests
3337
+ * @property [accountId] - Cloudflare account ID; defaults to CF_ACCOUNT_ID env var
3338
+ * @property [apiToken] - Cloudflare API token; defaults to CF_API_TOKEN env var
3339
+ * @property [keepAlive = 240000] - session keep-alive time in milliseconds
3340
+ * @property [apiBase = https://api.cloudflare.com/client/v4] - Cloudflare API base URL
3341
+ * @property [input = cdp] - input method for user actions; defaults to 'cdp' for Kitesurf's real layout engine, but can be overridden
3342
+ * @property [capabilities] - pre-configured capabilities; Kitesurf uses { layout: 'real', screenshot: true }
3343
+ */
3344
+ type KitesurfConfig = {
3345
+ url?: string;
3346
+ accountId?: string;
3347
+ apiToken?: string;
3348
+ keepAlive?: number;
3349
+ apiBase?: string;
3350
+ input?: string;
3351
+ capabilities?: any;
3352
+ };
3353
+ /**
3354
+ * Kitesurf is a cloud browser helper that extends CDPBrowser to run tests against
3355
+ * Cloudflare's Browser Run service (Kitesurf browser). It automates real browser
3356
+ * sessions in Cloudflare's cloud infrastructure, eliminating the need to manage
3357
+ * local browser instances.
3358
+ *
3359
+ * **Status:** Beta
3360
+ *
3361
+ * ## Requirements
3362
+ *
3363
+ * - Cloudflare account with Browser Run enabled
3364
+ * - API token with **Browser Rendering Edit** permission
3365
+ *
3366
+ * ## Setup
3367
+ *
3368
+ * To create an API token with Browser Rendering Edit permission:
3369
+ * 1. Log in to your Cloudflare dashboard
3370
+ * 2. Go to My Profile > API Tokens
3371
+ * 3. Click "Create Token"
3372
+ * 4. Use the "Custom token" template
3373
+ * 5. Under "Permissions", select "Browser Rendering" > "Edit"
3374
+ * 6. Set the account scope to your target account
3375
+ * 7. Copy the token and set it as `CF_API_TOKEN` environment variable
3376
+ *
3377
+ * For more details, see:
3378
+ * - [Cloudflare Browser Run Developers Docs](https://developers.cloudflare.com/browser-run/)
3379
+ * - [Cloudflare Blog - Kitesurf Announcement](https://blog.cloudflare.com/kitesurf/)
3380
+ *
3381
+ * ## Example
3382
+ *
3383
+ * ```js
3384
+ * // codecept.conf.js
3385
+ * {
3386
+ * helpers: {
3387
+ * Kitesurf: {
3388
+ * url: 'https://example.com',
3389
+ * accountId: process.env.CF_ACCOUNT_ID,
3390
+ * apiToken: process.env.CF_API_TOKEN,
3391
+ * }
3392
+ * }
3393
+ * }
3394
+ * ```
3395
+ *
3396
+ * Or set environment variables and rely on defaults:
3397
+ *
3398
+ * ```bash
3399
+ * export CF_ACCOUNT_ID="your-account-id"
3400
+ * export CF_API_TOKEN="your-api-token"
3401
+ * ```
3402
+ *
3403
+ * <!-- configuration -->
3404
+ *
3405
+ * ## Methods
3406
+ */
3407
+ class Kitesurf {
3408
+ constructor(config: KitesurfConfig);
3409
+ /**
3410
+ * Acquires a Kitesurf browser session from the Cloudflare Browser Run API and resolves it to
3411
+ * the `wss://` debugger URL `CDPConnection` connects to. Overrides `CDPBrowser._resolveEndpoint`,
3412
+ * which resolves a fixed local endpoint instead of provisioning a cloud session per test.
3413
+ * @returns a `wss://` debugger URL ready to be passed to `CDPConnection`.
3414
+ */
3415
+ protected _resolveEndpoint(): Promise<string>;
3416
+ /**
3417
+ * Closes the target as `CDPBrowser._finishTest` does, then releases the cloud session acquired
3418
+ * in `_resolveEndpoint` via the Cloudflare API so it does not linger for the full `keepAlive`
3419
+ * window. The release runs in a `finally` so a rejection while closing the CDP connection still
3420
+ * frees the cloud session instead of leaving the browser alive until `keepAlive` expires; the
3421
+ * session id is cleared before the request, so a repeated call never releases it twice.
3422
+ */
3423
+ protected _finishTest(): void;
3424
+ }
3425
+ /**
3426
+ * ## Configuration
3427
+ *
3428
+ * This helper should be configured in codecept.conf.js. It accepts everything `CDPBrowser`
3429
+ * accepts (see its config table), plus:
3430
+ * @property [endpoint] - explicit CDP endpoint. Setting this switches the helper to ATTACH
3431
+ * mode: it only connects, and never spawns or kills a process, no matter what else is configured.
3432
+ * Leave it unset for SELF-MANAGED mode (see below).
3433
+ * @property [binaryPath] - path to the `obscura` executable, used in SELF-MANAGED mode
3434
+ * (`endpoint` unset). Checked before `OBSCURA_PATH` and `PATH`.
3435
+ * @property [port] - port `obscura serve` listens on, in SELF-MANAGED mode. When unset, a
3436
+ * free port is picked automatically, which is what makes `run-workers` collision-free — every
3437
+ * worker gets its own instance on its own port with zero config.
3438
+ * @property [serverStartTimeout = 15000] - milliseconds to wait for a spawned `obscura serve`
3439
+ * to answer `/json/version` before `_connect` gives up.
3440
+ */
3441
+ type ObscuraConfig = {
3442
+ endpoint?: string;
3443
+ binaryPath?: string;
3444
+ port?: number;
3445
+ serverStartTimeout?: number;
3446
+ };
3447
+ /**
3448
+ * Obscura drives [Obscura](https://github.com/h4ckf0r0day/obscura), a minimal headless
3449
+ * browser exposed over the Chrome DevTools Protocol. From v0.2.0, default release builds ship a
3450
+ * real rendering engine (layout, paint, screenshots); `-no-render` variants and v0.1.x builds keep
3451
+ * the original single-V8-isolate, nothing-rendered mode. This helper does not hardcode which mode a
3452
+ * given binary is in — `CDPBrowser._probeCapabilities` detects `layout`/`screenshot` per binary at
3453
+ * runtime, so the same helper works against either.
3454
+ *
3455
+ * This helper is a thin `CDPBrowser` subclass: it changes nothing about how locating or acting on
3456
+ * elements works, it only pins the config presets Obscura requires and manages the `obscura serve`
3457
+ * process lifecycle, the same way Playwright manages its own browser process.
3458
+ *
3459
+ * ## Modes
3460
+ *
3461
+ * - **ATTACH** — `endpoint` is set explicitly in the config. The helper only connects to it; it
3462
+ * never spawns or kills anything, no matter what `binaryPath`/`port` are set to.
3463
+ * - **SELF-LAUNCH** — `endpoint` is unset and a binary can be resolved, in order: `binaryPath` in
3464
+ * the config, then the `OBSCURA_PATH` environment variable, then `obscura` on `PATH`. The helper
3465
+ * spawns `obscura serve --port <port> --allow-private-network` (`port` from the config, or a
3466
+ * free port picked automatically), waits for it to answer, connects, and kills it in
3467
+ * `_finishTest`.
3468
+ * - **COURTESY-ATTACH** — `endpoint` is unset and no binary can be resolved, but something already
3469
+ * answers `http://127.0.0.1:9222/json/version` (e.g. `obscura serve` started by hand, or by CI
3470
+ * before this process ever ran). The helper attaches to it and never kills it — it isn't the
3471
+ * helper's process to kill. If neither a binary nor a running server on :9222 can be found, the
3472
+ * helper throws a loud, actionable error.
3473
+ *
3474
+ * ## Install
3475
+ *
3476
+ * Download a release binary and put it on your `PATH` (or point `binaryPath`/`OBSCURA_PATH` at
3477
+ * it directly) and the helper launches and tears it down for you automatically:
3478
+ *
3479
+ * ```sh
3480
+ * curl -sL https://github.com/h4ckf0r0day/obscura/releases/download/v0.2.0/obscura-x86_64-linux.tar.gz | tar xz
3481
+ * ```
3482
+ *
3483
+ * `--allow-private-network` is always passed by this helper (it's required to reach apps running
3484
+ * on `localhost`/private IPs, e.g. a dev server on `127.0.0.1:8000` — Obscura blocks
3485
+ * private-network requests by default).
3486
+ *
3487
+ * ## Config presets
3488
+ *
3489
+ * These are set automatically and only need overriding for unusual setups:
3490
+ *
3491
+ * | option | value | why |
3492
+ * | --- | --- | --- |
3493
+ * | `input` | `synthetic` | coordinate-click navigation is unreliable over CDP on Obscura even on rendering builds (no `frameNavigated` event, stale `page.url()`); `click` always takes the `forceClick` path — on Obscura, `click` and `forceClick` are the same thing |
3494
+ * | `xpathPolyfill` | `auto` | probed per binary/page: Obscura's native `document.evaluate` still doesn't support attribute selection or `not()`, so the polyfill is used until that lands |
3495
+ *
3496
+ * `capabilities.layout`/`capabilities.screenshot`/`capabilities.xpath` are intentionally left
3497
+ * unset here — `CDPBrowser._probeCapabilities` detects them at runtime from the actual binary
3498
+ * (`'real'`/`true` on v0.2.0+ default builds, `'none'`/`false` on `-no-render` builds and v0.1.x).
3499
+ * Set them explicitly in your own config to skip probing or to force a mode.
3500
+ *
3501
+ * ## Limitations
3502
+ *
3503
+ * - `input` is always `synthetic`, even on rendering builds — see `input` above.
3504
+ * - No frames, popups, or file uploads.
3505
+ * - On `-no-render` builds and v0.1.x: no screenshots, no visibility assertions
3506
+ * (`seeElement`/`dontSeeElement` always throw) — only DOM presence
3507
+ * (`seeElementInDOM`/`dontSeeElementInDOM`) is meaningful without a layout engine.
3508
+ * - On v0.2.0+ default (rendering) builds: layout, screenshots, and CSS work, but it's a new,
3509
+ * independently implemented rendering/CSS engine — expect edge cases and gaps versus a real browser.
3510
+ * - Single V8 isolate: heavy or long-running pages, or many pages in parallel against one
3511
+ * `obscura serve` process, compete for the same isolate.
3512
+ *
3513
+ * <!-- configuration -->
3514
+ *
3515
+ * ## Example
3516
+ *
3517
+ * ```js
3518
+ * // inside codecept.conf.js — SELF-LAUNCH mode (recommended): the helper finds/starts/stops
3519
+ * // obscura serve on its own, on a free port. Ideal for run-workers: every worker gets its own
3520
+ * // instance with no config.
3521
+ * {
3522
+ * helpers: {
3523
+ * Obscura: {
3524
+ * url: 'http://localhost',
3525
+ * }
3526
+ * }
3527
+ * }
3528
+ * ```
3529
+ *
3530
+ * ```js
3531
+ * // ATTACH mode — connect to an Obscura instance you manage yourself (remote host, container, etc.)
3532
+ * {
3533
+ * helpers: {
3534
+ * Obscura: {
3535
+ * url: 'http://localhost',
3536
+ * endpoint: 'http://127.0.0.1:9222',
3537
+ * }
3538
+ * }
3539
+ * }
3540
+ * ```
3541
+ *
3542
+ * ## Methods
3543
+ */
3544
+ class Obscura {
3545
+ constructor(config: ObscuraConfig);
3546
+ /**
3547
+ * In ATTACH mode, connects exactly as `CDPBrowser._connect` would. In SELF-MANAGED mode,
3548
+ * resolves and spawns `obscura serve` (or courtesy-attaches to an already-running one on
3549
+ * :9222) exactly once via `_resolveSelfManaged`, then connects.
3550
+ *
3551
+ * A spawn failure (e.g. a bad binary) is delivered asynchronously by Node as an `error`
3552
+ * event; it is recorded on `this.serverError` and surfaced as a rejection from `_waitForServer`
3553
+ * instead of crashing the process as an uncaught exception.
3554
+ */
3555
+ protected _connect(): void;
3556
+ /**
3557
+ * Resolves how to reach Obscura when no explicit `endpoint` was configured, trying, in order:
3558
+ * spawn a binary (`binaryPath` config, then `OBSCURA_PATH` env, then `obscura` on `PATH`),
3559
+ * courtesy-attach to `http://127.0.0.1:9222` if something already answers there, or throw a
3560
+ * loud, actionable error. Sets `this.options.endpoint` as a side effect.
3561
+ */
3562
+ protected _resolveSelfManaged(): void;
3563
+ /**
3564
+ * Resolves the `obscura` binary to spawn, in priority order: `options.binaryPath`, then the
3565
+ * `OBSCURA_PATH` environment variable, then `obscura` on `PATH`. The `PATH` lookup walks the
3566
+ * directories itself instead of shelling out to `which`, which does not exist on Windows: on
3567
+ * Windows every `PATHEXT` suffix is tried, so an `obscura.exe` on `PATH` is found too.
3568
+ * @returns an absolute or relative path to the binary, or null if none resolved.
3569
+ */
3570
+ protected _resolveBinary(): string | null;
3571
+ /**
3572
+ * Picks a free TCP port on 127.0.0.1 by briefly listening on port 0 and reading back the OS-assigned
3573
+ * port. Used as the SELF-LAUNCH default when `options.port` isn't explicitly set, so multiple
3574
+ * `run-workers` workers never collide on the same port.
3575
+ * @returns a free port.
3576
+ */
3577
+ protected _findFreePort(): Promise<number>;
3578
+ /**
3579
+ * Probes a `/json/version`-style URL with a short timeout, used for the COURTESY-ATTACH check.
3580
+ * @returns true if the URL answered.
3581
+ */
3582
+ protected _probeUp(url: string): Promise<boolean>;
3583
+ /**
3584
+ * Polls `http://127.0.0.1:<port>/json/version` until `obscura serve` responds, `this.serverError`
3585
+ * is set by the spawned process' `error` event, or `options.serverStartTimeout` elapses. The
3586
+ * process typically comes up within tens of milliseconds — a 20ms retry interval (down from a
3587
+ * previous 200ms) keeps the wasted tail after the server is actually ready small, since this cost
3588
+ * is paid once per run and counts directly toward real-world startup latency.
3589
+ */
3590
+ protected _waitForServer(): void;
3591
+ /**
3592
+ * Closes the CDP connection (via `CDPBrowser._finishTest`), then kills the `obscura serve`
3593
+ * process spawned by `_connect`, if any (never runs in ATTACH or COURTESY-ATTACH mode, since
3594
+ * `this.serverProcess` is only ever set in SELF-LAUNCH mode). Runs in a `finally` so the process
3595
+ * is always reaped even if closing the CDP connection throws. Sends `SIGTERM` first and waits for
3596
+ * the process to exit; a process that ignores `SIGTERM` is escalated to `SIGKILL` after 5s. The
3597
+ * promise only resolves once the child has actually exited (confirmed via the `exit` event, not
3598
+ * merely once `SIGKILL` was sent — the kernel needs a moment to reap it), with a final safety-net
3599
+ * timeout so a stuck child can never keep the event loop alive even if that confirmation is
3600
+ * somehow lost.
3601
+ */
3602
+ protected _finishTest(): void;
3603
+ }
1764
3604
  /**
1765
3605
  * ## Configuration
1766
3606
  *