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: CHANGELOG.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4003,7 +4003,7 @@ This change allows using auto-completion when running a specific test.
4003
4003
- PageObjects simplified to remove `_init()` extra method. Try updated generators and see [updated guide](https://codecept.io/pageobjects/#pageobject).
- [Puppeteer] Stability improvement. Waits for for `load` event on page load. This strategy can be changed in config:
4006
-
- `waitForNavigation` config option introduced. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagewaitfornavigationoptions)
4006
+
- `waitForNavigation` config option introduced. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.waitforoptions.md)
4007
4007
- `getPageTimeout` config option to set maximum navigation time in milliseconds. Default is 30 seconds.
4008
4008
- `waitForNavigation` method added. Explicitly waits for navigation to be finished.
4009
4009
- [WebDriverIO][Protractor][Puppeteer][Nightmare] **Possible BC** `grabTextFrom` unified. Return a text for single matched element and an array of texts for multiple elements.
@@ -4087,7 +4087,7 @@ Scenario('this test should throw error', I => {
4087
4087
- Added Chinese translation ("zh-CN" and "zh-TW") by @TechQuery.
4088
4088
- Fixed running tests from a different folder specified by `-c` option.
4089
4089
- [Puppeteer] Added support for hash handling in URL by @gavoja.
4090
-
- [Puppeteer] Fixed setting viewport size by @gavoja. See [Puppeteer issue](https://github.com/GoogleChrome/puppeteer/issues/1183)
4090
+
- [Puppeteer] Fixed setting viewport size by @gavoja. See [Puppeteer issue](https://github.com/puppeteer/puppeteer/issues/1183)
Copy file name to clipboardExpand all lines: docs/changelog.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3837,7 +3837,7 @@ This change allows using auto-completion when running a specific test.
3837
3837
- PageObjects simplified to remove `_init()` extra method. Try updated generators and see [updated guide](https://codecept.io/pageobjects/#pageobject).
-**[Puppeteer]** Stability improvement. Waitsforfor`load`event on page load. This strategy can be changed in config:
3840
-
-`waitForNavigation` config option introduced. Possible options:`load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagewaitfornavigationoptions)
3840
+
-`waitForNavigation` config option introduced. Possible options:`load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.waitforoptions.md)
3841
3841
-`getPageTimeout` config option to set maximum navigation time inmilliseconds. Default is 30 seconds.
3842
3842
-`waitForNavigation` method added. Explicitly waits for navigation to be finished.
3843
3843
- [WebDriverIO][Protractor][Puppeteer][Nightmare] **Possible BC**`grabTextFrom`unified. Return a text for single matched element and an array of texts for multiple elements.
@@ -3921,7 +3921,7 @@ Scenario('this test should throw error', I => {
3921
3921
- Added Chinese translation ("zh-CN" and "zh-TW") by **[TechQuery](https://github.com/TechQuery)**.
3922
3922
- Fixed running tests from a different folder specified by `-c` option.
3923
3923
-**[Puppeteer]** Added support for hash handling inURL by **[gavoja](https://github.com/gavoja)**.
3924
-
-**[Puppeteer]** Fixed setting viewport size by **[gavoja](https://github.com/gavoja)**. See [Puppeteer issue](https://github.com/GoogleChrome/puppeteer/issues/1183)
3924
+
-**[Puppeteer]** Fixed setting viewport size by **[gavoja](https://github.com/gavoja)**. See [Puppeteer issue](https://github.com/puppeteer/puppeteer/issues/1183)
Copy file name to clipboardExpand all lines: docs/custom-helpers.md
+40-50Lines changed: 40 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Custom Helpers
5
5
6
6
# Extending CodeceptJS With Custom Helpers
7
7
8
-
Helper is the core concept of CodeceptJS. Helper is a wrapper on top of various libraries providing unified interface around them. When `I` object is used in tests it delegates execution of its functions to currently enabled helper classes.
8
+
Helper is the core concept of CodeceptJS. Helper is a wrapper on top of various libraries providing unified interface around them. When `I` object is used in tests it delegates execution of its functions to currently enabled helper classes.
9
9
10
10
Use Helpers to introduce low-level API to your tests without polluting test scenarios. Helpers can also be used to share functionality across different project and installed as npm packages.
11
11
@@ -34,10 +34,9 @@ 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
+
constHelper=require('@codeceptjs/helper')
38
38
39
39
classMyHelperextendsHelper {
40
-
41
40
// before/after hooks
42
41
_before() {
43
42
// remove if not used
@@ -50,48 +49,43 @@ class MyHelper extends Helper {
50
49
// add custom methods here
51
50
// If you need to access other helpers
52
51
// use: this.helpers['helperName']
53
-
54
52
}
55
53
56
-
module.exports= MyHelper;
54
+
module.exports= MyHelper
57
55
```
58
56
59
57
When the helper is enabled in config all methods of a helper class are available in `I` object.
60
58
For instance, if we add a new method to helper class:
61
59
62
60
```js
63
-
constHelper=require('@codeceptjs/helper');
61
+
constHelper=require('@codeceptjs/helper')
64
62
65
63
classMyHelperextendsHelper {
66
-
67
64
doAwesomeThings() {
68
-
console.log('Hello from MyHelpr');
65
+
console.log('Hello from MyHelpr')
69
66
}
70
-
71
67
}
72
68
```
73
69
74
70
We can call a new method from within `I`:
75
71
76
72
```js
77
-
I.doAwesomeThings();
73
+
I.doAwesomeThings()
78
74
```
79
75
80
76
> Methods starting with `_` are considered special and won't available in `I` object.
81
77
82
-
83
-
Please note, `I` object can't be used helper class. As `I` object delegates its calls to helper classes, you can't make a circular dependency on it. Instead of calling `I` inside a helper, you can get access to other helpers by using `helpers` property of a helper. This allows you to access any other enabled helper by its name.
78
+
Please note, `I` object can't be used helper class. As `I` object delegates its calls to helper classes, you can't make a circular dependency on it. Instead of calling `I` inside a helper, you can get access to other helpers by using `helpers` property of a helper. This allows you to access any other enabled helper by its name.
84
79
85
80
For instance, to perform a click with Playwright helper, do it like this:
86
81
87
82
```js
88
83
doAwesomeThingsWithPlaywright() {
89
84
const { Playwright } =this.helpers;
90
-
Playwright.click('Awesome');
85
+
Playwright.click('Awesome');
91
86
}
92
87
```
93
88
94
-
95
89
After a custom helper is finished you can update CodeceptJS Type Definitions by running:
96
90
97
91
```sh
@@ -185,16 +179,16 @@ constructor(config) {
185
179
Helpers may contain several hooks you can use to handle events of a test.
186
180
Implement corresponding methods to them.
187
181
188
-
*`_init` - before all tests
189
-
*`_finishTest` - after all tests
190
-
*`_before` - before a test
191
-
*`_after` - after a test
192
-
*`_beforeStep` - before each step
193
-
*`_afterStep` - after each step
194
-
*`_beforeSuite` - before each suite
195
-
*`_afterSuite` - after each suite
196
-
*`_passed` - after a test passed
197
-
*`_failed` - after a test failed
182
+
-`_init` - before all tests
183
+
-`_finishTest` - after all tests
184
+
-`_before` - before a test
185
+
-`_after` - after a test
186
+
-`_beforeStep` - before each step
187
+
-`_afterStep` - after each step
188
+
-`_beforeSuite` - before each suite
189
+
-`_afterSuite` - after each suite
190
+
-`_passed` - after a test passed
191
+
-`_failed` - after a test failed
198
192
199
193
Each implemented method should return a value as they will be added to global promise chain as well.
200
194
@@ -225,22 +219,20 @@ Retry rules are available in array `recorder.retries`. The last retry rule can b
225
219
226
220
With Typescript, just simply replacing `module.exports` with `export` for autocompletion.
227
221
228
-
229
222
## Helper Examples
230
223
231
224
### Playwright Example
232
225
233
226
In this example we take the power of Playwright to change geolocation in our tests:
awaitbrowserContext.setGeolocation({ longitude, latitude });
243
-
awaitPlaywright.refreshPage();
233
+
const { browserContext } =this.helpers.Playwright
234
+
awaitbrowserContext.setGeolocation({ longitude, latitude })
235
+
awaitPlaywright.refreshPage()
244
236
}
245
237
}
246
238
```
@@ -250,10 +242,10 @@ class MyHelper extends Helper {
250
242
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).
251
243
252
244
```js
253
-
constHelper=require('@codeceptjs/helper');
245
+
constHelper=require('@codeceptjs/helper')
254
246
255
247
// use any assertion library you like
256
-
constassert=require('assert');
248
+
constassert=require('assert')
257
249
258
250
classMyHelperextendsHelper {
259
251
/**
@@ -262,45 +254,43 @@ class MyHelper extends Helper {
262
254
asyncseeAuthentication() {
263
255
// access current browser of WebDriver helper
264
256
const { WebDriver } =this.helpers
265
-
const { browser } = WebDriver;
257
+
const { browser } = WebDriver
266
258
267
259
// get all cookies according to https://webdriver.io/api/protocol/cookie.html
268
260
// any helper method should return a value in order to be added to promise chain
269
-
constres=awaitbrowser.cookie();
261
+
constres=awaitbrowser.cookie()
270
262
// get values
271
-
let cookies =res.value;
263
+
let cookies =res.value
272
264
for (let k in cookies) {
273
265
// check for a cookie
274
-
if (cookies[k].name!='logged_in') continue;
275
-
assert.equal(cookies[k].value, 'yes');
276
-
return;
266
+
if (cookies[k].name!='logged_in') continue
267
+
assert.equal(cookies[k].value, 'yes')
268
+
return
277
269
}
278
-
assert.fail(cookies, 'logged_in', "Auth cookie not set");
270
+
assert.fail(cookies, 'logged_in', 'Auth cookie not set')
279
271
}
280
272
}
281
273
282
-
module.exports= MyHelper;
274
+
module.exports= MyHelper
283
275
```
284
276
285
277
### Puppeteer Example
286
278
287
-
Puppeteer has [nice and elegant API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md) which you can use inside helpers. Accessing `page` instance via `this.helpers.Puppeteer.page` from inside a helper.
279
+
Puppeteer has [nice and elegant API](https://github.com/puppeteer/puppeteer/blob/main/docs/api/index.md) which you can use inside helpers. Accessing `page` instance via `this.helpers.Puppeteer.page` from inside a helper.
288
280
289
-
Let's see how we can use [emulate](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulateoptions) function to emulate iPhone browser in a test.
281
+
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.
0 commit comments