webdriverio 8.22.0 → 8.23.0

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.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/build/commands/browser/$$.d.ts +2 -2
  3. package/build/commands/browser/$$.d.ts.map +1 -1
  4. package/build/commands/browser/custom$$.d.ts +2 -3
  5. package/build/commands/browser/custom$$.d.ts.map +1 -1
  6. package/build/commands/browser/custom$$.js +1 -1
  7. package/build/commands/browser/custom$.js +1 -1
  8. package/build/commands/browser/emulate.d.ts +59 -0
  9. package/build/commands/browser/emulate.d.ts.map +1 -0
  10. package/build/commands/browser/emulate.js +127 -0
  11. package/build/commands/browser/react$$.d.ts +2 -2
  12. package/build/commands/browser/react$$.d.ts.map +1 -1
  13. package/build/commands/browser/saveScreenshot.d.ts.map +1 -1
  14. package/build/commands/browser/saveScreenshot.js +2 -4
  15. package/build/commands/browser/throttle.d.ts +4 -1
  16. package/build/commands/browser/throttle.d.ts.map +1 -1
  17. package/build/commands/browser/throttle.js +7 -137
  18. package/build/commands/browser/throttleCPU.d.ts +25 -0
  19. package/build/commands/browser/throttleCPU.d.ts.map +1 -0
  20. package/build/commands/browser/throttleCPU.js +41 -0
  21. package/build/commands/browser/throttleNetwork.d.ts +3 -0
  22. package/build/commands/browser/throttleNetwork.d.ts.map +1 -0
  23. package/build/commands/browser/throttleNetwork.js +145 -0
  24. package/build/commands/browser/url.js +2 -2
  25. package/build/commands/browser.d.ts +3 -0
  26. package/build/commands/browser.d.ts.map +1 -1
  27. package/build/commands/browser.js +3 -0
  28. package/build/commands/element/click.d.ts.map +1 -1
  29. package/build/commands/element/click.js +40 -17
  30. package/build/commands/element/custom$$.d.ts +1 -2
  31. package/build/commands/element/custom$$.d.ts.map +1 -1
  32. package/build/commands/element/custom$.js +1 -1
  33. package/build/commands/element/getCSSProperty.d.ts +7 -5
  34. package/build/commands/element/getCSSProperty.d.ts.map +1 -1
  35. package/build/commands/element/getCSSProperty.js +55 -18
  36. package/build/commands/element/moveTo.d.ts.map +1 -1
  37. package/build/commands/element/moveTo.js +25 -14
  38. package/build/commands/element/react$$.d.ts +1 -1
  39. package/build/commands/element/react$$.d.ts.map +1 -1
  40. package/build/commands/element/shadow$$.d.ts +1 -2
  41. package/build/commands/element/shadow$$.d.ts.map +1 -1
  42. package/build/multiremote.d.ts +2 -2
  43. package/build/multiremote.d.ts.map +1 -1
  44. package/build/types.d.ts +38 -5
  45. package/build/types.d.ts.map +1 -1
  46. package/build/utils/findStrategy.d.ts.map +1 -1
  47. package/build/utils/findStrategy.js +12 -7
  48. package/build/utils/getElementObject.d.ts +2 -2
  49. package/build/utils/getElementObject.d.ts.map +1 -1
  50. package/build/utils/index.d.ts +2 -2
  51. package/build/utils/index.d.ts.map +1 -1
  52. package/package.json +7 -7
package/README.md CHANGED
@@ -3,7 +3,7 @@ WebdriverIO
3
3
 
4
4
  > Next-gen browser and mobile automation test framework for Node.js
5
5
 
6
- This package provides an easy to manage API and a lot of syntactical sugar on top of the WebDriver specification. You can use WebdriverIO as a standalone package or via a testrunner using [`@wdio/cli`](https://webdriver.io/docs/clioptions). WebdriverIO allows to run tests locally using the WebDriver or Chrome DevTools protocol as well as remote user agents using cloud providers like [Sauce Labs](https://saucelabs.com/).
6
+ This package provides an easy-to-manage API and a lot of syntactical sugar on top of the WebDriver specification. You can use WebdriverIO as a standalone package or via a test runner using [`@wdio/cli`](https://webdriver.io/docs/clioptions). WebdriverIO allows you to run tests locally using the WebDriver or Chrome DevTools protocol as well as remote user agents using cloud providers like [Sauce Labs](https://saucelabs.com/).
7
7
 
8
8
  ## Installation
9
9
 
@@ -44,6 +44,6 @@ let browser
44
44
  })
45
45
  ```
46
46
 
47
- See the raw [protocol example](https://www.npmjs.com/package/webdriver#example) using the `webdriver` package to get a glance on the differences.
47
+ See the raw [protocol example](https://www.npmjs.com/package/webdriver#example) using the `webdriver` package to get a glance at the differences.
48
48
 
49
49
  For more information on [options](https://webdriver.io/docs/options#webdriver-options), [multiremote usage](https://webdriver.io/docs/multiremote) or integration into [cloud services](https://webdriver.io/docs/cloudservices) please check out the [docs](https://webdriver.io/docs/gettingstarted).
@@ -1,5 +1,5 @@
1
1
  import type { ElementReference } from '@wdio/protocols';
2
- import type { Selector, ElementArray } from '../../types.js';
2
+ import type { Selector } from '../../types.js';
3
3
  /**
4
4
  * The `$$` command is a short and handy way in order to fetch multiple elements on the page.
5
5
  * It returns a `ChainablePromiseArray` containing a set of WebdriverIO elements.
@@ -40,5 +40,5 @@ import type { Selector, ElementArray } from '../../types.js';
40
40
  * @type utility
41
41
  *
42
42
  */
43
- export declare function $$(this: WebdriverIO.Browser | WebdriverIO.Element, selector: Selector | ElementReference[] | WebdriverIO.Element[] | HTMLElement[]): Promise<ElementArray>;
43
+ export declare function $$(this: WebdriverIO.Browser | WebdriverIO.Element, selector: Selector | ElementReference[] | WebdriverIO.Element[] | HTMLElement[]): Promise<WebdriverIO.ElementArray>;
44
44
  //# sourceMappingURL=$$.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/$$.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,EAAE,CACpB,IAAI,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,EAC/C,QAAQ,EAAE,QAAQ,GAAG,gBAAgB,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,WAAW,EAAE,yBAkBlF"}
1
+ {"version":3,"file":"$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/$$.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,EAAE,CACpB,IAAI,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,EAC/C,QAAQ,EAAE,QAAQ,GAAG,gBAAgB,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,WAAW,EAAE,qCAkBlF"}
@@ -1,4 +1,3 @@
1
- import type { ElementArray } from '../../types.js';
2
1
  /**
3
2
  *
4
3
  * The `customs$$` allows you to use a custom strategy declared by using `browser.addLocatorStrategy`.
@@ -21,7 +20,7 @@ import type { ElementArray } from '../../types.js';
21
20
  * @alias custom$$
22
21
  * @param {string} strategyName
23
22
  * @param {*} strategyArguments
24
- * @return {ElementArray}
23
+ * @return {WebdriverIO.ElementArray}
25
24
  */
26
- export declare function custom$$(this: WebdriverIO.Browser, strategyName: string, ...strategyArguments: any[]): Promise<ElementArray>;
25
+ export declare function custom$$(this: WebdriverIO.Browser, strategyName: string, ...strategyArguments: any[]): Promise<WebdriverIO.ElementArray>;
27
26
  //# sourceMappingURL=custom$$.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/custom$$.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAmD,MAAM,gBAAgB,CAAA;AAEnG;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,QAAQ,CAC1B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,iBAAiB,EAAE,GAAG,EAAE,GAC5B,OAAO,CAAC,YAAY,CAAC,CAuBvB"}
1
+ {"version":3,"file":"custom$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/custom$$.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,QAAQ,CAC1B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,iBAAiB,EAAE,GAAG,EAAE,GAC5B,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAuBnC"}
@@ -23,7 +23,7 @@ import { ELEMENT_KEY } from '../../constants.js';
23
23
  * @alias custom$$
24
24
  * @param {string} strategyName
25
25
  * @param {*} strategyArguments
26
- * @return {ElementArray}
26
+ * @return {WebdriverIO.ElementArray}
27
27
  */
28
28
  export async function custom$$(strategyName, ...strategyArguments) {
29
29
  const strategy = this.strategies.get(strategyName);
@@ -45,5 +45,5 @@ export async function custom$(strategyName, ...strategyArguments) {
45
45
  if (res && typeof res[ELEMENT_KEY] === 'string') {
46
46
  return await getElement.call(this, strategyRef, res);
47
47
  }
48
- throw Error('Your locator strategy script must return an element');
48
+ return await getElement.call(this, strategyRef, new Error('no such element'));
49
49
  }
@@ -0,0 +1,59 @@
1
+ type SupportedScopes = 'geolocation' | 'userAgent' | 'colorScheme' | 'onLine';
2
+ interface EmulationOptions {
3
+ geolocation: Partial<GeolocationCoordinates>;
4
+ userAgent: string;
5
+ colorScheme: 'light' | 'dark';
6
+ onLine: boolean;
7
+ }
8
+ /**
9
+ * WebdriverIO allows you to emulate Web APIs using the `emulate` command. These Web APIs can then
10
+ * behave exactly as you specify it.
11
+ *
12
+ * Read more on this in the [Emulation](/docs/emulation) guidelines.
13
+ *
14
+ * :::info
15
+ *
16
+ * This feature requires WebDriver Bidi support for the browser. While recent versions of Chrome, Edge
17
+ * and Firefox have such support, Safari __does not__. For updates follow [wpt.fyi](https://wpt.fyi/results/webdriver/tests/bidi/script/add_preload_script/add_preload_script.py?label=experimental&label=master&aligned).
18
+ * Furthermore if you use a cloud vendor for spawning browsers, make sure your vendor also supports WebDriver Bidi.
19
+ *
20
+ * :::
21
+ *
22
+ * <example>
23
+ :emulateColorScheme.js
24
+ it('should open WebdriverIO using light color scheme', async () => {
25
+ await browser.emulate('colorScheme', 'light')
26
+ await browser.url('https://webdriver.io')
27
+ const backgroundColor = await browser.$('nav').getCSSProperty('background-color')
28
+ console.log(backgroundColor.parsed.hex) // outputs: "#efefef"
29
+ })
30
+ it('should open WebdriverIO using dark color scheme'm async () => {
31
+ await browser.emulate('colorScheme', 'dark')
32
+ await browser.url('https://webdriver.io')
33
+ const backgroundColor = await browser.$('nav').getCSSProperty('background-color')
34
+ console.log(backgroundColor.parsed.hex) // outputs: "#000000"
35
+ })
36
+ * </example>
37
+ *
38
+ * <example>
39
+ :emulateGeoLocation.js
40
+ it('should find my emulated geo location', async () => {
41
+ await browser.emulate('geolocation', {
42
+ latitude: 52.52,
43
+ longitude: 13.39,
44
+ accuracy: 100
45
+ })
46
+ await browser.url('https://www.google.com/maps')
47
+ await browser.$('aria/Show Your Location').click()
48
+ await browser.pause(5000)
49
+ console.log(await browser.getUrl()) // outputs: "https://www.google.com/maps/@52.52,13.39,16z?entry=ttu"
50
+ })
51
+ * </example>
52
+ *
53
+ * @param {string} scope feature of the browser you like to emulate, can be either `geolocation`, `userAgent`, `colorScheme` or `onLine`
54
+ * @param {EmulationOptions} options emulation option for specific scope
55
+ * @returns `void`
56
+ */
57
+ export declare function emulate<Scope extends SupportedScopes>(this: WebdriverIO.Browser, scope: Scope, options: EmulationOptions[Scope]): Promise<void>;
58
+ export {};
59
+ //# sourceMappingURL=emulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emulate.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/emulate.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAA;AAE7E,UAAU,gBAAgB;IACtB,WAAW,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,GAAG,MAAM,CAAA;IAC7B,MAAM,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAsB,OAAO,CAAC,KAAK,SAAS,eAAe,EACvD,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,iBAuFnC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * WebdriverIO allows you to emulate Web APIs using the `emulate` command. These Web APIs can then
3
+ * behave exactly as you specify it.
4
+ *
5
+ * Read more on this in the [Emulation](/docs/emulation) guidelines.
6
+ *
7
+ * :::info
8
+ *
9
+ * This feature requires WebDriver Bidi support for the browser. While recent versions of Chrome, Edge
10
+ * and Firefox have such support, Safari __does not__. For updates follow [wpt.fyi](https://wpt.fyi/results/webdriver/tests/bidi/script/add_preload_script/add_preload_script.py?label=experimental&label=master&aligned).
11
+ * Furthermore if you use a cloud vendor for spawning browsers, make sure your vendor also supports WebDriver Bidi.
12
+ *
13
+ * :::
14
+ *
15
+ * <example>
16
+ :emulateColorScheme.js
17
+ it('should open WebdriverIO using light color scheme', async () => {
18
+ await browser.emulate('colorScheme', 'light')
19
+ await browser.url('https://webdriver.io')
20
+ const backgroundColor = await browser.$('nav').getCSSProperty('background-color')
21
+ console.log(backgroundColor.parsed.hex) // outputs: "#efefef"
22
+ })
23
+ it('should open WebdriverIO using dark color scheme'm async () => {
24
+ await browser.emulate('colorScheme', 'dark')
25
+ await browser.url('https://webdriver.io')
26
+ const backgroundColor = await browser.$('nav').getCSSProperty('background-color')
27
+ console.log(backgroundColor.parsed.hex) // outputs: "#000000"
28
+ })
29
+ * </example>
30
+ *
31
+ * <example>
32
+ :emulateGeoLocation.js
33
+ it('should find my emulated geo location', async () => {
34
+ await browser.emulate('geolocation', {
35
+ latitude: 52.52,
36
+ longitude: 13.39,
37
+ accuracy: 100
38
+ })
39
+ await browser.url('https://www.google.com/maps')
40
+ await browser.$('aria/Show Your Location').click()
41
+ await browser.pause(5000)
42
+ console.log(await browser.getUrl()) // outputs: "https://www.google.com/maps/@52.52,13.39,16z?entry=ttu"
43
+ })
44
+ * </example>
45
+ *
46
+ * @param {string} scope feature of the browser you like to emulate, can be either `geolocation`, `userAgent`, `colorScheme` or `onLine`
47
+ * @param {EmulationOptions} options emulation option for specific scope
48
+ * @returns `void`
49
+ */
50
+ export async function emulate(scope, options) {
51
+ if (!this.isBidi) {
52
+ throw new Error('emulate command is only supported for Bidi');
53
+ }
54
+ if (scope === 'geolocation') {
55
+ if (!options) {
56
+ throw new Error('Missing geolocation emulation options');
57
+ }
58
+ const patchedFn = options instanceof Error
59
+ ? `cbError(new Error(${JSON.stringify(options.message)}))`
60
+ : `cbSuccess({
61
+ coords: ${JSON.stringify(options)},
62
+ timestamp: Date.now()
63
+ })`;
64
+ await this.scriptAddPreloadScript({
65
+ functionDeclaration: /*js*/ `() => {
66
+ Object.defineProperty(navigator.geolocation, 'getCurrentPosition', {
67
+ value: (cbSuccess, cbError) => ${patchedFn}
68
+ })
69
+ }`
70
+ });
71
+ return;
72
+ }
73
+ if (scope === 'userAgent') {
74
+ if (typeof options !== 'string') {
75
+ throw new Error(`Expected userAgent emulation options to be a string, received ${typeof options}`);
76
+ }
77
+ await this.scriptAddPreloadScript({
78
+ functionDeclaration: /*js*/ `() => {
79
+ Object.defineProperty(navigator, 'userAgent', {
80
+ value: ${JSON.stringify(options)}
81
+ })
82
+ }`
83
+ });
84
+ return;
85
+ }
86
+ if (scope === 'colorScheme') {
87
+ if (options !== 'light' && options !== 'dark') {
88
+ throw new Error(`Expected "colorScheme" emulation options to be either "light" or "dark", received "${options}"`);
89
+ }
90
+ await this.scriptAddPreloadScript({
91
+ functionDeclaration: /*js*/ `() => {
92
+ const originalMatchMedia = window.matchMedia
93
+ Object.defineProperty(window, 'matchMedia', {
94
+ value: (query) => {
95
+ const colorSchemeQuery = query.match(/\\(prefers-color-scheme:(\\s)*(dark|light)\\)/i)
96
+ if (colorSchemeQuery) {
97
+ const result = originalMatchMedia(query)
98
+ Object.defineProperty(result, 'matches', {
99
+ value: colorSchemeQuery[2] === "${options}",
100
+ configurable: true
101
+ })
102
+ return result
103
+ }
104
+
105
+ return originalMatchMedia(query)
106
+ },
107
+ configurable: true
108
+ })
109
+ }`
110
+ });
111
+ return;
112
+ }
113
+ if (scope === 'onLine') {
114
+ if (typeof options !== 'boolean') {
115
+ throw new Error(`Expected "onLine" emulation options to be a boolean, received "${typeof options}"`);
116
+ }
117
+ await this.scriptAddPreloadScript({
118
+ functionDeclaration: /*js*/ `() => {
119
+ Object.defineProperty(navigator, 'onLine', {
120
+ value: ${options}
121
+ })
122
+ }`
123
+ });
124
+ return;
125
+ }
126
+ return;
127
+ }
@@ -1,4 +1,4 @@
1
- import type { ReactSelectorOptions, ElementArray } from '../../types.js';
1
+ import type { ReactSelectorOptions } from '../../types.js';
2
2
  /**
3
3
  *
4
4
  * The `react$$` command is a useful command to query multiple React Components
@@ -32,5 +32,5 @@ import type { ReactSelectorOptions, ElementArray } from '../../types.js';
32
32
  * @return {ElementArray}
33
33
  *
34
34
  */
35
- export declare function react$$(this: WebdriverIO.Browser, selector: string, { props, state }?: ReactSelectorOptions): Promise<ElementArray>;
35
+ export declare function react$$(this: WebdriverIO.Browser, selector: string, { props, state }?: ReactSelectorOptions): Promise<WebdriverIO.ElementArray>;
36
36
  //# sourceMappingURL=react$$.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/react$$.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAIxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,OAAO,CACzB,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,QAAQ,EAAE,MAAM,EAChB,EAAE,KAAU,EAAE,KAAU,EAAE,GAAE,oBAAyB,yBAexD"}
1
+ {"version":3,"file":"react$$.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/react$$.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAI1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,OAAO,CACzB,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,QAAQ,EAAE,MAAM,EAChB,EAAE,KAAU,EAAE,KAAU,EAAE,GAAE,oBAAyB,qCAexD"}
@@ -1 +1 @@
1
- {"version":3,"file":"saveScreenshot.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/saveScreenshot.ts"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,cAAc,CAChC,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,QAAQ,EAAE,MAAM,mBA0BnB"}
1
+ {"version":3,"file":"saveScreenshot.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/saveScreenshot.ts"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,cAAc,CAChC,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,QAAQ,EAAE,MAAM,mBAwBnB"}
@@ -37,10 +37,8 @@ export async function saveScreenshot(filepath) {
37
37
  await assertDirectoryExists(absoluteFilepath);
38
38
  let screenBuffer;
39
39
  if (this.isBidi) {
40
- const { contexts } = await this.browsingContextGetTree({});
41
- const { data } = await this.browsingContextCaptureScreenshot({
42
- context: contexts[0].context
43
- });
40
+ const context = await this.getWindowHandle();
41
+ const { data } = await this.browsingContextCaptureScreenshot({ context });
44
42
  screenBuffer = data;
45
43
  }
46
44
  else {
@@ -1,3 +1,6 @@
1
1
  import type { ThrottleOptions } from '../../utils/interception/types.js';
2
- export declare function throttle(this: WebdriverIO.Browser, params: ThrottleOptions): Promise<null>;
2
+ /**
3
+ * @deprecated use `browser.throttleNetwork` instead
4
+ */
5
+ export declare function throttle(this: WebdriverIO.Browser, params: ThrottleOptions): Promise<void>;
3
6
  //# sourceMappingURL=throttle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/throttle.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAmExE,wBAAsB,QAAQ,CAC1B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,MAAM,EAAE,eAAe,iBA0C1B"}
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAMxE;;GAEG;AACH,wBAAsB,QAAQ,CAC1B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,MAAM,EAAE,eAAe,iBAK1B"}
@@ -1,141 +1,11 @@
1
+ import logger from '@wdio/logger';
2
+ import { getBrowserObject } from '../../utils/index.js';
3
+ const log = logger('webdriverio:throttle');
1
4
  /**
2
- * Throttle the network capabilities of the browser. This can help to
3
- * emulate certain scenarios where a user loses their internet connection
4
- * and your app needs to address that.
5
- *
6
- * There are many presets available with default configurations for ease of use.
7
- * They are `offline`, `GPRS`, `Regular2G`, `Good2G`, `Regular3G`, `Good3G`,
8
- * `Regular4G`, `DSL`, `WiFi`, `online`.
9
- *
10
- * You can see the values for these presets [in the source code](https://github.com/webdriverio/webdriverio/blob/6824e4eb118a8d20685f12f4bc42f13fd56f8a25/packages/webdriverio/src/commands/browser/throttle.js#L29).
11
- *
12
- * :::info
13
- *
14
- * Note that using the `throttle` command requires support for Chrome DevTools protocol and e.g.
15
- * can not be used when running automated tests in the cloud. Find out more in the
16
- * [Automation Protocols](/docs/automationProtocols) section.
17
- *
18
- * :::
19
- *
20
- * <example>
21
- :throttle.js
22
- it('should throttle the network', async () => {
23
- // via static string preset
24
- await browser.throttle('Regular3G')
25
-
26
- // via custom values
27
- await browser.throttle({
28
- offline: false,
29
- downloadThroughput: 200 * 1024 / 8,
30
- uploadThroughput: 200 * 1024 / 8,
31
- latency: 20
32
- })
33
- });
34
- * </example>
35
- *
36
- * @alias browser.throttle
37
- * @param {ThrottleOptions} params parameters for throttling
38
- * @param {boolean} params.offline True to emulate internet disconnection.
39
- * @param {number} params.latency Minimum latency from request sent to response headers received (ms).
40
- * @param {number} params.downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
41
- * @param {number} params.uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
42
- * @type utility
43
- *
5
+ * @deprecated use `browser.throttleNetwork` instead
44
6
  */
45
- import { getBrowserObject } from '../../utils/index.js';
46
- const NETWORK_PRESETS = {
47
- 'offline': {
48
- offline: true,
49
- downloadThroughput: 0,
50
- uploadThroughput: 0,
51
- latency: 1
52
- },
53
- 'GPRS': {
54
- offline: false,
55
- downloadThroughput: 50 * 1024 / 8,
56
- uploadThroughput: 20 * 1024 / 8,
57
- latency: 500
58
- },
59
- 'Regular2G': {
60
- offline: false,
61
- downloadThroughput: 250 * 1024 / 8,
62
- uploadThroughput: 50 * 1024 / 8,
63
- latency: 300
64
- },
65
- 'Good2G': {
66
- offline: false,
67
- downloadThroughput: 450 * 1024 / 8,
68
- uploadThroughput: 150 * 1024 / 8,
69
- latency: 150
70
- },
71
- 'Regular3G': {
72
- offline: false,
73
- downloadThroughput: 750 * 1024 / 8,
74
- uploadThroughput: 250 * 1024 / 8,
75
- latency: 100
76
- },
77
- 'Good3G': {
78
- offline: false,
79
- downloadThroughput: 1.5 * 1024 * 1024 / 8,
80
- uploadThroughput: 750 * 1024 / 8,
81
- latency: 40
82
- },
83
- 'Regular4G': {
84
- offline: false,
85
- downloadThroughput: 4 * 1024 * 1024 / 8,
86
- uploadThroughput: 3 * 1024 * 1024 / 8,
87
- latency: 20
88
- },
89
- 'DSL': {
90
- offline: false,
91
- downloadThroughput: 2 * 1024 * 1024 / 8,
92
- uploadThroughput: 1 * 1024 * 1024 / 8,
93
- latency: 5
94
- },
95
- 'WiFi': {
96
- offline: false,
97
- downloadThroughput: 30 * 1024 * 1024 / 8,
98
- uploadThroughput: 15 * 1024 * 1024 / 8,
99
- latency: 2
100
- },
101
- 'online': {
102
- offline: false,
103
- latency: 0,
104
- downloadThroughput: -1,
105
- uploadThroughput: -1
106
- }
107
- };
108
- const NETWORK_PRESET_TYPES = Object.keys(NETWORK_PRESETS);
109
7
  export async function throttle(params) {
110
- if (
111
- /**
112
- * check string parameter
113
- */
114
- (typeof params !== 'string' || !NETWORK_PRESET_TYPES.includes(params)) &&
115
- /**
116
- * check object parameter
117
- */
118
- (typeof params !== 'object')) {
119
- throw new Error(`Invalid parameter for "throttle". Expected it to be typeof object or one of the following values: ${NETWORK_PRESET_TYPES.join(', ')} but found "${params}"`);
120
- }
121
- /**
122
- * use WebDriver extension if connected with cloud service
123
- */
124
- if (this.isSauce) {
125
- const browser = getBrowserObject(this);
126
- await browser.throttleNetwork(params);
127
- return null;
128
- }
129
- // Connect to Chrome DevTools
130
- await this.getPuppeteer();
131
- if (!this.puppeteer) {
132
- throw new Error('No Puppeteer connection could be established which is required to use this command');
133
- }
134
- const pages = await this.puppeteer.pages();
135
- const client = await pages[0].target().createCDPSession();
136
- // Set throttling property
137
- await client.send('Network.emulateNetworkConditions', typeof params === 'string'
138
- ? NETWORK_PRESETS[params]
139
- : params);
140
- return null;
8
+ log.warn('Command "throttle" is deprecated and will be removed with the next major version release! Use `throttleNetwork` instead.');
9
+ const browser = getBrowserObject(this);
10
+ await browser.throttleNetwork(params);
141
11
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Throttles the CPU to emulate a slower processor.
3
+ *
4
+ * :::info
5
+ *
6
+ * Note that using the `throttleCPU` command requires support for Chrome DevTools protocol and e.g.
7
+ * can not be used when running automated tests in the cloud. Find out more in the
8
+ * [Automation Protocols](/docs/automationProtocols) section.
9
+ *
10
+ * :::
11
+ *
12
+ * <example>
13
+ :throttleCPU.js
14
+ it('should throttle the CPU', async () => {
15
+ await browser.throttleCPU(2) // 2x slowdown
16
+ });
17
+ * </example>
18
+ *
19
+ * @alias browser.throttleCPU
20
+ * @param {number} factor slowdown factor (1 is no throttle, 2 is 2x slowdown, etc)
21
+ * @type utility
22
+ *
23
+ */
24
+ export declare function throttleCPU(this: WebdriverIO.Browser, factor: number): Promise<void>;
25
+ //# sourceMappingURL=throttleCPU.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttleCPU.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/throttleCPU.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAsB,WAAW,CAC7B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,MAAM,EAAE,MAAM,iBAwBjB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Throttles the CPU to emulate a slower processor.
3
+ *
4
+ * :::info
5
+ *
6
+ * Note that using the `throttleCPU` command requires support for Chrome DevTools protocol and e.g.
7
+ * can not be used when running automated tests in the cloud. Find out more in the
8
+ * [Automation Protocols](/docs/automationProtocols) section.
9
+ *
10
+ * :::
11
+ *
12
+ * <example>
13
+ :throttleCPU.js
14
+ it('should throttle the CPU', async () => {
15
+ await browser.throttleCPU(2) // 2x slowdown
16
+ });
17
+ * </example>
18
+ *
19
+ * @alias browser.throttleCPU
20
+ * @param {number} factor slowdown factor (1 is no throttle, 2 is 2x slowdown, etc)
21
+ * @type utility
22
+ *
23
+ */
24
+ export async function throttleCPU(factor) {
25
+ if (typeof factor !== 'number') {
26
+ throw new Error('Invalid factor for "throttleCPU". Expected it to be a number (int)');
27
+ }
28
+ const failedConnectionMessage = 'No Puppeteer connection could be established which is required to use this command';
29
+ // Connect to Chrome DevTools
30
+ await this.getPuppeteer();
31
+ if (!this.puppeteer) {
32
+ throw new Error(failedConnectionMessage);
33
+ }
34
+ const pages = await this.puppeteer.pages();
35
+ if (!pages.length) {
36
+ throw new Error(failedConnectionMessage);
37
+ }
38
+ const client = await pages[0].target().createCDPSession();
39
+ // Set CPU throttling
40
+ await client.send('Emulation.setCPUThrottlingRate', { rate: factor });
41
+ }
@@ -0,0 +1,3 @@
1
+ import type { ThrottleOptions } from '../../utils/interception/types.js';
2
+ export declare function throttleNetwork(this: WebdriverIO.Browser, params: ThrottleOptions): Promise<null>;
3
+ //# sourceMappingURL=throttleNetwork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttleNetwork.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/throttleNetwork.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAmExE,wBAAsB,eAAe,CACjC,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,MAAM,EAAE,eAAe,iBAiD1B"}