You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ai.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -230,10 +230,9 @@ npx codeceptjs generate:heal
230
230
Heal recipes should be included into `codecept.conf.js` or `codecept.conf.ts` config file:
231
231
232
232
```js
233
+
import'./heal.js'
233
234
234
-
require('./heal')
235
-
236
-
exports.config= {
235
+
exportconstconfig= {
237
236
// ... your codeceptjs config
238
237
```
239
238
@@ -491,8 +490,8 @@ It is recommended to try HTML processing on one of your web pages before launchi
491
490
To do that open the common page of your application and using DevTools copy the outerHTML of `<html>` element. Don't use `Page Source` for that, as it may not include dynamically added HTML elements. Save this HTML into a file and create a NodeJS script:
Copy file name to clipboardExpand all lines: docs/best.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,8 +100,8 @@ class CheckoutForm {
100
100
}
101
101
102
102
}
103
-
module.exports=newCheckoutForm();
104
-
module.exports.CheckoutForm= CheckoutForm; // for inheritance
103
+
exportdefaultnewCheckoutForm();
104
+
export {CheckoutForm }; // for inheritance
105
105
```
106
106
107
107
* for components that are repeated accross a website (widgets) but don't belong to any page, use component objects. They are the same as page objects but focused only aroung one element:
@@ -143,8 +143,8 @@ class DatePicker {
143
143
}
144
144
145
145
146
-
module.exports=newDatePicker();
147
-
module.exports.DatePicker= DatePicker; // for inheritance
146
+
exportdefaultnewDatePicker();
147
+
export {DatePicker }; // for inheritance
148
148
```
149
149
150
150
## Configuration
@@ -156,15 +156,15 @@ module.exports.DatePicker = DatePicker; // for inheritance
156
156
* use `.env` files and dotenv package to load sensitive data
157
157
158
158
```js
159
-
require('dotenv').config({ path:'.env' });
159
+
import'dotenv/config'
160
160
```
161
161
162
162
* move similar parts in those configs by moving them to modules and putting them to `config` dir
163
163
* when you need to load lots of page objects/components, you can get components/pageobjects file declaring them:
164
164
165
165
```js
166
166
// inside config/components.js
167
-
module.exports= {
167
+
exportdefault {
168
168
DatePicker:"./components/datePicker",
169
169
Dropdown:"./components/dropdown",
170
170
}
@@ -173,10 +173,13 @@ module.exports = {
173
173
include them like this:
174
174
175
175
```js
176
+
importpagesfrom'./config/pages.js'
177
+
importcomponentsfrom'./config/components.js'
178
+
176
179
include: {
177
180
I:'./steps_file',
178
-
...require('./config/pages'), //require POs and DOs for module
179
-
...require('./config/components'), //require all components
181
+
...pages, //import POs and DOs for module
182
+
...components, //import all components
180
183
},
181
184
```
182
185
@@ -215,9 +218,9 @@ include: {
215
218
* When you need to customize access to API and go beyond what ApiDataFactory provides, implement DAO:
`run`, `run-workers`, `run-multiple`, `run-rerun` and `dry-run` accept a `-p` (`--plugins`) flag to enable plugins on the command line, with optional arguments per plugin. Tokens are colon-chained per plugin, comma-separated across plugins:
106
+
107
+
```sh
108
+
npx codeceptjs run -p <name># enable plugin
109
+
npx codeceptjs run -p <name>:<arg1>:<arg2># enable + pass args
110
+
npx codeceptjs run -p <plugin1>,<plugin2>:<arg># multiple plugins
111
+
```
112
+
113
+
Plugins listed via `-p` are activated even when their config has `enabled: false` (or no `enabled` flag). This is the supported way to switch a plugin on for a single run without editing `codecept.conf`.
114
+
115
+
A few examples:
116
+
117
+
```sh
118
+
npx codeceptjs run -p pauseOnFail # pause on first failure
119
+
npx codeceptjs run -p pauseOn:step # pause before every step
120
+
npx codeceptjs run -p pauseOn:url:/checkout/*# pause on URL match
121
+
npx codeceptjs run -p stepByStepReport # produce a step-by-step HTML report
122
+
```
123
+
124
+
### Browser Control
125
+
126
+
The built-in `browser` plugin overrides browser-helper config from the CLI — works for Playwright, Puppeteer, WebDriver and Appium without editing `codecept.conf`.
127
+
128
+
```sh
129
+
npx codeceptjs run -p browser:show # force visible browser
130
+
npx codeceptjs run -p browser:hide # force headless
131
+
npx codeceptjs run -p browser:browser=firefox # switch engine
132
+
npx codeceptjs run -p browser:windowSize=1024x768 # set viewport
133
+
npx codeceptjs run -p browser:hide:browser=webkit:windowSize=800x600
134
+
```
135
+
136
+
Tokens after `browser:` are either flags (`show`, `hide`) or `key=value` pairs. Three keys get per-helper translation:
137
+
138
+
-`browser=<name>` — Puppeteer receives `product`, Playwright/WebDriver receive `browser`. Validated per helper (`chromium`/`webkit`/`firefox` for Playwright, `chrome`/`firefox` for Puppeteer).
139
+
-`show=true|false` (or the `show`/`hide` flag) — sets `show` on Playwright/Puppeteer; injects/strips `--headless` in WebDriver chrome/firefox capability args.
140
+
-`windowSize=WxH` — sets `windowSize` on every helper; also adds `--window-size=W,H` to chromium/chrome args for Playwright/Puppeteer.
141
+
142
+
Anything else (`-p browser:video=false:waitForTimeout=10000`) is shallow-merged onto every browser helper present in config. Values are coerced (`true`/`false` → boolean, digits → Number, otherwise string).
143
+
103
144
## Run Workers
104
145
105
146
Run tests in parallel threads. CodeceptJS supports different distribution strategies for optimal performance.
Copy file name to clipboardExpand all lines: docs/configuration.md
+37-6Lines changed: 37 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,7 @@ Create `codecept.conf.js` file and make it export `config` property.
119
119
See the config example:
120
120
121
121
```js
122
-
exports.config= {
122
+
exportconstconfig= {
123
123
helpers: {
124
124
WebDriver: {
125
125
// load variables from the environment and provide defaults
@@ -158,21 +158,52 @@ codeceptjs run --config=./path/to/my/config.js
158
158
159
159
> 📺 [Watch this material](https://www.youtube.com/watch?v=onBnfo_rJa4&t=4s) on YouTube
160
160
161
-
[`@codeceptjs/configure` package](https://github.com/codeceptjs/configure) contains shared recipes for common configuration patterns. This allows to set meta-configuration, independent from a current helper enabled.
161
+
[`@codeceptjs/configure`](https://github.com/codeceptjs/configure)ships with CodeceptJS as a dependency and contains shared recipes for common configuration patterns. It lets you set meta-configuration that's independent of the active helper.
162
162
163
-
Install it and enable to easily switch to headless/window mode, change window size, etc.
For one-shot bundles use `setBrowserConfig` — pass any subset of `{ browser, show, windowSize, url, ... }` and the right per-helper translation happens automatically (Puppeteer receives `product` for `browser`, WebDriver gets `--headless` injected, etc.). Keys whose value is `undefined` are skipped, so unset env vars don't clobber existing config:
show:!process.env.HEADLESS, // headed unless HEADLESS is set
184
+
windowSize:'1280x720',
185
+
url:process.env.URL, // overrides helper.url when set
186
+
})
187
+
```
188
+
189
+
`setCommonPlugins()` enables a curated set of plugins and registers a few more as discoverable (so they can be activated ad-hoc via [`-p` plugin arguments](/commands#plugin-arguments) without editing config):
Copy file name to clipboardExpand all lines: docs/custom-helpers.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ Helpers are classes inherited from [corresponding abstract class](https://github
34
34
Created helper file should look like this:
35
35
36
36
```js
37
-
constHelper=require('@codeceptjs/helper')
37
+
importHelperfrom'@codeceptjs/helper'
38
38
39
39
classMyHelperextendsHelper {
40
40
// before/after hooks
@@ -51,14 +51,14 @@ class MyHelper extends Helper {
51
51
// use: this.helpers['helperName']
52
52
}
53
53
54
-
module.exports= MyHelper
54
+
exportdefaultMyHelper
55
55
```
56
56
57
57
When the helper is enabled in config all methods of a helper class are available in `I` object.
58
58
For instance, if we add a new method to helper class:
59
59
60
60
```js
61
-
constHelper=require('@codeceptjs/helper')
61
+
importHelperfrom'@codeceptjs/helper'
62
62
63
63
classMyHelperextendsHelper {
64
64
doAwesomeThings() {
@@ -202,8 +202,9 @@ This can be done inside a helper using the global [promise recorder](/hooks/#api
202
202
Example: Retrying rendering errors in Puppeteer.
203
203
204
204
```js
205
+
import { recorder } from'codeceptjs'
206
+
205
207
_before() {
206
-
constrecorder=require('codeceptjs').recorder;
207
208
recorder.retry({
208
209
retries:2,
209
210
when:err=>err.message.indexOf('Cannot find context with specified id') >-1,
@@ -217,7 +218,7 @@ Retry rules are available in array `recorder.retries`. The last retry rule can b
217
218
218
219
## Using Typescript
219
220
220
-
With Typescript, just simply replacing `module.exports` with `export` for autocompletion.
221
+
With Typescript, just simply replacing `export default` with `export` for autocompletion.
221
222
222
223
## Helper Examples
223
224
@@ -226,7 +227,7 @@ With Typescript, just simply replacing `module.exports` with `export` for autoco
226
227
In this example we take the power of Playwright to change geolocation in our tests:
227
228
228
229
```js
229
-
constHelper=require('@codeceptjs/helper')
230
+
importHelperfrom'@codeceptjs/helper'
230
231
231
232
classMyHelperextendsHelper {
232
233
asyncsetGeoLocation(longitude, latitude) {
@@ -242,10 +243,10 @@ class MyHelper extends Helper {
242
243
Next example demonstrates how to use WebDriver library to create your own test action. Method `seeAuthentication` will use `browser` instance of WebDriver to get access to cookies. Standard NodeJS assertion library will be used (you can use any).
243
244
244
245
```js
245
-
constHelper=require('@codeceptjs/helper')
246
+
importHelperfrom'@codeceptjs/helper'
246
247
247
248
// use any assertion library you like
248
-
constassert=require('assert')
249
+
importassertfrom'assert'
249
250
250
251
classMyHelperextendsHelper {
251
252
/**
@@ -271,7 +272,7 @@ class MyHelper extends Helper {
271
272
}
272
273
}
273
274
274
-
module.exports= MyHelper
275
+
exportdefaultMyHelper
275
276
```
276
277
277
278
### Puppeteer Example
@@ -281,8 +282,8 @@ Puppeteer has [nice and elegant API](https://github.com/puppeteer/puppeteer/blob
281
282
Let's see how we can use [emulate](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.page.emulate.md) function to emulate iPhone browser in a test.
282
283
283
284
```js
284
-
constHelper=require('@codeceptjs/helper')
285
-
constpuppeteer=require('puppeteer')
285
+
importHelperfrom'@codeceptjs/helper'
286
+
importpuppeteerfrom'puppeteer'
286
287
constiPhone=puppeteer.devices['iPhone 6']
287
288
288
289
classMyHelperextendsHelper {
@@ -292,5 +293,5 @@ class MyHelper extends Helper {
0 commit comments