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
From the graphical representation, you can see that we returned our text, although the browser's address bar shows we navigated to _google.com._ Also, it's clear that we didn't mock the favicon, which was fetched from an external source. We can write this same example using the puppeteer API. For this, _webdriverio_ has the [getPuppeteer()][get-puppeteer] command:
47
47
48
48
```javascript
49
-
it("should mock google.com using puppeteer api", asyncfunction ({browser}) {
49
+
it("should mock google.com using puppeteer api", asyncfunction ({browser}) {
50
50
// Get puppeteer instance
51
51
constpuppeteer=awaitbrowser.getPuppeteer();
52
52
@@ -78,7 +78,7 @@ it("should mock google.com using puppeteer api", async function ({browser}) {
78
78
Now, let's imagine that puppeteer doesn't yet have an API for mocking requests, but this is already implemented in the [Fetch][fetch] domain of CDP. In this case, we will use this domain's method by interacting with the CDP session directly. For this, puppeteer has the [CDPSession.send()][cdp-session-send] method:
79
79
80
80
```javascript
81
-
it("should mock google.com using cdp fetch domain", asyncfunction ({browser}) {
81
+
it("should mock google.com using cdp fetch domain", asyncfunction ({browser}) {
82
82
// Get puppeteer instance
83
83
constpuppeteer=awaitbrowser.getPuppeteer();
84
84
@@ -122,7 +122,7 @@ Obviously, when using the _webdriverio_ API for mocking requests, the code is mu
122
122
## Example 2: Canceling the Request for Google's Logo {#example_2}
123
123
124
124
```javascript
125
-
it("should abort request to logo on google.com", asyncfunction ({browser}) {
125
+
it("should abort request to logo on google.com", asyncfunction ({browser}) {
@@ -190,7 +190,7 @@ it("should modify response from google.com", async function ({browser}) {
190
190
Additionally, we can modify responses from unknown sources in advance. For example, let's modify all scripts loaded on _google.com:_
191
191
192
192
```javascript
193
-
it("should modify response from google.com", asyncfunction ({browser}) {
193
+
it("should modify response from google.com", asyncfunction ({browser}) {
194
194
// The first argument specifies that we will intercept all requests
195
195
constmock=awaitbrowser.mock("**", {
196
196
headers:headers=> {
@@ -217,7 +217,7 @@ it("should modify response from google.com", async function ({browser}) {
217
217
Let's say we need to collect a list of all URLs loaded on the page. Using this information, we could determine if we have requests for external resources or neighboring services that we do not control. This means they could fail at any time and break our tests. Here's what our code might look like:
218
218
219
219
```javascript
220
-
it("should mock yandex.ru and log all loaded urls", asyncfunction ({browser}) {
220
+
it("should mock yandex.ru and log all loaded urls", asyncfunction ({browser}) {
221
221
// Intercept absolutely all requests
222
222
constmock=awaitbrowser.mock("**");
223
223
@@ -235,7 +235,7 @@ it("should mock yandex.ru and log all loaded urls", async function ({browser}) {
235
235
Most likely, your tests are more complex than these examples and involve various clicks on elements that open in new tabs. In such cases, the previous code will not capture the opening of new tabs or that URLs need to be collected there as well. Therefore, in such cases, you need to use puppeteer's API:
236
236
237
237
```javascript
238
-
it("should mock yandex.ru and log all loaded urls (using puppeteer)", asyncfunction ({browser}) {
238
+
it("should mock yandex.ru and log all loaded urls (using puppeteer)", asyncfunction ({browser}) {
239
239
// Accumulative list of all URLs
240
240
consturls= [];
241
241
@@ -298,7 +298,7 @@ module.exports = {
298
298
"testplane-global-hook": {
299
299
enabled:true,
300
300
301
-
beforeEach:asyncfunction ({browser}) {
301
+
beforeEach:asyncfunction ({browser}) {
302
302
// Check that the browser name starts with "chrome"
303
303
if (!/^chrome$/i.test(browser.capabilities.browserName)) {
Copy file name to clipboardExpand all lines: docs/guides/how-to-manage-cpu-performance.mdx
+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
@@ -18,7 +18,7 @@ The CPU speed on mobile devices is significantly slower than on computers. There
18
18
Let's use this method to slow down CPU speed by 8 times:
19
19
20
20
```javascript
21
-
it("should open yandex.ru with emulation 8x slower CPU", asyncfunction ({browser}) {
21
+
it("should open yandex.ru with emulation 8x slower CPU", asyncfunction ({browser}) {
22
22
// Get puppeteer instance
23
23
constpuppeteer=awaitbrowser.getPuppeteer();
24
24
@@ -39,7 +39,7 @@ Initially, _webdriverio_ did not support the `page.emulateCPUThrottling` method
39
39
However, this limitation could be bypassed using puppeteer's [CDPSession.send()][cdp-session-send] method by sending the browser the [Emulation.setCPUThrottlingRate][emulation-set-cpu-throttling-rate] command via CDP:
40
40
41
41
```javascript
42
-
it("should open yandex.ru with emulation 8x slower CPU", asyncfunction ({browser}) {
42
+
it("should open yandex.ru with emulation 8x slower CPU", asyncfunction ({browser}) {
0 commit comments