codeceptjs 4.0.0-rc.21 → 4.0.0-rc.23

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.
@@ -5,119 +5,63 @@ title: Continuous Integration
5
5
 
6
6
  # Continuous Integration
7
7
 
8
- CodeceptJS runs in any CI system that can install Node.js. The work is in the surrounding environment: a headless browser, a driver server for WebDriver, failure artifacts to upload, and a parallelization strategy that keeps the wall-clock time reasonable. This guide covers each step and provides drop-in configs for the major CI systems.
8
+ CodeceptJS runs in any CI that can install Node.js. This page covers the setup, then provides ready-to-use configs for the major CI systems.
9
9
 
10
- ## Preparing tests for CI
10
+ ## Setup
11
11
 
12
- A CI-ready suite needs only a few things:
12
+ - **Node.js** — install it on the runner (`actions/setup-node`, the `node:20` image, `NodeTool@0` on Azure). Examples below use Node 20.
13
+ - **Headless** — `codecept.conf.js` must contain `setHeadlessWhen(process.env.HEADLESS || process.env.CI)`. `codeceptjs init` adds it; since CI sets `CI=true`, the suite runs headless automatically.
13
14
 
14
- - **Headless mode.** Playwright runs headless by default — only act if you set `show: true` locally. To toggle it from CI, export `HEADLESS=true` and read it from your config.
15
- - **Colored logs.** Export `FORCE_COLOR=1` so CodeceptJS output renders correctly in CI log viewers.
16
- - **Failure artifacts.** Keep `screenshotOnFail` enabled (it is on by default). For Playwright, also enable `trace` and `video` in the helper config — they make a remote failure diagnosable from a single artifact.
17
- - **Self-healing for flaky tests.** Use the [`heal` plugin](/heal) to recover from broken locators. The `retryFailedStep` plugin is already enabled by default — you do not need to configure it.
15
+ ```js
16
+ import { setHeadlessWhen } from '@codeceptjs/configure'
18
17
 
19
- You do **not** need to set `CI=true`. Every CI provider exports it automatically, and CodeceptJS reads it to relax certain timeouts.
18
+ setHeadlessWhen(process.env.HEADLESS || process.env.CI)
19
+ ```
20
20
 
21
- ## Installing browsers and drivers
21
+ Override the browser or viewport per run with the [`browser` plugin](/plugins#browser): `-p browser:browser=firefox:windowSize=1280x1024`.
22
+ - **Artifacts** — enable the on-failure capture plugins:
22
23
 
23
- ### Playwright
24
-
25
- Playwright needs browser binaries plus Linux system libraries. The recommended approach (per the [official Playwright CI docs](https://playwright.dev/docs/ci)) is:
26
-
27
- ```bash
28
- npm ci
29
- npx playwright install --with-deps chromium
30
- ```
31
-
32
- `--with-deps` pulls in `libnss`, fonts, and other OS packages. To install all engines, drop the `chromium` argument. Playwright explicitly recommends against caching browser binaries — restoring the cache takes about as long as a fresh download.
33
-
34
- If you prefer the official Playwright Docker image, see the [Playwright Docker docs](https://playwright.dev/docs/docker). Pin the image tag to **the same version as your installed `playwright` package** — a mismatched image will fail to find browser executables. The examples below use `node:20` + `npx playwright install --with-deps` to avoid this version-pin problem entirely.
35
-
36
- ### WebDriver
37
-
38
- CodeceptJS's WebDriver helper talks to any WebDriver-protocol endpoint. In CI, the simplest setup is a [Selenium Docker container](https://github.com/SeleniumHQ/docker-selenium):
39
-
40
- ```bash
41
- docker run -d --net=host --shm-size=2g selenium/standalone-chrome
42
- ```
43
-
44
- Point the helper at it:
45
-
46
- ```js
47
- helpers: {
48
- WebDriver: {
49
- url: 'http://localhost:8000',
50
- browser: 'chrome',
51
- host: process.env.SELENIUM_HOST || 'localhost',
52
- port: parseInt(process.env.SELENIUM_PORT || '4444', 10),
24
+ ```js
25
+ plugins: {
26
+ screenshot: { enabled: true }, // screenshot on failure
27
+ pageInfo: { enabled: true }, // page URL, HTML errors, console logs
28
+ aiTrace: { enabled: true, on: 'fail' }, // AI-friendly trace.md
53
29
  }
54
- }
55
- ```
30
+ ```
56
31
 
57
- For an alternative without Selenium, see the [WebDriver helper docs](/webdriver) recent WebdriverIO versions can manage drivers (chromedriver, geckodriver) directly. Selenium is still the most portable choice for CI.
32
+ [`screencast`](/plugins#screencast) records video of failed tests (Playwright). Everything lands in `output/` upload that directory as a build artifact. Every example below does.
58
33
 
59
- `--shm-size=2g` matters. The default 64 MB causes Chrome tabs to crash on heavy pages.
34
+ ## Browsers and drivers
60
35
 
61
- ## Running tests
36
+ - **Playwright** — `npx playwright install --with-deps`. Docs: [Playwright CI](https://playwright.dev/docs/ci), [Playwright Docker image](https://playwright.dev/docs/docker) (pin the tag to your installed `playwright` version).
37
+ - **WebDriver** — run a Selenium server: `selenium/standalone-chrome` on port `4444`. Docs: [WebDriver helper](/webdriver), [WebdriverIO Selenium Grid](https://webdriver.io/docs/seleniumgrid), [Selenium Docker images](https://github.com/SeleniumHQ/docker-selenium).
62
38
 
63
- A single process:
39
+ ## Check before running
64
40
 
65
- ```bash
66
- npx codeceptjs run
67
- ```
68
-
69
- Parallel workers on one machine:
41
+ `npx codeceptjs check` loads the config, opens the browser (or connects to Selenium), and counts tests. Prepend it so a broken environment fails fast with a clear message:
70
42
 
71
43
  ```bash
72
- npx codeceptjs run-workers 4 --by pool
44
+ npx codeceptjs check
45
+ npx codeceptjs run
73
46
  ```
74
47
 
75
- `--by pool` distributes tests dynamically: each worker grabs the next test as it finishes, so no worker sits idle. See [Parallel Execution](/parallel) for `--by test` and `--by suite`.
76
-
77
- Sharded across multiple machines (CI matrix):
48
+ Every CI example below does this.
78
49
 
79
- ```bash
80
- npx codeceptjs run --shard 1/4
81
- npx codeceptjs run --shard 2/4
82
- npx codeceptjs run --shard 3/4
83
- npx codeceptjs run --shard 4/4
84
- ```
50
+ ## Parallel execution
85
51
 
86
- You can combine the two — each shard runs on its own machine, and `run-workers` parallelizes within the shard.
52
+ - `npx codeceptjs run` one process.
53
+ - `npx codeceptjs run-workers 4` — parallel on one machine, tests handed to workers dynamically.
54
+ - `npx codeceptjs run --shard 1/4` — split the suite across CI matrix jobs (one shard per machine).
87
55
 
88
- Filter by tag:
89
-
90
- ```bash
91
- npx codeceptjs run --grep "@smoke"
92
- npx codeceptjs run --grep "@slow" --invert
93
- ```
56
+ Shards and workers combine. Full reference: [Parallel Execution](/parallel).
94
57
 
95
58
  ## Reporting
96
59
 
97
- For CI test reporting, use [`@testomatio/reporter`](https://github.com/testomatio/reporter). It ships built-in **pipes** that publish results directly into the CI platform's UI no XML wrangling required.
98
-
99
- | CI | Recommended pipes | Result |
100
- |---|---|---|
101
- | GitHub Actions | `github` + `html` | PR check annotations + a self-contained HTML report |
102
- | GitLab CI | `gitlab` | Merge request widget with test results |
103
- | Bitbucket Pipelines | `bitbucket` | Pipeline test report |
104
- | Any | `html` | HTML report you can upload as an artifact |
105
-
106
- Install:
107
-
108
- ```bash
109
- npm i --save-dev @testomatio/reporter
110
- ```
111
-
112
- See the [reporter README](https://github.com/testomatio/reporter) for the per-pipe environment variables.
113
-
114
- Whatever reporter you use, also upload the `output/` directory as a build artifact. It contains failure screenshots and, with Playwright, traces and videos.
60
+ Use [`@testomatio/reporter`](https://github.com/testomatio/reporter). It ships pipes that publish results into GitHub PR checks, GitLab merge-request widgets, and Bitbucket pipeline reports. [See Reporting](/reports).
115
61
 
116
- For other reporter formats, see [Reports](/reports).
62
+ ## CI examples
117
63
 
118
- ## CI system examples
119
-
120
- The examples below use Playwright by default. A WebDriver-with-Selenium variant follows where it differs.
64
+ Each example uses Playwright by default; a WebDriver-with-Selenium variant follows where it differs. A `node:20` base image plus `npx playwright install --with-deps` keeps these configs free of version pins.
121
65
 
122
66
  ### GitHub Actions — Playwright
123
67
 
@@ -145,6 +89,7 @@ jobs:
145
89
  cache: npm
146
90
  - run: npm ci
147
91
  - run: npx playwright install --with-deps chromium
92
+ - run: npx codeceptjs check
148
93
  - run: npx codeceptjs run-workers 4 --by pool
149
94
  - uses: actions/upload-artifact@v4
150
95
  if: failure()
@@ -178,6 +123,7 @@ jobs:
178
123
  with:
179
124
  node-version: 20
180
125
  - run: npm ci
126
+ - run: npx codeceptjs check
181
127
  - run: npx codeceptjs run-workers 2 --by pool
182
128
  - uses: actions/upload-artifact@v4
183
129
  if: failure()
@@ -186,7 +132,7 @@ jobs:
186
132
  path: output/
187
133
  ```
188
134
 
189
- ### GitHub Actions — Sharding matrix
135
+ ### GitHub Actions — sharded matrix
190
136
 
191
137
  Each shard runs on its own runner in parallel:
192
138
 
@@ -205,11 +151,43 @@ jobs:
205
151
  node-version: 20
206
152
  - run: npm ci
207
153
  - run: npx playwright install --with-deps chromium
154
+ - run: npx codeceptjs check
208
155
  - run: npx codeceptjs run --shard ${{ matrix.shard }}
209
156
  - uses: actions/upload-artifact@v4
210
157
  if: failure()
211
158
  with:
212
- name: output-shard-${{ strategy.job-index }}
159
+ name: output-${{ strategy.job-index }}
160
+ path: output/
161
+ ```
162
+
163
+ ### GitHub Actions — browser matrix
164
+
165
+ Run the same suite across browsers and viewports via the [`browser` plugin](/plugins#browser) (`npm i --save-dev @codeceptjs/configure`):
166
+
167
+ ```yaml
168
+ jobs:
169
+ test:
170
+ runs-on: ubuntu-latest
171
+ strategy:
172
+ fail-fast: false
173
+ matrix:
174
+ include:
175
+ - { browser: chromium, size: 1920x1080 }
176
+ - { browser: firefox, size: 1366x768 }
177
+ - { browser: webkit, size: 414x896 }
178
+ steps:
179
+ - uses: actions/checkout@v4
180
+ - uses: actions/setup-node@v4
181
+ with:
182
+ node-version: 20
183
+ - run: npm ci
184
+ - run: npx playwright install --with-deps
185
+ - run: npx codeceptjs check
186
+ - run: npx codeceptjs run -p browser:browser=${{ matrix.browser }}:windowSize=${{ matrix.size }}
187
+ - uses: actions/upload-artifact@v4
188
+ if: failure()
189
+ with:
190
+ name: output-${{ matrix.browser }}-${{ matrix.size }}
213
191
  path: output/
214
192
  ```
215
193
 
@@ -230,11 +208,11 @@ playwright:
230
208
  - npm ci
231
209
  - npx playwright install --with-deps chromium
232
210
  script:
211
+ - npx codeceptjs check
233
212
  - npx codeceptjs run --shard $CI_NODE_INDEX/$CI_NODE_TOTAL
234
213
  artifacts:
235
214
  when: on_failure
236
- paths:
237
- - output/
215
+ paths: [output/]
238
216
  expire_in: 1 week
239
217
 
240
218
  webdriver:
@@ -248,13 +226,14 @@ webdriver:
248
226
  SELENIUM_PORT: "4444"
249
227
  script:
250
228
  - npm ci
229
+ - npx codeceptjs check
251
230
  - npx codeceptjs run-workers 2 --by pool
252
231
  artifacts:
253
232
  when: on_failure
254
233
  paths: [output/]
255
234
  ```
256
235
 
257
- `$CI_NODE_INDEX` is 1-based, which matches CodeceptJS's `--shard` syntax exactly.
236
+ `$CI_NODE_INDEX` is 1-based it maps directly to CodeceptJS's `--shard` index.
258
237
 
259
238
  ### Bitbucket Pipelines
260
239
 
@@ -264,6 +243,8 @@ webdriver:
264
243
  image: node:20
265
244
 
266
245
  definitions:
246
+ caches:
247
+ playwright: ~/.cache/ms-playwright
267
248
  services:
268
249
  selenium:
269
250
  image: selenium/standalone-chrome
@@ -271,37 +252,25 @@ definitions:
271
252
 
272
253
  pipelines:
273
254
  default:
274
- - step:
275
- name: Install
276
- caches: [node]
277
- script:
278
- - npm ci
279
- - npx playwright install --with-deps chromium
280
255
  - parallel:
281
256
  - step:
282
- name: Shard 1/4
283
- script:
284
- - npx codeceptjs run --shard 1/4
285
- artifacts:
286
- - output/**
287
- - step:
288
- name: Shard 2/4
289
- script:
290
- - npx codeceptjs run --shard 2/4
291
- artifacts:
292
- - output/**
293
- - step:
294
- name: Shard 3/4
257
+ name: Playwright — shard 1/2
258
+ caches: [node, playwright]
295
259
  script:
296
- - npx codeceptjs run --shard 3/4
297
- artifacts:
298
- - output/**
260
+ - npm ci
261
+ - npx playwright install --with-deps chromium
262
+ - npx codeceptjs check
263
+ - npx codeceptjs run --shard 1/2
264
+ artifacts: [output/**]
299
265
  - step:
300
- name: Shard 4/4
266
+ name: Playwright — shard 2/2
267
+ caches: [node, playwright]
301
268
  script:
302
- - npx codeceptjs run --shard 4/4
303
- artifacts:
304
- - output/**
269
+ - npm ci
270
+ - npx playwright install --with-deps chromium
271
+ - npx codeceptjs check
272
+ - npx codeceptjs run --shard 2/2
273
+ artifacts: [output/**]
305
274
  ```
306
275
 
307
276
  For WebDriver, attach the Selenium service to the step:
@@ -310,14 +279,13 @@ For WebDriver, attach the Selenium service to the step:
310
279
  pipelines:
311
280
  default:
312
281
  - step:
313
- image: node:20
314
282
  services: [selenium]
315
283
  script:
316
284
  - npm ci
317
285
  - export SELENIUM_HOST=localhost SELENIUM_PORT=4444
286
+ - npx codeceptjs check
318
287
  - npx codeceptjs run-workers 2 --by pool
319
- artifacts:
320
- - output/**
288
+ artifacts: [output/**]
321
289
  ```
322
290
 
323
291
  ### Jenkins
@@ -344,10 +312,10 @@ pipeline {
344
312
  }
345
313
  stage('Test') {
346
314
  parallel {
347
- stage('Shard 1/4') { steps { sh 'npx codeceptjs run --shard 1/4' } }
348
- stage('Shard 2/4') { steps { sh 'npx codeceptjs run --shard 2/4' } }
349
- stage('Shard 3/4') { steps { sh 'npx codeceptjs run --shard 3/4' } }
350
- stage('Shard 4/4') { steps { sh 'npx codeceptjs run --shard 4/4' } }
315
+ stage('Shard 1/4') { steps { sh 'npx codeceptjs check && npx codeceptjs run --shard 1/4' } }
316
+ stage('Shard 2/4') { steps { sh 'npx codeceptjs check && npx codeceptjs run --shard 2/4' } }
317
+ stage('Shard 3/4') { steps { sh 'npx codeceptjs check && npx codeceptjs run --shard 3/4' } }
318
+ stage('Shard 4/4') { steps { sh 'npx codeceptjs check && npx codeceptjs run --shard 4/4' } }
351
319
  }
352
320
  }
353
321
  }
@@ -359,18 +327,17 @@ pipeline {
359
327
  }
360
328
  ```
361
329
 
362
- For WebDriver, launch Selenium alongside the test container:
330
+ For WebDriver, run Selenium alongside the test container:
363
331
 
364
332
  ```groovy
365
333
  stage('Test') {
366
334
  steps {
367
335
  script {
368
- docker.image('selenium/standalone-chrome')
369
- .withRun('--shm-size=2g -p 4444:4444') { c ->
370
- sh '''
371
- export SELENIUM_HOST=localhost SELENIUM_PORT=4444
372
- npx codeceptjs run-workers 2 --by pool
373
- '''
336
+ docker.image('selenium/standalone-chrome').withRun('--shm-size=2g -p 4444:4444') { c ->
337
+ withEnv(['SELENIUM_HOST=localhost', 'SELENIUM_PORT=4444']) {
338
+ sh 'npx codeceptjs check'
339
+ sh 'npx codeceptjs run-workers 2 --by pool'
340
+ }
374
341
  }
375
342
  }
376
343
  }
@@ -393,6 +360,7 @@ jobs:
393
360
  - checkout
394
361
  - run: npm ci
395
362
  - run: npx playwright install --with-deps chromium
363
+ - run: npx codeceptjs check
396
364
  - run:
397
365
  name: Run shard
398
366
  command: |
@@ -411,6 +379,7 @@ jobs:
411
379
  steps:
412
380
  - checkout
413
381
  - run: npm ci
382
+ - run: npx codeceptjs check
414
383
  - run: npx codeceptjs run-workers 2 --by pool
415
384
  - store_artifacts:
416
385
  path: output
@@ -444,9 +413,10 @@ steps:
444
413
  - script: npm ci
445
414
  displayName: Install dependencies
446
415
  - script: npx playwright install --with-deps chromium
447
- displayName: Install Playwright browsers
448
- - script: |
449
- npx codeceptjs run --shard $(System.JobPositionInPhase)/$(System.TotalJobsInPhase)
416
+ displayName: Install browsers
417
+ - script: npx codeceptjs check
418
+ displayName: Check setup
419
+ - script: npx codeceptjs run --shard $(System.JobPositionInPhase)/$(System.TotalJobsInPhase)
450
420
  displayName: Run shard $(System.JobPositionInPhase)/$(System.TotalJobsInPhase)
451
421
  env:
452
422
  FORCE_COLOR: 1
@@ -457,35 +427,27 @@ steps:
457
427
  artifactName: codeceptjs-output-$(System.JobPositionInPhase)
458
428
  ```
459
429
 
460
- For WebDriver, run Selenium as a sidecar before tests:
430
+ For WebDriver, run Selenium as a sidecar before the tests:
461
431
 
462
432
  ```yaml
463
433
  - script: docker run -d --net=host --shm-size=2g selenium/standalone-chrome
464
434
  displayName: Start Selenium
465
435
  - script: |
466
436
  export SELENIUM_HOST=localhost SELENIUM_PORT=4444
437
+ npx codeceptjs check
467
438
  npx codeceptjs run-workers 2 --by pool
468
439
  displayName: Run tests
469
440
  ```
470
441
 
471
442
  ## Docker
472
443
 
473
- The official `codeceptjs/codeceptjs` image runs Playwright, Puppeteer, and WebDriver suites without further setup. Pass runtime flags through `CODECEPT_ARGS` and the worker count through `NO_OF_WORKERS`. See [Docker](/docker) for the full reference and Compose examples.
474
-
475
- ## Tips
476
-
477
- - **Raise per-test timeouts in CI.** CI machines are slower than your laptop. Bump `timeout` in `codecept.conf.js` when assertions race the page.
478
- - **Diagnose from logs.** Re-run with `--debug` or `DEBUG=codeceptjs:*` when a job fails and you cannot reproduce locally.
479
- - **Selenium Chrome: always `--shm-size=2g`.** The default 64 MB causes tab crashes on heavy pages.
480
- - **Custom Playwright images: install OS deps.** When you cannot use `mcr.microsoft.com/playwright`, run `npx playwright install --with-deps` to pull in `libnss`, fonts, and other system libraries.
481
- - **Upload `output/` only on failure.** Successful runs produce no useful artifacts.
444
+ The official `codeceptjs/codeceptjs` image runs Playwright, Puppeteer, and WebDriver suites with no extra setup. Pass runner flags through `CODECEPT_ARGS` and the worker count through `NO_OF_WORKERS`. See [Docker](/docker).
482
445
 
483
446
  ## See also
484
447
 
485
- - [Playwright CI guide](https://playwright.dev/docs/ci) upstream notes on browser install, sharding, and per-platform config.
486
- - [Playwright Docker image](https://playwright.dev/docs/docker) image tags and the version-pinning rule.
487
- - [WebdriverIO Selenium Grid](https://webdriver.io/docs/seleniumgrid) connection options for `host`/`port`/`path`.
488
- - [Selenium Docker images](https://github.com/SeleniumHQ/docker-selenium) — image variants (`standalone-chrome`, `standalone-firefox`, debug images with VNC).
448
+ - [Playwright CI guide](https://playwright.dev/docs/ci) · [Playwright Docker image](https://playwright.dev/docs/docker)
449
+ - [WebdriverIO Selenium Grid](https://webdriver.io/docs/seleniumgrid) · [Selenium Docker images](https://github.com/SeleniumHQ/docker-selenium)
450
+ - [Parallel Execution](/parallel) · [Reports](/reports) · [Plugins](/plugins) · [Docker](/docker)
489
451
 
490
452
  ## Community recipes
491
453
 
@@ -197,7 +197,7 @@ Each implemented method should return a value as they will be added to global pr
197
197
  It is possible to execute global conditional retries to handle unforseen errors.
198
198
  Lost connections and network issues are good candidates to be retried whenever they appear.
199
199
 
200
- This can be done inside a helper using the global [promise recorder](/hooks/#api):
200
+ This can be done inside a helper using the global [promise recorder](/architecture#the-recorder):
201
201
 
202
202
  Example: Retrying rendering errors in Puppeteer.
203
203