codeceptjs 2.6.1 → 2.6.2

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.
@@ -1,45 +1,166 @@
1
1
  ---
2
2
  permalink: /helpers/MockRequest
3
- editLink: false
4
3
  sidebar: auto
5
4
  title: MockRequest
6
5
  ---
7
6
 
7
+ # MockRequest
8
+
9
+
8
10
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
11
 
10
12
  ## MockRequest
11
13
 
12
- **Extends Helper**
13
-
14
14
  This helper allows to **mock requests while running tests in Puppeteer or WebDriver**.
15
15
  For instance, you can block calls to 3rd-party services like Google Analytics, CDNs.
16
16
  Another way of using is to emulate requests from server by passing prepared data.
17
17
 
18
- ### Installations
18
+ MockRequest helper works in these [modes][1]:
19
19
 
20
- Requires [Polly.js][1] library by Netflix installed
20
+ - passthrough (default) - mock prefefined HTTP requests
21
+ - record - record all requests into a file
22
+ - replay - replay all recorded requests from a file
23
+
24
+ Combining record/replay modes allows testing websites with large datasets.
25
+
26
+ To use in passthrough mode set rules to mock requests and they will be automatically intercepted and replaced:
27
+
28
+ ```js
29
+ // default mode
30
+ I.mockRequest('GET', '/api/users', '[]');
31
+ ```
32
+
33
+ In record-replay mode start mocking to make HTTP requests recorded/replayed, and stop when you don't need to block requests anymore:
34
+
35
+ ```js
36
+ // record or replay all XHR for /users page
37
+ I.startMocking();
38
+ I.amOnPage('/users');
39
+ I.stopMocking();
40
+ ```
41
+
42
+ ### Installations
21
43
 
22
- npm i @pollyjs/core @pollyjs/adapter-puppeteer --save-dev
44
+ npm i @codeceptjs/mock-request --save-dev
23
45
 
24
46
  Requires Puppeteer helper or WebDriver helper enabled
25
47
 
26
48
  ### Configuration
27
49
 
28
- Just enable helper in config file:
50
+ #### With Puppeteer
51
+
52
+ Enable helper in config file:
29
53
 
30
54
  ```js
31
55
  helpers: {
32
56
  Puppeteer: {
33
57
  // regular Puppeteer config here
34
58
  },
35
- MockRequest: {}
59
+ MockRequestHelper: {
60
+ require: '@codeceptjs/mock-request',
61
+ }
36
62
  }
37
63
  ```
38
64
 
39
- > Partially works with WebDriver helper
40
-
41
65
  [Polly config options][2] can be passed as well:
42
66
 
67
+ ```js
68
+ // sample options
69
+ helpers: {
70
+ MockRequestHelper: {
71
+ require: '@codeceptjs/mock-request',
72
+ mode: record,
73
+ recordIfMissing: true,
74
+ recordFailedRequests: false,
75
+ expiresIn: null,
76
+ persisterOptions: {
77
+ keepUnusedRequests: false
78
+ fs: {
79
+ recordingsDir: './data/requests',
80
+ },
81
+ },
82
+ }
83
+ }
84
+ ```
85
+
86
+ * * *
87
+
88
+ **TROUBLESHOOTING**: Puppeteer does not mock requests in headless mode:
89
+
90
+ Problem: request mocking does not work and in debug mode you see this in output:
91
+
92
+ Access to fetch at {url} from origin {url} has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
93
+
94
+ Solution: update Puppeteer config to include `--disable-web-security` arguments:
95
+
96
+ ```js
97
+ Puppeteer: {
98
+ show: false,
99
+ chrome: {
100
+ args: [
101
+ '--disable-web-security',
102
+ ],
103
+ },
104
+ },
105
+ ```
106
+
107
+ * * *
108
+
109
+ #### With WebDriver
110
+
111
+ This helper partially works with WebDriver. It can intercept and mock requests **only on already loaded page**.
112
+
113
+ ```js
114
+ helpers: {
115
+ WebDriver: {
116
+ // regular WebDriver config here
117
+ },
118
+ MockRequestHelper: {
119
+ require: '@codeceptjs/mock-request',
120
+ }
121
+ }
122
+ ```
123
+
124
+ > Record/Replay mode is not tested in WebDriver but technically can work with [REST Persister][3]
125
+
126
+ ## Usage
127
+
128
+ ### 👻 Mock Requests
129
+
130
+ To intercept API requests and mock them use following API
131
+
132
+ - [startMocking()][4] - to enable request interception
133
+ - [mockRequest()][5] - to define mock in a simple way
134
+ - [mockServer()][6] - to use PollyJS server API to define complex mocks
135
+ - [stopMocking()][7] - to stop intercepting requests and disable mocks.
136
+
137
+ Calling `mockRequest` or `mockServer` will start mocking, if it was not enabled yet.
138
+
139
+ ```js
140
+ I.startMocking(); // optionally
141
+ I.mockRequest('/google-analytics/*path', 200);
142
+ // return an empty successful response
143
+ I.mockRequest('GET', '/api/users', 200);
144
+ // mock users api
145
+ I.mockServer(server => {
146
+ server.get('https://server.com/api/users*').
147
+ intercept((req, res) => { res.status(200).json(users);
148
+ });
149
+ });
150
+ I.click('Get users);
151
+ I.stopMocking();
152
+ ```
153
+
154
+ ### 📼 Record & Replay
155
+
156
+ > At this moment works only with Puppeteer
157
+
158
+ Record & Replay mode allows you to record all xhr & fetch requests and save them to file.
159
+ On next runs those requests can be replayed.
160
+ By default, it stores all passed requests, but this behavior can be customized with `I.mockServer`
161
+
162
+ Set mode via enironment variable, `replay` mode by default:
163
+
43
164
  ```js
44
165
  // enable replay mode
45
166
  helpers: {
@@ -47,39 +168,52 @@ helpers: {
47
168
  // regular Puppeteer config here
48
169
  },
49
170
  MockRequest: {
50
- mode: 'replay',
171
+ require: '@codeceptjs/mock-request',
172
+ mode: process.env.MOCK_MODE || 'replay',
51
173
  },
52
174
  }
53
175
  ```
54
176
 
55
- ### Usage
177
+ Interactions between `I.startMocking()` and `I.stopMocking()` will be recorded and saved to `data/requests` directory.
56
178
 
57
- Use `I.mockRequest` to intercept and mock requests.
179
+ ```js
180
+ I.startMocking() // record requests under 'Test' name
181
+ I.startMocking('users') // record requests under 'users' name
182
+ ```
58
183
 
59
- ### Parameters
184
+ Use `I.mockServer()` to customize which requests should be recorded and under which name:
60
185
 
61
- - `config`
186
+ ```js
187
+ I.startMocking();
188
+ I.mockServer((server) => {
189
+ // mock request only from ap1.com and api2.com and
190
+ // store recording into two different files
191
+ server.any('https://api1.com/*').passthrough(false).recordingName('api1');
192
+ server.any('https://api2.com/*').passthrough(false).recordingName('api2');
193
+ });
194
+ ```
62
195
 
63
- ### _checkAndStartMocking
196
+ To stop request recording/replaying use `I.stopMocking()`.
64
197
 
65
- Starts mocking if it's not started yet.
198
+ 🎥 To record HTTP interactions execute tests with MOCK_MODE environment variable set as "record":
66
199
 
67
- ### _connectPuppeteer
200
+ MOCK_MODE=record npx codeceptjs run --debug
68
201
 
69
- Creates a polly instance by registering puppeteer adapter with the instance
202
+ 📼 To replay them launch tests without environment variable:
70
203
 
71
- #### Parameters
204
+ npx codeceptjs run --debug
72
205
 
73
- - `title` **any**
206
+ ### Parameters
74
207
 
75
- ### _connectWebDriver
208
+ - `config`
76
209
 
77
- Creates polly object in the browser window context using xhr and fetch adapters,
78
- after loading PollyJs and adapter scripts.
210
+ ### flushMocking
79
211
 
80
- #### Parameters
212
+ Waits for all requests handled by MockRequests to be resolved:
81
213
 
82
- - `title` **any**
214
+ ```js
215
+ I.flushMocking();
216
+ ```
83
217
 
84
218
  ### mockRequest
85
219
 
@@ -100,33 +234,142 @@ I.mockRequest('GET', ['/secrets', '/v2/secrets'], 403);
100
234
 
101
235
  #### Parameters
102
236
 
103
- - `method` **[string][3]** request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`.
104
- - `oneOrMoreUrls` **([string][3] | [Array][4]&lt;[string][3]>)** url(s) to mock. Can be exact URL, a pattern, or an array of URLs.
105
- - `dataOrStatusCode` **([number][5] | [string][3] | [object][6])** status code when number provided. A response body otherwise
106
- - `additionalData` **([string][3] | [object][6])** response body when a status code is set by previous parameter.
237
+ - `method` **[string][8]** request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`.
238
+ - `oneOrMoreUrls` **([string][8] \| [Array][9]&lt;[string][8]>)** url(s) to mock. Can be exact URL, a pattern, or an array of URLs.
239
+ - `dataOrStatusCode` **([number][10] \| [string][8] \| [object][11])** status code when number provided. A response body otherwise
240
+ - `additionalData` **([string][8] \| [object][11])** response body when a status code is set by previous parameter. (optional, default `null`)
241
+
242
+ ### mockServer
243
+
244
+ Use PollyJS [Server Routes API][12] to declare mocks via callback function:
245
+
246
+ ```js
247
+ // basic usage
248
+ server.get('/api/v2/users').intercept((req, res) => {
249
+ res.sendStatus(200).json({ users });
250
+ });
251
+
252
+ // passthrough requests to "/api/v2"
253
+ server.get('/api/v1').passthrough();
254
+ ```
255
+
256
+ In record replay mode you can define which routes should be recorded and where to store them:
257
+
258
+ ```js
259
+ I.startMocking('mock');
260
+ I.mockServer((server) => {
261
+
262
+ // record requests from cdn1.com and save them to data/recording/xml
263
+ server.any('https://cdn1.com/*').passthrough(false).recordingName('xml');
264
+
265
+ // record requests from cdn2.com and save them to data/recording/svg
266
+ server.any('https://cdn2.com/*').passthrough(false).recordingName('svg');
267
+
268
+ // record requests from /api and save them to data/recording/mock (default)
269
+ server.any('/api/*').passthrough(false);
270
+ });
271
+ ```
272
+
273
+ #### Parameters
274
+
275
+ - `configFn`
276
+
277
+ ### passthroughMocking
278
+
279
+ Forces passthrough mode for mocking.
280
+ Requires mocking to be started.
281
+
282
+ ```js
283
+ I.passthroughMocking();
284
+ ```
285
+
286
+ ### recordMocking
287
+
288
+ Forces record mode for mocking.
289
+ Requires mocking to be started.
290
+
291
+ ```js
292
+ I.recordMocking();
293
+ ```
294
+
295
+ ### replayMocking
296
+
297
+ Forces replay mode for mocking.
298
+ Requires mocking to be started.
299
+
300
+ ```js
301
+ I.replayMocking();
302
+ ```
107
303
 
108
304
  ### startMocking
109
305
 
110
306
  Starts mocking of http requests.
111
- Used by mockRequest method to automatically start
112
- mocking requests.
307
+ In record mode starts recording of all requests.
308
+ In replay mode blocks all requests and replaces them with saved.
309
+
310
+ If inside one test you plan to record/replay requests in several places, provide [recording name][13] as the parameter.
311
+
312
+ ```js
313
+ // start mocking requests for a test
314
+ I.startMocking();
315
+
316
+ // start mocking requests for main page
317
+ I.startMocking('main-page');
318
+ // do actions
319
+ I.stopMocking();
320
+ I.startMocking('login-page');
321
+ ```
322
+
323
+ To update [PollyJS configuration][14] use secon argument:
324
+
325
+ ```js
326
+ // change mode
327
+ I.startMocking('comments', { mode: 'replay' });
328
+
329
+ // override config
330
+ I.startMocking('users-loaded', {
331
+ recordFailedRequests: true
332
+ })
333
+ ```
113
334
 
114
335
  #### Parameters
115
336
 
116
- - `title` **any**
337
+ - `title` **any** (optional, default `'Test'`)
338
+ - `config` (optional, default `{}`)
117
339
 
118
340
  ### stopMocking
119
341
 
120
342
  Stops mocking requests.
343
+ Must be called to save recorded requests into faile.
121
344
 
122
- [1]: https://netflix.github.io/pollyjs/#/
345
+ ```js
346
+ I.stopMocking();
347
+ ```
348
+
349
+ [1]: https://netflix.github.io/pollyjs/#/configuration?id=mode
123
350
 
124
351
  [2]: https://netflix.github.io/pollyjs/#/configuration?id=configuration
125
352
 
126
- [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
353
+ [3]: https://netflix.github.io/pollyjs/#/examples?id=rest-persister
354
+
355
+ [4]: #startMocking
356
+
357
+ [5]: #mockRequest
358
+
359
+ [6]: #mockServer
360
+
361
+ [7]: #stopMocking
362
+
363
+ [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
364
+
365
+ [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
366
+
367
+ [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
368
+
369
+ [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
127
370
 
128
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
371
+ [12]: https://netflix.github.io/pollyjs/#/server/overview
129
372
 
130
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
373
+ [13]: https://netflix.github.io/pollyjs/#/api?id=recordingname
131
374
 
132
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
375
+ [14]: https://netflix.github.io/pollyjs/#/configuration
@@ -38,7 +38,7 @@ This helper should be configured in codecept.json or codecept.conf.js
38
38
  - `keepBrowserState`: - keep browser state between tests when `restart` is set to false.
39
39
  - `keepCookies`: - keep cookies between tests when `restart` is set to false.
40
40
  - `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 100.
41
- - `waitForNavigation`: . When to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Playwright API][2]. Array values are accepted as well.
41
+ - `waitForNavigation`: . When to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. Choose one of those options is possible. See [Playwright API][2].
42
42
  - `pressKeyDelay`: . Delay between key presses in ms. Used when calling Playwrights page.type(...) in fillField/appendField
43
43
  - `getPageTimeout` config option to set maximum navigation time in milliseconds.
44
44
  - `waitForTimeout`: (optional) default wait* timeout in ms. Default: 1000.
@@ -63,7 +63,7 @@ This helper should be configured in codecept.json or codecept.conf.js
63
63
  }
64
64
  ```
65
65
 
66
- #### Example #2: Wait for DOMContentLoaded event and 0 network connections
66
+ #### Example #2: Wait for DOMContentLoaded event
67
67
 
68
68
  ```js
69
69
  {
@@ -71,7 +71,7 @@ This helper should be configured in codecept.json or codecept.conf.js
71
71
  Playwright : {
72
72
  url: "http://localhost",
73
73
  restart: false,
74
- waitForNavigation: [ "domcontentloaded", "networkidle0" ],
74
+ waitForNavigation: "domcontentloaded",
75
75
  waitForAction: 500
76
76
  }
77
77
  }
@@ -890,6 +890,24 @@ let email = await I.grabValueFrom('input[name=email]');
890
890
 
891
891
  Returns **[Promise][9]&lt;[string][7]>** attribute value
892
892
 
893
+ ### handleDownloads
894
+
895
+ Handles a file download.Aa file name is required to save the file on disk.
896
+ Files are saved to "output" directory.
897
+
898
+ Should be used with [FileSystem helper][11] to check that file were downloaded correctly.
899
+
900
+ ```js
901
+ I.handleDownloads('downloads/avatar.jpg');
902
+ I.click('Download Avatar');
903
+ I.amInPath('output/downloads');
904
+ I.waitForFile('downloads/avatar.jpg', 5);
905
+ ```
906
+
907
+ #### Parameters
908
+
909
+ - `fileName` **[string][7]?** set filename for downloaded file
910
+
893
911
  ### haveRequestHeaders
894
912
 
895
913
  Set headers for all next requests
@@ -928,7 +946,7 @@ Open new tab and switch to it
928
946
  I.openNewTab();
929
947
  ```
930
948
 
931
- You can pass in [page options][11] to emulate device on this page
949
+ You can pass in [page options][12] to emulate device on this page
932
950
 
933
951
  ```js
934
952
  // enable mobile
@@ -943,7 +961,7 @@ I.openNewTab({ isMobile: true });
943
961
 
944
962
  Presses a key in the browser (on a focused element).
945
963
 
946
- _Hint:_ For populating text field or textarea, it is recommended to use [`fillField`][12].
964
+ _Hint:_ For populating text field or textarea, it is recommended to use [`fillField`][13].
947
965
 
948
966
  ```js
949
967
  I.pressKey('Backspace');
@@ -1002,13 +1020,13 @@ Some of the supported key names are:
1002
1020
 
1003
1021
  #### Parameters
1004
1022
 
1005
- - `key` **([string][7] | [Array][10]&lt;[string][7]>)** key or array of keys to press._Note:_ Shortcuts like `'Meta'` + `'A'` do not work on macOS ([GoogleChrome/Playwright#1313][13]).
1023
+ - `key` **([string][7] | [Array][10]&lt;[string][7]>)** key or array of keys to press._Note:_ Shortcuts like `'Meta'` + `'A'` do not work on macOS ([GoogleChrome/Playwright#1313][14]).
1006
1024
 
1007
1025
  ### pressKeyDown
1008
1026
 
1009
1027
  Presses a key in the browser and leaves it in a down state.
1010
1028
 
1011
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][14]).
1029
+ To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][15]).
1012
1030
 
1013
1031
  ```js
1014
1032
  I.pressKeyDown('Control');
@@ -1024,7 +1042,7 @@ I.pressKeyUp('Control');
1024
1042
 
1025
1043
  Releases a key in the browser which was previously set to a down state.
1026
1044
 
1027
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][14]).
1045
+ To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][15]).
1028
1046
 
1029
1047
  ```js
1030
1048
  I.pressKeyDown('Control');
@@ -1092,7 +1110,7 @@ I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scro
1092
1110
  #### Parameters
1093
1111
 
1094
1112
  - `fileName` **[string][7]** file name to save.
1095
- - `fullPage` **[boolean][15]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1113
+ - `fullPage` **[boolean][16]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1096
1114
 
1097
1115
  ### scrollPageToBottom
1098
1116
 
@@ -1541,7 +1559,7 @@ I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and
1541
1559
 
1542
1560
  #### Parameters
1543
1561
 
1544
- - `fn` **([string][7] | [function][16])** to be executed in browser context.
1562
+ - `fn` **([string][7] | [function][17])** to be executed in browser context.
1545
1563
  - `argsOrSec` **([Array][10]&lt;any> | [number][8])?** (optional, `1` by default) arguments for function or seconds.
1546
1564
  - `sec` **[number][8]?** (optional, `1` by default) time in seconds to wait
1547
1565
 
@@ -1563,7 +1581,7 @@ I.waitForInvisible('#popup');
1563
1581
 
1564
1582
  Waits for navigation to finish. By default takes configured `waitForNavigation` option.
1565
1583
 
1566
- See [Pupeteer's reference][2]
1584
+ See [Pupeteer's reference][18]
1567
1585
 
1568
1586
  #### Parameters
1569
1587
 
@@ -1580,7 +1598,7 @@ I.waitForRequest(request => request.url() === 'http://example.com' && request.me
1580
1598
 
1581
1599
  #### Parameters
1582
1600
 
1583
- - `urlOrPredicate` **([string][7] | [function][16])**
1601
+ - `urlOrPredicate` **([string][7] | [function][17])**
1584
1602
  - `sec` **[number][8]?** seconds to wait
1585
1603
 
1586
1604
  ### waitForResponse
@@ -1594,7 +1612,7 @@ I.waitForResponse(request => request.url() === 'http://example.com' && request.m
1594
1612
 
1595
1613
  #### Parameters
1596
1614
 
1597
- - `urlOrPredicate` **([string][7] | [function][16])**
1615
+ - `urlOrPredicate` **([string][7] | [function][17])**
1598
1616
  - `sec` **[number][8]?** number of seconds to wait
1599
1617
 
1600
1618
  ### waitForText
@@ -1640,7 +1658,7 @@ I.waitForVisible('#popup');
1640
1658
  #### Parameters
1641
1659
 
1642
1660
  - `locator` **([string][7] | [object][5])** element located by CSS|XPath|strict locator.
1643
- - `sec` **[number][8]** (optional, `1` by default) time in seconds to waitThis method accepts [React selectors][17].
1661
+ - `sec` **[number][8]** (optional, `1` by default) time in seconds to waitThis method accepts [React selectors][19].
1644
1662
 
1645
1663
  ### waitInUrl
1646
1664
 
@@ -1694,7 +1712,7 @@ I.waitUntil(() => window.requests == 0, 5);
1694
1712
 
1695
1713
  #### Parameters
1696
1714
 
1697
- - `fn` **([function][16] | [string][7])** function which is executed in browser context.
1715
+ - `fn` **([function][17] | [string][7])** function which is executed in browser context.
1698
1716
  - `sec` **[number][8]** (optional, `1` by default) time in seconds to wait
1699
1717
  - `timeoutMsg` **[string][7]** message to show in case of timeout fail.
1700
1718
  - `interval` **[number][8]?**
@@ -1715,7 +1733,7 @@ I.waitUrlEquals('http://127.0.0.1:8000/info');
1715
1733
 
1716
1734
  [1]: https://github.com/microsoft/playwright
1717
1735
 
1718
- [2]: https://github.com/GoogleChrome/Playwright/blob/master/docs/api.md#pagewaitfornavigationoptions
1736
+ [2]: https://github.com/microsoft/playwright/blob/master/docs/api.md#pagewaitfornavigationoptions
1719
1737
 
1720
1738
  [3]: https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target
1721
1739
 
@@ -1733,16 +1751,20 @@ I.waitUrlEquals('http://127.0.0.1:8000/info');
1733
1751
 
1734
1752
  [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
1735
1753
 
1736
- [11]: https://github.com/microsoft/playwright/blob/v0.12.1/docs/api.md#browsernewpageoptions
1754
+ [11]: https://codecept.io/helpers/FileSystem
1755
+
1756
+ [12]: https://github.com/microsoft/playwright/blob/v0.12.1/docs/api.md#browsernewpageoptions
1757
+
1758
+ [13]: #fillfield
1737
1759
 
1738
- [12]: #fillfield
1760
+ [14]: https://github.com/GoogleChrome/Playwright/issues/1313
1739
1761
 
1740
- [13]: https://github.com/GoogleChrome/Playwright/issues/1313
1762
+ [15]: #click
1741
1763
 
1742
- [14]: #click
1764
+ [16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
1743
1765
 
1744
- [15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
1766
+ [17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1745
1767
 
1746
- [16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1768
+ [18]: https://github.com/GoogleChrome/Playwright/blob/master/docs/api.md#pagewaitfornavigationoptions
1747
1769
 
1748
- [17]: https://codecept.io/react
1770
+ [19]: https://codecept.io/react
@@ -696,6 +696,42 @@ I.fillField({css: 'form#login input[name=username]'}, 'John');
696
696
  This action supports [React locators](https://codecept.io/react#locators)
697
697
 
698
698
 
699
+ ### forceClick
700
+
701
+ Perform an emulated click on a link or a button, given by a locator.
702
+ Unlike normal click instead of sending native event, emulates a click with JavaScript.
703
+ This works on hidden, animated or inactive elements as well.
704
+
705
+ If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
706
+ For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
707
+ For images, the "alt" attribute and inner text of any parent links are searched.
708
+
709
+ The second parameter is a context (CSS or XPath locator) to narrow the search.
710
+
711
+ ```js
712
+ // simple link
713
+ I.forceClick('Logout');
714
+ // button of form
715
+ I.forceClick('Submit');
716
+ // CSS button
717
+ I.forceClick('#form input[type=submit]');
718
+ // XPath
719
+ I.forceClick('//form/*[@type=submit]');
720
+ // link in context
721
+ I.forceClick('Logout', '#nav');
722
+ // using strict locator
723
+ I.forceClick({css: 'nav a.login'});
724
+ ```
725
+
726
+ #### Parameters
727
+
728
+ - `locator` **([string][8] | [object][6])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
729
+ - `context` **([string][8]? | [object][6])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
730
+
731
+
732
+ This action supports [React locators](https://codecept.io/react#locators)
733
+
734
+
699
735
  ### grabAttributeFrom
700
736
 
701
737
  Retrieves an attribute from an element located by CSS or XPath and returns it to test.
@@ -391,12 +391,14 @@ this.helpers['WebDriver']._locateCheckable('I agree with terms and conditions').
391
391
  Find a clickable element by providing human readable text:
392
392
 
393
393
  ```js
394
- this.helpers['WebDriver']._locateClickable('Next page').then // ...
394
+ const els = await this.helpers.WebDriver._locateClickable('Next page');
395
+ const els = await this.helpers.WebDriver._locateClickable('Next page', '.pages');
395
396
  ```
396
397
 
397
398
  #### Parameters
398
399
 
399
400
  - `locator` **([string][19] | [object][18])** element located by CSS|XPath|strict locator.
401
+ - `context`
400
402
 
401
403
  ### _locateFields
402
404
 
@@ -873,6 +875,42 @@ I.fillField({css: 'form#login input[name=username]'}, 'John');
873
875
  This action supports [React locators](https://codecept.io/react#locators)
874
876
 
875
877
 
878
+ ### forceClick
879
+
880
+ Perform an emulated click on a link or a button, given by a locator.
881
+ Unlike normal click instead of sending native event, emulates a click with JavaScript.
882
+ This works on hidden, animated or inactive elements as well.
883
+
884
+ If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
885
+ For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
886
+ For images, the "alt" attribute and inner text of any parent links are searched.
887
+
888
+ The second parameter is a context (CSS or XPath locator) to narrow the search.
889
+
890
+ ```js
891
+ // simple link
892
+ I.forceClick('Logout');
893
+ // button of form
894
+ I.forceClick('Submit');
895
+ // CSS button
896
+ I.forceClick('#form input[type=submit]');
897
+ // XPath
898
+ I.forceClick('//form/*[@type=submit]');
899
+ // link in context
900
+ I.forceClick('Logout', '#nav');
901
+ // using strict locator
902
+ I.forceClick({css: 'nav a.login'});
903
+ ```
904
+
905
+ #### Parameters
906
+
907
+ - `locator` **([string][19] | [object][18])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
908
+ - `context` **([string][19]? | [object][18])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
909
+
910
+
911
+ This action supports [React locators](https://codecept.io/react#locators)
912
+
913
+
876
914
  ### grabAllWindowHandles
877
915
 
878
916
  Get all Window Handles.