codeceptjs 4.2.1 → 4.2.3

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 (74) hide show
  1. package/README.md +5 -3
  2. package/docs/ai.md +1 -1
  3. package/docs/alternative-browsers.md +59 -4
  4. package/docs/api.md +13 -13
  5. package/docs/assertions.md +6 -6
  6. package/docs/best.md +1 -1
  7. package/docs/bootstrap.md +1 -1
  8. package/docs/data.md +8 -8
  9. package/docs/helpers/ApiDataFactory.md +2 -2
  10. package/docs/helpers/Appium.md +2 -2
  11. package/docs/helpers/Decision.md +1 -1
  12. package/docs/helpers/Detox.md +1 -1
  13. package/docs/helpers/ExpectHelper.md +1 -1
  14. package/docs/helpers/FileSystem.md +1 -1
  15. package/docs/helpers/GraphQL.md +1 -1
  16. package/docs/helpers/GraphQLDataFactory.md +2 -2
  17. package/docs/helpers/JSONResponse.md +1 -1
  18. package/docs/helpers/Kitesurf.md +1 -1
  19. package/docs/helpers/Lightpanda.md +1837 -9
  20. package/docs/helpers/MockRequest.md +1 -1
  21. package/docs/helpers/Moli.md +1956 -0
  22. package/docs/helpers/Obscura.md +1 -1
  23. package/docs/helpers/Playwright.md +2 -2
  24. package/docs/helpers/Puppeteer.md +3 -3
  25. package/docs/helpers/REST.md +1 -1
  26. package/docs/helpers/WebDriver.md +1 -1
  27. package/docs/installation.md +19 -1
  28. package/docs/lint.md +111 -0
  29. package/docs/mobile.md +3 -2
  30. package/docs/mobilewright.md +166 -0
  31. package/docs/parallel.md +1 -1
  32. package/docs/playwright.md +5 -5
  33. package/docs/plugins/aiTrace.md +1 -1
  34. package/docs/plugins/autoDelay.md +1 -1
  35. package/docs/plugins/customLocator.md +1 -1
  36. package/docs/plugins/customReporter.md +1 -1
  37. package/docs/plugins/junitReporter.md +2 -2
  38. package/docs/plugins/pageInfo.md +1 -1
  39. package/docs/plugins/pauseOnFail.md +1 -1
  40. package/docs/plugins/retryFailedStep.md +1 -1
  41. package/docs/plugins/screenshotOnFail.md +1 -1
  42. package/docs/plugins/stepTimeout.md +1 -1
  43. package/docs/plugins.md +10 -10
  44. package/docs/puppeteer.md +4 -4
  45. package/docs/timeouts.md +5 -5
  46. package/docs/webdriver.md +8 -8
  47. package/lib/aria.js +1 -0
  48. package/lib/codecept.js +1 -1
  49. package/lib/command/run-multiple.js +7 -2
  50. package/lib/container.js +1 -1
  51. package/lib/helper/ApiDataFactory.js +1 -1
  52. package/lib/helper/Appium.js +1 -1
  53. package/lib/helper/Decision.js +1 -1
  54. package/lib/helper/GraphQLDataFactory.js +1 -1
  55. package/lib/helper/Moli.js +125 -0
  56. package/lib/helper/Playwright.js +1 -1
  57. package/lib/helper/Puppeteer.js +3 -3
  58. package/lib/helper/WebDriver.js +3 -6
  59. package/lib/mocha/asyncWrapper.js +14 -3
  60. package/lib/mocha/cli.js +2 -2
  61. package/lib/mocha/index.js +1 -2
  62. package/lib/mocha/suite.js +1 -1
  63. package/lib/mocha/test.js +2 -2
  64. package/lib/mocha/ui.js +3 -3
  65. package/lib/plugin/auth.js +3 -0
  66. package/lib/plugin/junitReporter.js +21 -12
  67. package/lib/plugin/pause.js +1 -1
  68. package/lib/recorder.js +20 -2
  69. package/lib/step/func.js +1 -1
  70. package/lib/step/helper.js +1 -1
  71. package/lib/workers.js +15 -0
  72. package/package.json +31 -34
  73. package/typings/promiseBasedTypes.d.ts +112 -6
  74. package/typings/types.d.ts +112 -6
package/docs/timeouts.md CHANGED
@@ -85,11 +85,11 @@ Each helper (Playwright, Puppeteer, WebDriver, Appium, REST) has its own timeout
85
85
 
86
86
  Refer to helper-specific documentation for timeout configuration:
87
87
 
88
- - [Playwright Helper](/helpers/Playwright) — `timeout`, `waitForTimeout`, `getPageTimeout`
89
- - [Puppeteer Helper](/helpers/Puppeteer) — `waitForTimeout`, `getPageTimeout`
90
- - [WebDriver Helper](/helpers/WebDriver) — `waitForTimeout`, `smartWait`, `timeouts` object
91
- - [Appium Helper](/helpers/Appium) — `timeouts` object
92
- - [REST Helper](/helpers/REST) — `timeout`
88
+ - [Playwright Helper](/helpers/playwright) — `timeout`, `waitForTimeout`, `getPageTimeout`
89
+ - [Puppeteer Helper](/helpers/puppeteer) — `waitForTimeout`, `getPageTimeout`
90
+ - [WebDriver Helper](/helpers/web-driver) — `waitForTimeout`, `smartWait`, `timeouts` object
91
+ - [Appium Helper](/helpers/appium) — `timeouts` object
92
+ - [REST Helper](/helpers/rest) — `timeout`
93
93
 
94
94
  ## stepTimeout Plugin
95
95
 
package/docs/webdriver.md CHANGED
@@ -91,7 +91,7 @@ keepBrowserState: true,
91
91
  keepCookies: true,
92
92
  ```
93
93
 
94
- > ▶ More config options available on [WebDriver helper reference](/helpers/WebDriver#configuration)
94
+ > ▶ More config options available on [WebDriver helper reference](/helpers/web-driver#configuration)
95
95
 
96
96
  ### Headless Mode
97
97
 
@@ -138,7 +138,7 @@ desiredCapabilities: {
138
138
 
139
139
  ### Cloud Providers
140
140
 
141
- By default, WebdriverIO starts a local driver automatically, so no connection parameters are needed. To run tests via [Cloud Providers](/helpers/WebDriver#cloud-providers) instead, specify `host`, `port`, `protocol`, and `path` parameters pointing to the service. You may also need `user` and `key` parameters to authenticate on the cloud service.
141
+ By default, WebdriverIO starts a local driver automatically, so no connection parameters are needed. To run tests via [Cloud Providers](/helpers/web-driver#cloud-providers) instead, specify `host`, `port`, `protocol`, and `path` parameters pointing to the service. You may also need `user` and `key` parameters to authenticate on the cloud service.
142
142
 
143
143
  There are also [browser and platform specific capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Services like SauceLabs, BrowserStack or browser vendors can provide their own specific capabilities for more tuning.
144
144
 
@@ -208,7 +208,7 @@ Tests consist with a scenario of user's action taken on a page. The most widely
208
208
  * `see`, `dontSee` - to check for a text on a page
209
209
  * `seeElement`, `dontSeeElement` - to check for elements on a page
210
210
 
211
- > ℹ All actions are listed in [WebDriver helper reference](https://codecept.io/helpers/WebDriver/).*
211
+ > ℹ All actions are listed in [WebDriver helper reference](https://codecept.io/helpers/web-driver/).*
212
212
 
213
213
  All actions which interact with elements **support CSS and XPath locators**. Actions like `click` or `fillField` by locate elements by their name or value on a page:
214
214
 
@@ -252,7 +252,7 @@ npx codeceptjs run --steps
252
252
 
253
253
  After a page is opened a full control of a browser is given to a terminal. Type in different commands such as `click`, `see`, `fillField` to write the test. A successful commands will be saved to `./output/cli-history` file and can be copied into a test.
254
254
 
255
- > ℹ All actions are listed in [WebDriver helper reference](/helpers/WebDriver).
255
+ > ℹ All actions are listed in [WebDriver helper reference](/helpers/web-driver).
256
256
 
257
257
  An interactive shell output may look like this:
258
258
 
@@ -420,7 +420,7 @@ There are following options available:
420
420
 
421
421
  * Use headless Chrome or Firefox.
422
422
  * Use [Selenoid](/plugins/selenoid) to run browsers inside Docker containers.
423
- * Use paid [cloud services (SauceLabs, BrowserStack, TestingBot)](/helpers/WebDriver#cloud-providers).
423
+ * Use paid [cloud services (SauceLabs, BrowserStack, TestingBot)](/helpers/web-driver#cloud-providers).
424
424
 
425
425
  ## Video Recording
426
426
 
@@ -494,7 +494,7 @@ This is useful when you want to isolate application testing from a backend. For
494
494
 
495
495
  > **WebDriver has limited ability to mock requests**, so you can only mock only requests performed after page is loaded. This means that you can't block Google Analytics, or CDN calls, but you can mock API requests performed on user action.
496
496
 
497
- To mock requests enable additional helper [MockRequest](/helpers/MockRequest) (which is based on Polly.js).
497
+ To mock requests enable additional helper [MockRequest](/helpers/mock-request) (which is based on Polly.js).
498
498
 
499
499
  ```js
500
500
  helpers: {
@@ -529,7 +529,7 @@ I.click('Go to Next Page');
529
529
  // in WebDriver as we can't detect that the page was reloaded, so no mocking :(
530
530
  ```
531
531
 
532
- > See [`mockRequest` API](/helpers/MockRequest#mockrequest)
532
+ > See [`mockRequest` API](/helpers/mock-request#mockrequest)
533
533
 
534
534
  To see `mockRequest` method in intellisense auto completion don't forget to run `codeceptjs def` command:
535
535
 
@@ -542,7 +542,7 @@ Mocking rules will be kept while a test is running. To stop mocking use `I.stopM
542
542
 
543
543
  ## Accessing webdriverio API
544
544
 
545
- To get [webdriverio browser API](https://webdriver.io/docs/api.html) inside a test use [`I.useWebDriverTo`](/helpers/WebDriver/#usewebdriverto) method with a callback.
545
+ To get [webdriverio browser API](https://webdriver.io/docs/api.html) inside a test use [`I.useWebDriverTo`](/helpers/web-driver/#usewebdriverto) method with a callback.
546
546
  To keep test readable provide a description of a callback inside the first parameter.
547
547
 
548
548
  ```js
package/lib/aria.js CHANGED
@@ -121,6 +121,7 @@ function dropEmpty(nodes) {
121
121
  const children = dropEmpty(node.children)
122
122
  if (INTERACTIVE_ROLES.has(node.role)) return [{ ...node, children }]
123
123
  if (children.length > 0) return [{ ...node, children }]
124
+ if (node.value !== undefined && node.value !== null && String(node.value).trim()) return [{ ...node, children }]
124
125
  return []
125
126
  })
126
127
  }
package/lib/codecept.js CHANGED
@@ -279,7 +279,7 @@ class Codecept {
279
279
  */
280
280
  filterLastFailedTests(mocha) {
281
281
  if (!this.opts.lastFailed) return
282
- const failedTestUids = new Set(Result.loadFailedTests().map(test => test.uid))
282
+ const failedTestUids = new Set(Result.loadFailedTests().map(test => test.uid?.split('@')[0]))
283
283
  const filterSuite = suite => {
284
284
  suite.tests = suite.tests.filter(test => failedTestUids.has(test.uid))
285
285
  suite.suites.forEach(filterSuite)
@@ -75,10 +75,10 @@ export default async function (selectedRuns, options) {
75
75
  if (options.config) {
76
76
  // update paths to config path
77
77
  if (config.tests) {
78
- config.tests = path.resolve(testRoot, config.tests)
78
+ config.tests = resolvePatterns(testRoot, config.tests)
79
79
  }
80
80
  if (config.gherkin && config.gherkin.features) {
81
- config.gherkin.features = path.resolve(testRoot, config.gherkin.features)
81
+ config.gherkin.features = resolvePatterns(testRoot, config.gherkin.features)
82
82
  }
83
83
  }
84
84
 
@@ -117,6 +117,11 @@ export default async function (selectedRuns, options) {
117
117
  })
118
118
  }
119
119
 
120
+ export function resolvePatterns(testRoot, patterns) {
121
+ const resolve = pattern => path.resolve(testRoot, pattern).split(path.sep).join(path.posix.sep)
122
+ return Array.isArray(patterns) ? patterns.map(resolve) : resolve(patterns)
123
+ }
124
+
120
125
  function executeRun(runName, runConfig) {
121
126
  // clone config
122
127
  let overriddenConfig = { ...config }
package/lib/container.js CHANGED
@@ -61,7 +61,7 @@ class Container {
61
61
  *
62
62
  */
63
63
  static get STANDARD_ACTING_HELPERS() {
64
- return ['Playwright', 'WebDriver', 'Puppeteer', 'Appium', 'Obscura', 'Lightpanda']
64
+ return ['Playwright', 'WebDriver', 'Puppeteer', 'Appium', 'Obscura', 'Lightpanda', 'Moli']
65
65
  }
66
66
  /**
67
67
  * Create container with all required helpers and support objects
@@ -99,7 +99,7 @@ import { resolveImportModulePath } from '../utils.js'
99
99
  * It is required to set REST API `endpoint` which is the baseURL for all API requests.
100
100
  * Factory file is expected to be passed via `factory` option.
101
101
  *
102
- * This Helper uses [REST](http://codecept.io/helpers/REST/) helper and accepts its configuration in "REST" section.
102
+ * This Helper uses [REST](http://codecept.io/helpers/rest/) helper and accepts its configuration in "REST" section.
103
103
  * For instance, to set timeout you should add:
104
104
  *
105
105
  * ```js
@@ -24,7 +24,7 @@ const vendorPrefix = {
24
24
  }
25
25
 
26
26
  /**
27
- * Appium helper extends [Webdriver](http://codecept.io/helpers/WebDriver/) helper.
27
+ * Appium helper extends [Webdriver](http://codecept.io/helpers/web-driver/) helper.
28
28
  * It supports all browser methods and also includes special methods for mobile apps testing.
29
29
  * You can use this helper to test Web on desktop and mobile devices and mobile apps.
30
30
  *
@@ -244,7 +244,7 @@ class Decision extends Helper {
244
244
 
245
245
  _actingHelper() {
246
246
  const helper = pickActingHelper(Container.helpers())
247
- if (!helper) throw new Error('Decision helper requires a web helper: Playwright, Puppeteer, WebDriver, Obscura or Lightpanda')
247
+ if (!helper) throw new Error('Decision helper requires a web helper: Playwright, Puppeteer, WebDriver, Obscura, Lightpanda or Moli')
248
248
  return helper
249
249
  }
250
250
  }
@@ -100,7 +100,7 @@ import store from '../store.js'
100
100
  * It is required to set GraphQL `endpoint` which is the URL to which all the queries go to.
101
101
  * Factory file is expected to be passed via `factory` option.
102
102
  *
103
- * This Helper uses [GraphQL](http://codecept.io/helpers/GraphQL/) helper and accepts its configuration in "GraphQL" section.
103
+ * This Helper uses [GraphQL](http://codecept.io/helpers/graph-ql/) helper and accepts its configuration in "GraphQL" section.
104
104
  * For instance, to set timeout you should add:
105
105
  *
106
106
  * ```js
@@ -0,0 +1,125 @@
1
+ import CDPBrowser from './CDPBrowser.js'
2
+
3
+ /**
4
+ * ## Configuration
5
+ *
6
+ * This helper should be configured in codecept.conf.js
7
+ *
8
+ * @typedef MoliConfig
9
+ * @type {object}
10
+ * @prop {string} [endpoint] - explicit CDP endpoint. Setting this switches the helper to ATTACH
11
+ * mode: it only connects, and never spawns or kills a process, no matter what else is configured.
12
+ * Leave it unset for SELF-MANAGED mode (see below).
13
+ * @prop {string} [binaryPath] - path to the `moli` executable, used in SELF-MANAGED mode
14
+ * (`endpoint` unset). Checked before `MOLI_PATH` and `PATH`.
15
+ * @prop {number} [port] - port `moli serve` listens on, in SELF-MANAGED mode. When unset, a free
16
+ * port is picked automatically, which is what makes `run-workers` collision-free — every worker
17
+ * gets its own instance on its own port with zero config.
18
+ * @prop {number} [serverStartTimeout=15000] - milliseconds to wait for a spawned `moli serve` to
19
+ * answer `/json/version` before `_connect` gives up.
20
+ */
21
+ const config = {}
22
+
23
+ /**
24
+ * Moli drives [Moli](https://github.com/lexmount/moli), an open-source headless browser written
25
+ * in Rust for automation, exposed over the Chrome DevTools Protocol. It runs real JavaScript in V8
26
+ * and computes styles with Servo's Stylo, but by default skips layout and painting: element boxes
27
+ * use deterministic placeholder geometry, so there are no screenshots and no coordinate input.
28
+ *
29
+ * This helper is a thin `CDPBrowser` subclass: it changes nothing about how locating or acting on
30
+ * elements works, it only pins the config presets Moli requires and manages the `moli serve`
31
+ * process lifecycle, the same way Playwright manages its own browser process.
32
+ *
33
+ * > Moli support is experimental. Pin the browser version in CI and keep a
34
+ * > Playwright/WebDriver job for browser-compatibility coverage.
35
+ *
36
+ * ## Modes
37
+ *
38
+ * - **ATTACH** — `endpoint` is set explicitly in the config. The helper only connects to it; it
39
+ * never spawns or kills anything, no matter what `binaryPath`/`port` are set to.
40
+ * - **SELF-LAUNCH** — `endpoint` is unset and a binary can be resolved, in order: `binaryPath` in
41
+ * the config, then the `MOLI_PATH` environment variable, then `moli` on `PATH`. The helper
42
+ * spawns `moli serve --host 127.0.0.1 --port <port>` (`port` from the config, or a free port
43
+ * picked automatically), waits for it to answer, connects, and kills it in `_finishTest`.
44
+ * - **COURTESY-ATTACH** — `endpoint` is unset and no binary can be resolved, but something already
45
+ * answers `http://127.0.0.1:9222/json/version` (e.g. `moli serve` started by hand). The helper
46
+ * attaches to it and never kills it. If neither a binary nor a running server on :9222 can be
47
+ * found, the helper throws a loud, actionable error.
48
+ *
49
+ * ## Install
50
+ *
51
+ * Follow the [official installation instructions](https://github.com/lexmount/moli#direct-installation),
52
+ * then put `moli` on your `PATH`, or point `binaryPath`/`MOLI_PATH` at it. The helper then
53
+ * launches and tears it down automatically.
54
+ *
55
+ * ## Config presets
56
+ *
57
+ * These are set automatically and only need overriding for unusual setups:
58
+ *
59
+ * | option | value | why |
60
+ * | --- | --- | --- |
61
+ * | `input` | `synthetic` | without layout Moli rejects coordinate mouse input, so `click` always takes the `forceClick` path |
62
+ * | `xpathPolyfill` | `auto` | probed per binary/page |
63
+ * | `capabilities.layout` | `real` | Moli computes real styles and gives displayed elements a non-empty placeholder box, which is enough for `seeElement` and the `waitForVisible` family; it is pinned because the runtime probe would also enable coordinate input |
64
+ * | `capabilities.screenshot` | `false` | screenshots require `moli serve --layout`, which this helper does not use: its layout is a snapshot that goes stale when the page changes |
65
+ *
66
+ * ## Limitations
67
+ *
68
+ * - No screenshots and no screencast: `saveScreenshot` and `saveElementScreenshot` do nothing (a debug message is printed).
69
+ * - No coordinate-based input (`clickXY`).
70
+ * - No frames or popups.
71
+ * - Uploaded files are sent as `application/octet-stream` regardless of their extension.
72
+ * - The default stylesheet does not color links: `a` computes `color: rgb(0, 0, 0)`.
73
+ *
74
+ * <!-- configuration -->
75
+ *
76
+ * ## Example
77
+ *
78
+ * ```js
79
+ * // inside codecept.conf.js — SELF-LAUNCH mode (recommended): the helper finds/starts/stops
80
+ * // moli serve on its own, on a free port. Ideal for run-workers: every worker gets its own
81
+ * // instance with no config.
82
+ * {
83
+ * helpers: {
84
+ * Moli: {
85
+ * url: 'http://localhost',
86
+ * }
87
+ * }
88
+ * }
89
+ * ```
90
+ *
91
+ * ```js
92
+ * // ATTACH mode — connect to a Moli instance you manage yourself (remote host, container, etc.)
93
+ * {
94
+ * helpers: {
95
+ * Moli: {
96
+ * url: 'http://localhost',
97
+ * endpoint: 'http://127.0.0.1:9222',
98
+ * }
99
+ * }
100
+ * }
101
+ * ```
102
+ *
103
+ * ## Methods
104
+ */
105
+ class Moli extends CDPBrowser {
106
+ /**
107
+ * @param {MoliConfig} config
108
+ */
109
+ constructor(config) {
110
+ super({
111
+ input: 'synthetic',
112
+ xpathPolyfill: 'auto',
113
+ ...config,
114
+ capabilities: { layout: 'real', screenshot: false, ...((config && config.capabilities) || {}) },
115
+ })
116
+ this._manageServer(config, {
117
+ name: 'moli',
118
+ envVar: 'MOLI_PATH',
119
+ args: port => ['serve', '--host', '127.0.0.1', '--port', String(port)],
120
+ releases: 'https://github.com/lexmount/moli/releases',
121
+ })
122
+ }
123
+ }
124
+
125
+ export default Moli
@@ -2054,7 +2054,7 @@ class Playwright extends Helper {
2054
2054
  * Handles a file download. A file name is required to save the file on disk.
2055
2055
  * Files are saved to "output" directory.
2056
2056
  *
2057
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
2057
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
2058
2058
  *
2059
2059
  * ```js
2060
2060
  * I.handleDownloads('downloads/avatar.jpg');
@@ -94,7 +94,7 @@ const consoleLogStore = new Console()
94
94
  * @prop {string} [windowSize] - default window size. Set a dimension in format WIDTHxHEIGHT like `640x480`.
95
95
  * @prop {string} [userAgent] - user-agent string.
96
96
  * @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
97
- * @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/Puppeteer-firefox).
97
+ * @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/puppeteer-firefox).
98
98
  * @prop {object} [chrome] - pass additional [Puppeteer run options](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.launchoptions.md).
99
99
  * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
100
100
  */
@@ -115,7 +115,7 @@ const config = {}
115
115
  * ```
116
116
  * Using `puppeteer-core` package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
117
117
  *
118
- * > Experimental Firefox support [can be activated](https://codecept.io/helpers/Puppeteer-firefox).
118
+ * > Experimental Firefox support [can be activated](https://codecept.io/helpers/puppeteer-firefox).
119
119
  *
120
120
  * <!-- configuration -->
121
121
  *
@@ -1320,7 +1320,7 @@ class Puppeteer extends Helper {
1320
1320
 
1321
1321
  /**
1322
1322
  * Sets a directory to where save files. Allows to test file downloads.
1323
- * Should be used with [FileSystem helper](https://codecept.io/helpers/FileSystem) to check that file were downloaded correctly.
1323
+ * Should be used with [FileSystem helper](https://codecept.io/helpers/file-system) to check that file were downloaded correctly.
1324
1324
  *
1325
1325
  * By default, files are saved to `output/downloads`.
1326
1326
  * This directory is cleaned on every `handleDownloads` call, to ensure no old files are kept.
@@ -1079,7 +1079,6 @@ class WebDriver extends Helper {
1079
1079
  *
1080
1080
  */
1081
1081
  async click(locator, context = null) {
1082
- const clickMethod = this.browser.isMobile && this.browser.capabilities.platformName !== 'android' ? 'touchClick' : 'elementClick'
1083
1082
  const locateFn = prepareLocateFn.call(this, context)
1084
1083
 
1085
1084
  const res = await findClickable.call(this, locator, locateFn)
@@ -1090,7 +1089,7 @@ class WebDriver extends Helper {
1090
1089
  }
1091
1090
  const elem = selectElement(res, locator, this)
1092
1091
  highlightActiveElement.call(this, elem)
1093
- return this.browser[clickMethod](getElementId(elem))
1092
+ return this.browser.elementClick(getElementId(elem))
1094
1093
  }
1095
1094
 
1096
1095
  /**
@@ -1390,7 +1389,6 @@ class WebDriver extends Helper {
1390
1389
  * {{> checkOption }}
1391
1390
  */
1392
1391
  async checkOption(field, context = null) {
1393
- const clickMethod = this.browser.isMobile && this.browser.capabilities.platformName !== 'android' ? 'touchClick' : 'elementClick'
1394
1392
  const locateFn = prepareLocateFn.call(this, context)
1395
1393
 
1396
1394
  const res = await findCheckable.call(this, field, locateFn)
@@ -1403,7 +1401,7 @@ class WebDriver extends Helper {
1403
1401
  const isSelected = await isElementChecked(this.browser, elementId)
1404
1402
 
1405
1403
  if (isSelected) return Promise.resolve(true)
1406
- return this.browser[clickMethod](elementId)
1404
+ return this.browser.elementClick(elementId)
1407
1405
  }
1408
1406
 
1409
1407
  /**
@@ -1411,7 +1409,6 @@ class WebDriver extends Helper {
1411
1409
  * {{> uncheckOption }}
1412
1410
  */
1413
1411
  async uncheckOption(field, context = null) {
1414
- const clickMethod = this.browser.isMobile && this.browser.capabilities.platformName !== 'android' ? 'touchClick' : 'elementClick'
1415
1412
  const locateFn = prepareLocateFn.call(this, context)
1416
1413
 
1417
1414
  const res = await findCheckable.call(this, field, locateFn)
@@ -1424,7 +1421,7 @@ class WebDriver extends Helper {
1424
1421
  const isSelected = await isElementChecked(this.browser, elementId)
1425
1422
 
1426
1423
  if (!isSelected) return Promise.resolve(true)
1427
- return this.browser[clickMethod](elementId)
1424
+ return this.browser.elementClick(elementId)
1428
1425
  }
1429
1426
 
1430
1427
  /**
@@ -54,7 +54,10 @@ export function test(test) {
54
54
 
55
55
  test.fn = function (done) {
56
56
  const doneFn = makeDoneCallableOnce(done)
57
+ let recoveryStarted = false
57
58
  recorder.errHandler(err => {
59
+ if (recoveryStarted) return
60
+ recoveryStarted = true
58
61
  recorder.session.start('teardown')
59
62
  recorder.cleanAsyncErr()
60
63
  if (test.throws) {
@@ -114,7 +117,13 @@ export function test(test) {
114
117
  export function injected(fn, suite, hookName) {
115
118
  return function (done) {
116
119
  const doneFn = makeDoneCallableOnce(done)
120
+ const opts = suite.opts || {}
121
+ const retries = opts[`retry${ucfirst(hookName)}`] || 0
122
+ let retryPending = retries > 0
123
+ let recoveryStarted = false
117
124
  const errHandler = err => {
125
+ if (retryPending || recoveryStarted) return
126
+ recoveryStarted = true
118
127
  recorder.session.start('teardown')
119
128
  recorder.cleanAsyncErr()
120
129
  if (['before', 'beforeSuite'].includes(hookName)) {
@@ -149,9 +158,6 @@ export function injected(fn, suite, hookName) {
149
158
  })
150
159
  }
151
160
 
152
- const opts = suite.opts || {}
153
- const retries = opts[`retry${ucfirst(hookName)}`] || 0
154
-
155
161
  const currentTest = hookName === 'before' || hookName === 'after' ? suite?.ctx?.currentTest : null
156
162
 
157
163
  promiseRetry(
@@ -165,8 +171,13 @@ export function injected(fn, suite, hookName) {
165
171
  retry(err)
166
172
  } finally {
167
173
  if (number < retries) {
174
+ // drain the failed chain so in-flight steps (sessions, listeners)
175
+ // finish before the next attempt starts queueing new ones
176
+ await recorder.promise().catch(() => {})
168
177
  recorder.stop()
169
178
  recorder.start()
179
+ } else {
180
+ retryPending = false
170
181
  }
171
182
  }
172
183
  },
package/lib/mocha/cli.js CHANGED
@@ -1,5 +1,5 @@
1
- import mocha from 'mocha'
2
- const { reporters: { Base } } = mocha
1
+ import { reporters } from 'mocha'
2
+ const { Base } = reporters
3
3
  import ms from 'ms'
4
4
  import figures from 'figures'
5
5
  import { readFileSync } from 'fs'
@@ -1,5 +1,4 @@
1
- import Suite from 'mocha/lib/suite.js'
2
- import Test from 'mocha/lib/test.js'
1
+ import { Suite, Test } from 'mocha'
3
2
  import { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } from './hooks.js'
4
3
 
5
4
  export {
@@ -1,4 +1,4 @@
1
- import MochaSuite from 'mocha/lib/suite.js'
1
+ import { Suite as MochaSuite } from 'mocha'
2
2
  /**
3
3
  * @typedef {import('mocha')} Mocha
4
4
  */
package/lib/mocha/test.js CHANGED
@@ -1,5 +1,4 @@
1
- import Test from 'mocha/lib/test.js'
2
- import Suite from 'mocha/lib/suite.js'
1
+ import { Suite, Test } from 'mocha'
3
2
  import { genTestId, serializeError, clearString, relativeDir } from '../utils.js'
4
3
  import Step from '../step/base.js'
5
4
  import { enhanceMochaSuite } from './suite.js'
@@ -107,6 +106,7 @@ function serializeTest(test, error = null) {
107
106
  const parent = {}
108
107
  if (test.parent) {
109
108
  parent.title = test.parent.title
109
+ parent.file = test.parent.file
110
110
  }
111
111
 
112
112
  if (test.opts) {
package/lib/mocha/ui.js CHANGED
@@ -7,7 +7,7 @@ import { createTest } from './test.js'
7
7
  import { createSuite } from './suite.js'
8
8
  import { HookConfig, AfterSuiteHook, AfterHook, BeforeSuiteHook, BeforeHook } from './hooks.js'
9
9
  import { initMochaGlobals } from '../globals.js'
10
- import common from 'mocha/lib/interfaces/common.js'
10
+ import { createCommon } from 'mocha/lib/interfaces/common.js'
11
11
  import container from '../container.js'
12
12
  import store from '../store.js'
13
13
 
@@ -49,7 +49,7 @@ export default function (suite) {
49
49
  let afterEachHooksAreLoaded
50
50
 
51
51
  suite.on('pre-require', (context, file, mocha) => {
52
- const cmn = common(suites, context, mocha)
52
+ const cmn = createCommon(suites, context, mocha)
53
53
 
54
54
  const addScenario = function (title, opts = {}, fn) {
55
55
  const suite = suites[0]
@@ -74,7 +74,7 @@ export default function (suite) {
74
74
  context.BeforeAll = cmn.before
75
75
  context.AfterAll = cmn.after
76
76
 
77
- context.run = mocha.options.delay && common.runWithSuite(suite)
77
+ context.run = mocha.options.delay && cmn.runWithSuite(suite)
78
78
  /**
79
79
  * Describe a "suite" with the given `title`
80
80
  * and callback `fn` containing nested suites
@@ -303,6 +303,7 @@ export default function (config) {
303
303
 
304
304
  section.start()
305
305
 
306
+ const queueId = recorder.getQueueId()
306
307
  const cookies = store[`${name}_session`]
307
308
  const shouldAwait = isAsyncFunction(userSession.login) || isAsyncFunction(userSession.restore) || isAsyncFunction(userSession.check)
308
309
 
@@ -338,6 +339,7 @@ export default function (config) {
338
339
  }
339
340
  section.end()
340
341
  recorder.session.catch(err => {
342
+ if (recorder.getQueueId() !== queueId) return
341
343
  output.debug(`Failed auto login for ${name} due to ${err}`)
342
344
  output.debug('Logging in again')
343
345
  recorder.session.start('auto login')
@@ -355,6 +357,7 @@ export default function (config) {
355
357
  })
356
358
  })
357
359
  recorder.add(() => {
360
+ if (recorder.getQueueId() !== queueId) return
358
361
  recorder.session.restore('check login')
359
362
  })
360
363
 
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
  import os from 'os'
4
+ import { isMainThread } from 'worker_threads'
4
5
  import { mkdirp } from 'mkdirp'
5
6
  import { DOMImplementation, XMLSerializer } from '@xmldom/xmldom'
6
7
 
@@ -45,7 +46,7 @@ const INVALID_XML_CHARS = new RegExp('[\\u0000-\\u0008\\u000B\\u000C\\u000E-\\u0
45
46
  * Possible config options:
46
47
  *
47
48
  * * `outputName`: file name for the report. Default: `report.xml`.
48
- * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory.
49
+ * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory. With `run-workers` and `multiple` runs, each run writes its own report into its run folder (e.g. `output/dev_chromium1`) and this option is ignored.
49
50
  * * `testGroupName`: value of the `name` attribute on the root `<testsuites>` element. Default: `CodeceptJS`.
50
51
  * * `attachMeta`: add the test's meta information (`meta` keys, `tags`, `retries`) as `<properties>`. Default: true.
51
52
  * * `attachSteps`: add the step/substep log as `<system-out>`. Default: true.
@@ -67,10 +68,6 @@ export default function (config = {}) {
67
68
 
68
69
  let written = false
69
70
  const hookFailures = []
70
- // groupBySuite() (below) groups by object identity, not by value — reused
71
- // across BeforeSuite/AfterSuite failures from the same worker-forwarded
72
- // suite so they land in one <testsuite>, not one per failure.
73
- const workerSuiteByKey = new Map()
74
71
 
75
72
  event.dispatcher.on(event.hook.failed, hook => {
76
73
  if (!hook || !['BeforeSuite', 'AfterSuite'].includes(hook.hookName)) return
@@ -84,11 +81,7 @@ export default function (config = {}) {
84
81
  // groups under its real suite instead of the "Tests" fallback.
85
82
  let suite = runnable && runnable.parent
86
83
  if (!suite && hook.suiteTitle) {
87
- const key = `${hook.suiteTitle} ${hook.suiteFile || ''}`
88
- if (!workerSuiteByKey.has(key)) {
89
- workerSuiteByKey.set(key, { title: hook.suiteTitle, file: hook.suiteFile, tags: hook.suiteTags })
90
- }
91
- suite = workerSuiteByKey.get(key)
84
+ suite = { title: hook.suiteTitle, file: hook.suiteFile, tags: hook.suiteTags }
92
85
  }
93
86
  hookFailures.push({
94
87
  title: hook.title || `${hook.hookName} hook failed`,
@@ -100,19 +93,35 @@ export default function (config = {}) {
100
93
  meta: {},
101
94
  steps: [],
102
95
  duration: (runnable && runnable.duration) || 0,
96
+ outputDir: hook.outputDir,
103
97
  })
104
98
  })
105
99
 
106
100
  const writeReport = result => {
107
101
  if (written) return
108
102
  if (!result || !Array.isArray(result.tests)) return
103
+ if (!isMainThread) return
109
104
  written = true
110
105
 
106
+ const runDirs = [...new Set(result.tests.map(test => test.outputDir).filter(Boolean))]
107
+ if (runDirs.length) {
108
+ for (const dir of runDirs) {
109
+ const runResult = { tests: result.tests.filter(test => test.outputDir === dir), stats: result.stats }
110
+ const runHookFailures = hookFailures.filter(hf => hf.outputDir === dir)
111
+ saveXml(dir, buildXml(runResult, config, runHookFailures))
112
+ }
113
+ return
114
+ }
115
+
111
116
  const dir = config.output ? path.resolve(store.codeceptDir || process.cwd(), config.output) : store.outputDir || process.cwd()
117
+ saveXml(dir, buildXml(result, config, hookFailures))
118
+ }
119
+
120
+ const saveXml = (dir, xml) => {
112
121
  mkdirp.sync(dir)
113
122
  const file = path.join(dir, config.outputName)
114
123
 
115
- fs.writeFileSync(file, buildXml(result, config, hookFailures))
124
+ fs.writeFileSync(file, xml)
116
125
  output.plugin('junitReporter', `JUnit report saved to ${file}`)
117
126
  }
118
127
 
@@ -296,7 +305,7 @@ function groupBySuite(tests) {
296
305
  const groups = []
297
306
  const byKey = new Map()
298
307
  for (const test of tests) {
299
- const key = test.parent || test
308
+ const key = test.parent ? `${test.parent.title}\0${test.parent.file || test.file || ''}` : test
300
309
  if (!byKey.has(key)) {
301
310
  const list = []
302
311
  byKey.set(key, list)
@@ -109,7 +109,7 @@ function initUrlMode(pattern) {
109
109
  const helper = getBrowserHelper()
110
110
 
111
111
  if (!helper) {
112
- output.error('pause:on=url requires a browser helper (Playwright, WebDriver, Puppeteer, Appium, Obscura, Lightpanda)')
112
+ output.error('pause:on=url requires a browser helper (Playwright, WebDriver, Puppeteer, Appium, Obscura, Lightpanda, Moli)')
113
113
  return
114
114
  }
115
115