Skip to content

Commit 3e9b799

Browse files
authored
fix(docs): update some deprecated links of puppeteer and playwright (#5222)
* fixed: types: PupeteerConfig.waitForNavigation can be an array * restore original formatting * fix Puppeteer links * fixed more links
1 parent 0345fc7 commit 3e9b799

File tree

8 files changed

+1210
-1372
lines changed

8 files changed

+1210
-1372
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,7 +4003,7 @@ This change allows using auto-completion when running a specific test.
40034003
- PageObjects simplified to remove `_init()` extra method. Try updated generators and see [updated guide](https://codecept.io/pageobjects/#pageobject).
40044004
- [Puppeteer] [Multiple sessions](https://codecept.io/acceptance/#multiple-sessions) enabled. Requires Puppeteer >= 1.5
40054005
- [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)
40074007
- `getPageTimeout` config option to set maximum navigation time in milliseconds. Default is 30 seconds.
40084008
- `waitForNavigation` method added. Explicitly waits for navigation to be finished.
40094009
- [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 => {
40874087
- Added Chinese translation ("zh-CN" and "zh-TW") by @TechQuery.
40884088
- Fixed running tests from a different folder specified by `-c` option.
40894089
- [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)
40914091
40924092
## 1.1.7
40934093

docs/changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ This change allows using auto-completion when running a specific test.
38373837
- PageObjects simplified to remove `_init()` extra method. Try updated generators and see [updated guide](https://codecept.io/pageobjects/#pageobject).
38383838
- **[Puppeteer]** [Multiple sessions](https://codecept.io/acceptance/#multiple-sessions) enabled. Requires Puppeteer >= 1.5
38393839
- **[Puppeteer]** Stability improvement. Waits for for `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)
38413841
- `getPageTimeout` config option to set maximum navigation time in milliseconds. Default is 30 seconds.
38423842
- `waitForNavigation` method added. Explicitly waits for navigation to be finished.
38433843
- [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 => {
39213921
- Added Chinese translation ("zh-CN" and "zh-TW") by **[TechQuery](https://github.com/TechQuery)**.
39223922
- Fixed running tests from a different folder specified by `-c` option.
39233923
- **[Puppeteer]** Added support for hash handling in URL 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)
39253925

39263926
## 1.1.7
39273927

docs/custom-helpers.md

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Custom Helpers
55

66
# Extending CodeceptJS With Custom Helpers
77

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.
99

1010
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.
1111

@@ -34,10 +34,9 @@ Helpers are classes inherited from [corresponding abstract class](https://github
3434
Created helper file should look like this:
3535

3636
```js
37-
const Helper = require('@codeceptjs/helper');
37+
const Helper = require('@codeceptjs/helper')
3838

3939
class MyHelper extends Helper {
40-
4140
// before/after hooks
4241
_before() {
4342
// remove if not used
@@ -50,48 +49,43 @@ class MyHelper extends Helper {
5049
// add custom methods here
5150
// If you need to access other helpers
5251
// use: this.helpers['helperName']
53-
5452
}
5553

56-
module.exports = MyHelper;
54+
module.exports = MyHelper
5755
```
5856

5957
When the helper is enabled in config all methods of a helper class are available in `I` object.
6058
For instance, if we add a new method to helper class:
6159

6260
```js
63-
const Helper = require('@codeceptjs/helper');
61+
const Helper = require('@codeceptjs/helper')
6462

6563
class MyHelper extends Helper {
66-
6764
doAwesomeThings() {
68-
console.log('Hello from MyHelpr');
65+
console.log('Hello from MyHelpr')
6966
}
70-
7167
}
7268
```
7369

7470
We can call a new method from within `I`:
7571

7672
```js
77-
I.doAwesomeThings();
73+
I.doAwesomeThings()
7874
```
7975

8076
> Methods starting with `_` are considered special and won't available in `I` object.
8177
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.
8479

8580
For instance, to perform a click with Playwright helper, do it like this:
8681

8782
```js
8883
doAwesomeThingsWithPlaywright() {
8984
const { Playwright } = this.helpers;
90-
Playwright.click('Awesome');
85+
Playwright.click('Awesome');
9186
}
9287
```
9388

94-
9589
After a custom helper is finished you can update CodeceptJS Type Definitions by running:
9690

9791
```sh
@@ -185,16 +179,16 @@ constructor(config) {
185179
Helpers may contain several hooks you can use to handle events of a test.
186180
Implement corresponding methods to them.
187181

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
198192

199193
Each implemented method should return a value as they will be added to global promise chain as well.
200194

@@ -225,22 +219,20 @@ Retry rules are available in array `recorder.retries`. The last retry rule can b
225219

226220
With Typescript, just simply replacing `module.exports` with `export` for autocompletion.
227221

228-
229222
## Helper Examples
230223

231224
### Playwright Example
232225

233226
In this example we take the power of Playwright to change geolocation in our tests:
234227

235228
```js
236-
const Helper = require('@codeceptjs/helper');
229+
const Helper = require('@codeceptjs/helper')
237230

238231
class MyHelper extends Helper {
239-
240232
async setGeoLocation(longitude, latitude) {
241-
const { browserContext } = this.helpers.Playwright;
242-
await browserContext.setGeolocation({ longitude, latitude });
243-
await Playwright.refreshPage();
233+
const { browserContext } = this.helpers.Playwright
234+
await browserContext.setGeolocation({ longitude, latitude })
235+
await Playwright.refreshPage()
244236
}
245237
}
246238
```
@@ -250,10 +242,10 @@ class MyHelper extends Helper {
250242
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).
251243

252244
```js
253-
const Helper = require('@codeceptjs/helper');
245+
const Helper = require('@codeceptjs/helper')
254246

255247
// use any assertion library you like
256-
const assert = require('assert');
248+
const assert = require('assert')
257249

258250
class MyHelper extends Helper {
259251
/**
@@ -262,45 +254,43 @@ class MyHelper extends Helper {
262254
async seeAuthentication() {
263255
// access current browser of WebDriver helper
264256
const { WebDriver } = this.helpers
265-
const { browser } = WebDriver;
257+
const { browser } = WebDriver
266258

267259
// get all cookies according to https://webdriver.io/api/protocol/cookie.html
268260
// any helper method should return a value in order to be added to promise chain
269-
const res = await browser.cookie();
261+
const res = await browser.cookie()
270262
// get values
271-
let cookies = res.value;
263+
let cookies = res.value
272264
for (let k in cookies) {
273265
// 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
277269
}
278-
assert.fail(cookies, 'logged_in', "Auth cookie not set");
270+
assert.fail(cookies, 'logged_in', 'Auth cookie not set')
279271
}
280272
}
281273

282-
module.exports = MyHelper;
274+
module.exports = MyHelper
283275
```
284276

285277
### Puppeteer Example
286278

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.
288280

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.
290282

291283
```js
292-
const Helper = require('@codeceptjs/helper');
293-
const puppeteer = require('puppeteer');
294-
const iPhone = puppeteer.devices['iPhone 6'];
284+
const Helper = require('@codeceptjs/helper')
285+
const puppeteer = require('puppeteer')
286+
const iPhone = puppeteer.devices['iPhone 6']
295287

296288
class MyHelper extends Helper {
297-
298289
async emulateIPhone() {
299-
const { page } = this.helpers.Puppeteer;
300-
await page.emulate(iPhone);
290+
const { page } = this.helpers.Puppeteer
291+
await page.emulate(iPhone)
301292
}
302-
303293
}
304294

305-
module.exports = MyHelper;
295+
module.exports = MyHelper
306296
```

0 commit comments

Comments
 (0)