appium-uiautomator2-driver 6.7.6 → 6.7.7

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 (73) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/lib/commands/actions.d.ts +26 -29
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +19 -27
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +14 -22
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +8 -19
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +7 -10
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +4 -14
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/battery.d.ts +4 -5
  15. package/build/lib/commands/battery.d.ts.map +1 -1
  16. package/build/lib/commands/battery.js +4 -9
  17. package/build/lib/commands/battery.js.map +1 -1
  18. package/build/lib/commands/clipboard.d.ts +9 -13
  19. package/build/lib/commands/clipboard.d.ts.map +1 -1
  20. package/build/lib/commands/clipboard.js +7 -14
  21. package/build/lib/commands/clipboard.js.map +1 -1
  22. package/build/lib/commands/element.d.ts +29 -0
  23. package/build/lib/commands/element.d.ts.map +1 -1
  24. package/build/lib/commands/element.js +29 -0
  25. package/build/lib/commands/element.js.map +1 -1
  26. package/build/lib/commands/find.d.ts +13 -9
  27. package/build/lib/commands/find.d.ts.map +1 -1
  28. package/build/lib/commands/find.js +4 -16
  29. package/build/lib/commands/find.js.map +1 -1
  30. package/build/lib/commands/gestures.d.ts +63 -0
  31. package/build/lib/commands/gestures.d.ts.map +1 -1
  32. package/build/lib/commands/gestures.js +63 -0
  33. package/build/lib/commands/gestures.js.map +1 -1
  34. package/build/lib/commands/keyboard.d.ts +30 -41
  35. package/build/lib/commands/keyboard.d.ts.map +1 -1
  36. package/build/lib/commands/keyboard.js +22 -37
  37. package/build/lib/commands/keyboard.js.map +1 -1
  38. package/build/lib/commands/misc.d.ts +4 -0
  39. package/build/lib/commands/misc.d.ts.map +1 -1
  40. package/build/lib/commands/misc.js +4 -0
  41. package/build/lib/commands/misc.js.map +1 -1
  42. package/build/lib/commands/navigation.d.ts +11 -16
  43. package/build/lib/commands/navigation.d.ts.map +1 -1
  44. package/build/lib/commands/navigation.js +9 -17
  45. package/build/lib/commands/navigation.js.map +1 -1
  46. package/build/lib/commands/viewport.d.ts +23 -22
  47. package/build/lib/commands/viewport.d.ts.map +1 -1
  48. package/build/lib/commands/viewport.js +17 -24
  49. package/build/lib/commands/viewport.js.map +1 -1
  50. package/build/tsconfig.tsbuildinfo +1 -1
  51. package/lib/commands/actions.ts +95 -0
  52. package/lib/commands/alert.ts +46 -0
  53. package/lib/commands/app-management.ts +25 -0
  54. package/lib/commands/battery.ts +19 -0
  55. package/lib/commands/clipboard.ts +29 -0
  56. package/lib/commands/element.ts +29 -0
  57. package/lib/commands/find.ts +48 -0
  58. package/lib/commands/gestures.ts +63 -0
  59. package/lib/commands/keyboard.ts +102 -0
  60. package/lib/commands/misc.ts +4 -0
  61. package/lib/commands/navigation.ts +32 -0
  62. package/lib/commands/viewport.ts +78 -0
  63. package/npm-shrinkwrap.json +2 -2
  64. package/package.json +1 -1
  65. package/lib/commands/actions.js +0 -107
  66. package/lib/commands/alert.js +0 -63
  67. package/lib/commands/app-management.js +0 -32
  68. package/lib/commands/battery.js +0 -23
  69. package/lib/commands/clipboard.js +0 -37
  70. package/lib/commands/find.js +0 -47
  71. package/lib/commands/keyboard.js +0 -108
  72. package/lib/commands/navigation.js +0 -33
  73. package/lib/commands/viewport.js +0 -100
@@ -0,0 +1,32 @@
1
+ import type {AndroidUiautomator2Driver} from '../driver';
2
+
3
+ /**
4
+ * Sets the URL for the current app.
5
+ * @param url - The URL to navigate to.
6
+ */
7
+ export async function setUrl(this: AndroidUiautomator2Driver, url: string): Promise<void> {
8
+ await this.adb.startUri(url, this.opts.appPackage as string);
9
+ }
10
+
11
+ /**
12
+ * Starts a URL that takes users directly to specific content in the app.
13
+ * @param url - The deep link URL to start.
14
+ * @param pkg - Optional package name to start the URI with. If not provided, uses the current app package.
15
+ * @param waitForLaunch - If false, adb won't wait for the started activity to return control. Defaults to true.
16
+ */
17
+ export async function mobileDeepLink(
18
+ this: AndroidUiautomator2Driver,
19
+ url: string,
20
+ pkg?: string,
21
+ waitForLaunch: boolean = true,
22
+ ): Promise<void> {
23
+ return await this.adb.startUri(url, pkg, {waitForLaunch});
24
+ }
25
+
26
+ /**
27
+ * Navigates back in the app.
28
+ */
29
+ export async function back(this: AndroidUiautomator2Driver): Promise<void> {
30
+ await this.adb.keyevent(4);
31
+ }
32
+
@@ -0,0 +1,78 @@
1
+ import type {Rect, Size} from '@appium/types';
2
+ import type {AndroidUiautomator2Driver} from '../driver';
3
+ import type {RelativeRect} from './types';
4
+
5
+ /**
6
+ * Gets the status bar height in pixels.
7
+ * @returns The status bar height in pixels.
8
+ */
9
+ export async function getStatusBarHeight(this: AndroidUiautomator2Driver): Promise<number> {
10
+ const {statusBar} = (await this.uiautomator2.jwproxy.command(`/appium/device/system_bars`, 'GET', {})) as {
11
+ statusBar: number;
12
+ };
13
+ return statusBar;
14
+ }
15
+
16
+ /**
17
+ * Gets the device pixel ratio.
18
+ * @returns The device pixel ratio as a string.
19
+ */
20
+ export async function getDevicePixelRatio(this: AndroidUiautomator2Driver): Promise<string> {
21
+ return String(await this.uiautomator2.jwproxy.command('/appium/device/pixel_ratio', 'GET', {}));
22
+ }
23
+
24
+ /**
25
+ * Gets the viewport rectangle coordinates.
26
+ * @returns The viewport rectangle (left, top, width, height), accounting for status bar height.
27
+ */
28
+ export async function getViewPortRect(this: AndroidUiautomator2Driver): Promise<RelativeRect> {
29
+ const windowSize = await this.getWindowSize();
30
+ const statusBarHeight = await this.getStatusBarHeight();
31
+ // android returns the upscaled window size, so to get the true size of the
32
+ // rect we have to downscale
33
+ return {
34
+ left: 0,
35
+ top: statusBarHeight,
36
+ width: windowSize.width,
37
+ height: windowSize.height - statusBarHeight,
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Returns the viewport coordinates.
43
+ * @returns The viewport rectangle (left, top, width, height).
44
+ */
45
+ export async function mobileViewPortRect(this: AndroidUiautomator2Driver): Promise<RelativeRect> {
46
+ return await this.getViewPortRect();
47
+ }
48
+
49
+ /**
50
+ * Gets the window rectangle (W3C endpoint).
51
+ * @returns The window rectangle (x, y, width, height).
52
+ */
53
+ export async function getWindowRect(this: AndroidUiautomator2Driver): Promise<Rect> {
54
+ const {width, height} = await this.getWindowSize();
55
+ return {
56
+ width,
57
+ height,
58
+ x: 0,
59
+ y: 0,
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Gets the display density.
65
+ * @returns The display density value.
66
+ */
67
+ export async function getDisplayDensity(this: AndroidUiautomator2Driver): Promise<number> {
68
+ return (await this.uiautomator2.jwproxy.command('/appium/device/display_density', 'GET', {})) as number;
69
+ }
70
+
71
+ /**
72
+ * Gets the window size.
73
+ * @returns The window size (width, height).
74
+ */
75
+ export async function getWindowSize(this: AndroidUiautomator2Driver): Promise<Size> {
76
+ return (await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {})) as Size;
77
+ }
78
+
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "appium-uiautomator2-driver",
3
- "version": "6.7.6",
3
+ "version": "6.7.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "appium-uiautomator2-driver",
9
- "version": "6.7.6",
9
+ "version": "6.7.7",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "appium-adb": "^14.0.0",
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "automated testing",
8
8
  "android"
9
9
  ],
10
- "version": "6.7.6",
10
+ "version": "6.7.7",
11
11
  "bugs": {
12
12
  "url": "https://github.com/appium/appium-uiautomator2-driver/issues"
13
13
  },
@@ -1,107 +0,0 @@
1
- /**
2
- * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
3
- * @this {AndroidUiautomator2Driver}
4
- * @param {string} name
5
- * @param {import('@appium/types').StringRecord[]} steps
6
- * @param {number} [maxPass]
7
- * @param {number} [maxFail]
8
- * @param {number} [times]
9
- * @param {number} [intervalMs]
10
- * @param {number} [maxHistoryItems]
11
- * @returns {Promise<any>}
12
- */
13
- export async function mobileScheduleAction(
14
- name,
15
- steps,
16
- maxPass,
17
- maxFail,
18
- times,
19
- intervalMs,
20
- maxHistoryItems,
21
- ) {
22
- return await this.uiautomator2.jwproxy.command(
23
- '/appium/schedule_action',
24
- 'POST',
25
- {
26
- name,
27
- steps,
28
- maxFail,
29
- maxPass,
30
- times,
31
- intervalMs,
32
- maxHistoryItems,
33
- }
34
- );
35
- }
36
-
37
- /**
38
- * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
39
- * @this {AndroidUiautomator2Driver}
40
- * @param {string} name
41
- * @returns {Promise<import('./types').ActionResult>}
42
- */
43
- export async function mobileGetActionHistory(name) {
44
- return /** @type {import('./types').ActionResult} */ (
45
- await this.uiautomator2.jwproxy.command(
46
- '/appium/action_history',
47
- 'POST',
48
- {name}
49
- )
50
- );
51
- }
52
-
53
- /**
54
- * @this {AndroidUiautomator2Driver}
55
- * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
56
- * @param {string} name
57
- * @returns {Promise<any>}
58
- */
59
- export async function mobileUnscheduleAction(name) {
60
- return await this.uiautomator2.jwproxy.command(
61
- '/appium/unschedule_action',
62
- 'POST',
63
- {name}
64
- );
65
- }
66
-
67
- /**
68
- * @this {AndroidUiautomator2Driver}
69
- * @param {import('@appium/types').StringRecord[]} actions
70
- * @returns {Promise<void>}
71
- */
72
- export async function performActions(actions) {
73
- // This is mandatory, since Selenium API uses MOUSE as the default pointer type
74
- const preprocessedActions = actions.map((action) =>
75
- Object.assign(
76
- {},
77
- action,
78
- action.type === 'pointer'
79
- ? {
80
- parameters: {
81
- pointerType: 'touch',
82
- },
83
- }
84
- : {}
85
- )
86
- );
87
- this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
88
- await this.uiautomator2.jwproxy.command(
89
- '/actions',
90
- 'POST',
91
- {
92
- actions: preprocessedActions,
93
- }
94
- );
95
- }
96
-
97
- /**
98
- * @this {AndroidUiautomator2Driver}
99
- * @returns {Promise<void>}
100
- */
101
- export async function releaseActions() {
102
- this.log.info('On this platform, releaseActions is a no-op');
103
- }
104
-
105
- /**
106
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
107
- */
@@ -1,63 +0,0 @@
1
- /**
2
- * @this {AndroidUiautomator2Driver}
3
- * @returns {Promise<string>}
4
- */
5
- export async function getAlertText() {
6
- return String(
7
- await this.uiautomator2.jwproxy.command(
8
- '/alert/text',
9
- 'GET',
10
- {}
11
- )
12
- );
13
- }
14
-
15
- /**
16
- * @this {AndroidUiautomator2Driver}
17
- * @param {string} [buttonLabel] The name of the button to click in order to accept the alert.
18
- * If the name is not provided
19
- * then the script will try to detect the button automatically.
20
- * @returns {Promise<void>}
21
- */
22
- export async function mobileAcceptAlert(buttonLabel) {
23
- await this.uiautomator2.jwproxy.command(
24
- '/alert/accept',
25
- 'POST',
26
- {buttonLabel}
27
- );
28
- }
29
-
30
- /**
31
- * @this {AndroidUiautomator2Driver}
32
- * @returns {Promise<void>}
33
- */
34
- export async function postAcceptAlert() {
35
- await this.mobileAcceptAlert();
36
- }
37
-
38
- /**
39
- * @this {AndroidUiautomator2Driver}
40
- * @param {string} [buttonLabel] The name of the button to click in order to dismiss the alert.
41
- * If the name is not provided
42
- * then the script will try to detect the button automatically.
43
- * @returns {Promise<void>}
44
- */
45
- export async function mobileDismissAlert(buttonLabel) {
46
- await this.uiautomator2.jwproxy.command(
47
- '/alert/dismiss',
48
- 'POST',
49
- {buttonLabel}
50
- );
51
- }
52
-
53
- /**
54
- * @this {AndroidUiautomator2Driver}
55
- * @returns {Promise<void>}
56
- */
57
- export async function postDismissAlert() {
58
- await this.mobileDismissAlert();
59
- }
60
-
61
- /**
62
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
63
- */
@@ -1,32 +0,0 @@
1
- import _ from 'lodash';
2
- import B from 'bluebird';
3
- import {errors} from 'appium/driver';
4
- import {APK_EXTENSION} from '../extensions';
5
-
6
- /**
7
- * Install multiple APKs with `install-multiple` option.
8
- * @this {AndroidUiautomator2Driver}
9
- * @param {string[]} apks The list of APKs to install. Each APK should be a path to a apk
10
- * or downloadable URL as HTTP/HTTPS.
11
- * @param {import('./types').InstallOptions} [options] Installation options.
12
- * @throws {Error} if an error occured while installing the given APKs.
13
- * @returns {Promise<void>}
14
- */
15
- export async function mobileInstallMultipleApks(apks, options) {
16
- if (!_.isArray(apks) || _.isEmpty(apks)) {
17
- throw new errors.InvalidArgumentError('No apks are given to install');
18
- }
19
- const configuredApks = await B.all(
20
- apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
21
- );
22
- await this.adb.installMultipleApks(configuredApks, options);
23
- }
24
-
25
- /**
26
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
27
- */
28
-
29
- /**
30
- * @template [T=any]
31
- * @typedef {import('@appium/types').StringRecord<T>} StringRecord
32
- */
@@ -1,23 +0,0 @@
1
-
2
- /**
3
- * Reads the battery information from the device under test.
4
- * @this {AndroidUiautomator2Driver}
5
- * @returns {Promise<import('./types').BatteryInfo>} The actual battery info
6
- */
7
- export async function mobileGetBatteryInfo() {
8
- const result = /** @type {import('./types').MapKey<BatteryInfo, 'state', 'status'>} */ (
9
- await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
10
- this.uiautomator2
11
- ).jwproxy.command('/appium/device/battery_info', 'GET', {})
12
- );
13
- const batteryInfo = /** @type {any} */ (result);
14
- // Give it the same name as in iOS
15
- batteryInfo.state = result.status;
16
- delete batteryInfo.status;
17
- return /** @type {BatteryInfo} */ (batteryInfo);
18
- }
19
-
20
- /**
21
- * @typedef {import('./types').BatteryInfo} BatteryInfo
22
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
23
- */
@@ -1,37 +0,0 @@
1
- /**
2
- * @this {AndroidUiautomator2Driver}
3
- * @returns {Promise<string>} Base64-encoded content of the clipboard
4
- * or an empty string if the clipboard is empty.
5
- */
6
- export async function getClipboard() {
7
- return String(
8
- (await this.adb.getApiLevel()) < 29
9
- ? await this.uiautomator2.jwproxy.command(
10
- '/appium/device/get_clipboard',
11
- 'POST',
12
- {}
13
- )
14
- : await this.settingsApp.getClipboard()
15
- );
16
- }
17
-
18
- /**
19
- * @this {AndroidUiautomator2Driver}
20
- * @param {string} content Base64-encoded clipboard payload
21
- * @param {'plaintext'} [contentType='plaintext'] Only a single
22
- * content type is supported, which is 'plaintext'
23
- * @param {string} [label] Optinal label to identify the current
24
- * clipboard payload
25
- * @returns {Promise<void>}
26
- */
27
- export async function setClipboard(content, contentType, label) {
28
- await this.uiautomator2.jwproxy.command(
29
- '/appium/device/set_clipboard',
30
- 'POST',
31
- {content, contentType, label}
32
- );
33
- }
34
-
35
- /**
36
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
37
- */
@@ -1,47 +0,0 @@
1
- import {CssConverter} from '../css-converter';
2
-
3
- // we override the xpath search for this first-visible-child selector, which
4
- // looks like /*[@firstVisible="true"]
5
- const MAGIC_FIRST_VIS_CHILD_SEL = /\/\*\[@firstVisible ?= ?('|")true\1\]/;
6
-
7
- const MAGIC_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
8
- const MAGIC_SCROLLABLE_BY = 'new UiSelector().scrollable(true)';
9
-
10
- /**
11
- * @privateRemarks Overriding helpers.doFindElementOrEls functionality of appium-android-driver,
12
- * this.element initialized in find.js of appium-android-drive.
13
- *
14
- * @this {AndroidUiautomator2Driver}
15
- * @param {import('appium-android-driver').FindElementOpts} params
16
- * @returns {Promise<Element | Element[]>}
17
- */
18
- export async function doFindElementOrEls(params) {
19
- const uiautomator2 = /** @type {import('../uiautomator2').UiAutomator2Server} */ (
20
- this.uiautomator2
21
- );
22
- if (params.strategy === 'xpath' && MAGIC_FIRST_VIS_CHILD_SEL.test(params.selector)) {
23
- let elementId = params.context;
24
- return /** @type {Element} */ (
25
- await uiautomator2.jwproxy.command(`/appium/element/${elementId}/first_visible`, 'GET', {})
26
- );
27
- }
28
- if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
29
- params.strategy = '-android uiautomator';
30
- params.selector = MAGIC_SCROLLABLE_BY;
31
- }
32
- if (params.strategy === 'css selector') {
33
- params.strategy = '-android uiautomator';
34
- params.selector = new CssConverter(
35
- params.selector,
36
- this.opts.appPackage
37
- ).toUiAutomatorSelector();
38
- }
39
- return /** @type {Element|Element[]} */ (
40
- await uiautomator2.jwproxy.command(`/element${params.multiple ? 's' : ''}`, 'POST', params)
41
- );
42
- }
43
-
44
- /**
45
- * @typedef {import('@appium/types').Element} Element
46
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
47
- */
@@ -1,108 +0,0 @@
1
- import { errors } from 'appium/driver';
2
- import _ from 'lodash';
3
-
4
- /**
5
- * @this {AndroidUiautomator2Driver}
6
- * @param {string|number} keycode
7
- * @param {number} [metastate]
8
- * @param {number} [flags]
9
- * @returns {Promise<void>}
10
- */
11
- export async function pressKeyCode(keycode, metastate, flags) {
12
- await this.uiautomator2.jwproxy.command(
13
- '/appium/device/press_keycode',
14
- 'POST',
15
- {
16
- keycode,
17
- metastate,
18
- flags,
19
- }
20
- );
21
- }
22
-
23
- /**
24
- * @this {AndroidUiautomator2Driver}
25
- * @param {string|number} keycode
26
- * @param {number} metastate
27
- * @param {number} [flags]
28
- * @returns {Promise<void>}
29
- */
30
- export async function longPressKeyCode(keycode, metastate, flags) {
31
- await this.uiautomator2.jwproxy.command(
32
- '/appium/device/long_press_keycode',
33
- 'POST',
34
- {
35
- keycode,
36
- metastate,
37
- flags,
38
- }
39
- );
40
- }
41
-
42
- /**
43
- * @this {AndroidUiautomator2Driver}
44
- * @param {number} keycode A valid Android key code. See https://developer.android.com/reference/android/view/KeyEvent
45
- * for the list of available key codes.
46
- * @param {number} [metastate] An integer in which each bit set to 1 represents a pressed meta key. See
47
- * https://developer.android.com/reference/android/view/KeyEvent for more details.
48
- * @param {string} [flags] Flags for the particular key event. See
49
- * https://developer.android.com/reference/android/view/KeyEvent for more details.
50
- * @param {boolean} [isLongPress=false] Whether to emulate long key press
51
- * @returns {Promise<void>}
52
- */
53
- export async function mobilePressKey(keycode, metastate, flags, isLongPress = false) {
54
- await this.uiautomator2.jwproxy.command(
55
- `/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
56
- 'POST',
57
- {
58
- keycode,
59
- metastate,
60
- flags,
61
- }
62
- );
63
- }
64
-
65
- /**
66
- * Types the given Unicode string.
67
- * It is expected that the focus is already put
68
- * to the destination input field before this method is called.
69
- *
70
- * @this {AndroidUiautomator2Driver}
71
- * @param {string | number | boolean} text The text to type. Can be a string, number or boolean.
72
- * @returns {Promise<boolean>} `true` if the input text has been successfully sent to adb
73
- * @throws {Error} if `text` property has not been provided
74
- */
75
- export async function mobileType(text) {
76
- if (_.isUndefined(text)) {
77
- throw new errors.InvalidArgumentError(`The 'text' argument is mandatory`);
78
- }
79
- return await this.settingsApp.typeUnicode(String(text));
80
- }
81
-
82
- /**
83
- * @this {AndroidUiautomator2Driver}
84
- * @param {import('appium-android-driver').SendKeysOpts} params
85
- * @returns {Promise<void>}
86
- */
87
- export async function doSendKeys(params) {
88
- await this.uiautomator2.jwproxy.command(
89
- '/keys',
90
- 'POST',
91
- params
92
- );
93
- }
94
-
95
- /**
96
- * @this {AndroidUiautomator2Driver}
97
- * @param {string|number} keycode
98
- * @param {number} [metastate]
99
- * @returns {Promise<void>}
100
- */
101
- export async function keyevent(keycode, metastate) {
102
- this.log.debug(`Ignoring metastate ${metastate}`);
103
- await this.adb.keyevent(keycode);
104
- }
105
-
106
- /**
107
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
108
- */
@@ -1,33 +0,0 @@
1
- /**
2
- * @this {AndroidUiautomator2Driver}
3
- * @param {string} url
4
- * @returns {Promise<void>}
5
- */
6
- export async function setUrl(url) {
7
- await this.adb.startUri(url, /** @type {string} */ (this.opts.appPackage));
8
- }
9
-
10
- /**
11
- * Start URL that take users directly to specific content in the app
12
- * @this {AndroidUiautomator2Driver}
13
- * @param {string} url The name of URL to start.
14
- * @param {string} [pkg] The name of the package to start the URI with.
15
- * @param {boolean} [waitForLaunch=true] If `false` then adb won't wait for
16
- * the started activity to return the control.
17
- * @returns {Promise<void>}
18
- */
19
- export async function mobileDeepLink(url, pkg, waitForLaunch) {
20
- return await this.adb.startUri(url, pkg, {waitForLaunch});
21
- }
22
-
23
- /**
24
- * @this {AndroidUiautomator2Driver}
25
- * @returns {Promise<void>}
26
- */
27
- export async function back() {
28
- await this.adb.keyevent(4);
29
- }
30
-
31
- /**
32
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
33
- */
@@ -1,100 +0,0 @@
1
-
2
- // memoized in constructor
3
- /**
4
- * @this {AndroidUiautomator2Driver}
5
- * @returns {Promise<number>}
6
- */
7
- export async function getStatusBarHeight() {
8
- const {statusBar} = /** @type {{statusBar: number}} */ (
9
- await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
10
- this.uiautomator2
11
- ).jwproxy.command(`/appium/device/system_bars`, 'GET', {})
12
- );
13
- return statusBar;
14
- }
15
-
16
- // memoized in constructor
17
- /**
18
- * @this {AndroidUiautomator2Driver}
19
- * @returns {Promise<string>}
20
- */
21
- export async function getDevicePixelRatio() {
22
- return String(
23
- await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
24
- this.uiautomator2
25
- ).jwproxy.command('/appium/device/pixel_ratio', 'GET', {})
26
- );
27
- }
28
-
29
- /**
30
- * @this {AndroidUiautomator2Driver}
31
- * @returns {Promise<import('./types').RelativeRect>}
32
- */
33
- export async function getViewPortRect() {
34
- const windowSize = await this.getWindowSize();
35
- const statusBarHeight = await this.getStatusBarHeight();
36
- // android returns the upscaled window size, so to get the true size of the
37
- // rect we have to downscale
38
- return {
39
- left: 0,
40
- top: statusBarHeight,
41
- width: windowSize.width,
42
- height: windowSize.height - statusBarHeight,
43
- };
44
- }
45
-
46
- /**
47
- * Returns the viewport coordinates.
48
- * @this {AndroidUiautomator2Driver}
49
- * @returns {Promise<import('./types').RelativeRect>} The viewport coordinates.
50
- */
51
- export async function mobileViewPortRect() {
52
- return await this.getViewPortRect();
53
- }
54
-
55
- // For W3C
56
- /**
57
- * @this {AndroidUiautomator2Driver}
58
- * @returns {Promise<import('@appium/types').Rect>}
59
- */
60
- export async function getWindowRect() {
61
- const {width, height} = await this.getWindowSize();
62
- return {
63
- width,
64
- height,
65
- x: 0,
66
- y: 0,
67
- };
68
- }
69
-
70
- /**
71
- * @this {AndroidUiautomator2Driver}
72
- * @returns {Promise<number>}
73
- */
74
- export async function getDisplayDensity() {
75
- return /** @type {number} */ (
76
- await this.uiautomator2.jwproxy.command(
77
- '/appium/device/display_density',
78
- 'GET',
79
- {}
80
- )
81
- );
82
- }
83
-
84
- /**
85
- * @this {AndroidUiautomator2Driver}
86
- * @returns {Promise<import('@appium/types').Size>}
87
- */
88
- export async function getWindowSize() {
89
- return /** @type {import('@appium/types').Size} */ (
90
- await this.uiautomator2.jwproxy.command(
91
- '/window/current/size',
92
- 'GET',
93
- {}
94
- )
95
- );
96
- }
97
-
98
- /**
99
- * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
100
- */