appium-uiautomator2-driver 2.42.2 → 2.43.1

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 (114) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/lib/commands/actions.d.ts +22 -1
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +30 -62
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +28 -1
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +42 -23
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +19 -0
  11. package/build/lib/commands/app-management.d.ts.map +1 -0
  12. package/build/lib/commands/app-management.js +45 -0
  13. package/build/lib/commands/app-management.js.map +1 -0
  14. package/build/lib/commands/app-strings.d.ts +9 -0
  15. package/build/lib/commands/app-strings.d.ts.map +1 -1
  16. package/build/lib/commands/app-strings.js +11 -79
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/battery.d.ts +7 -0
  19. package/build/lib/commands/battery.d.ts.map +1 -1
  20. package/build/lib/commands/battery.js +14 -20
  21. package/build/lib/commands/battery.js.map +1 -1
  22. package/build/lib/commands/element.d.ts +100 -1
  23. package/build/lib/commands/element.d.ts.map +1 -1
  24. package/build/lib/commands/element.js +175 -125
  25. package/build/lib/commands/element.js.map +1 -1
  26. package/build/lib/commands/execute.d.ts +25 -0
  27. package/build/lib/commands/execute.d.ts.map +1 -0
  28. package/build/lib/commands/execute.js +109 -0
  29. package/build/lib/commands/execute.js.map +1 -0
  30. package/build/lib/commands/find.d.ts +10 -0
  31. package/build/lib/commands/find.d.ts.map +1 -1
  32. package/build/lib/commands/find.js +25 -27
  33. package/build/lib/commands/find.js.map +1 -1
  34. package/build/lib/commands/gestures.d.ts +103 -1
  35. package/build/lib/commands/gestures.d.ts.map +1 -1
  36. package/build/lib/commands/gestures.js +202 -173
  37. package/build/lib/commands/gestures.js.map +1 -1
  38. package/build/lib/commands/keyboard.d.ts +47 -0
  39. package/build/lib/commands/keyboard.d.ts.map +1 -0
  40. package/build/lib/commands/keyboard.js +92 -0
  41. package/build/lib/commands/keyboard.js.map +1 -0
  42. package/build/lib/commands/misc.d.ts +48 -0
  43. package/build/lib/commands/misc.d.ts.map +1 -0
  44. package/build/lib/commands/misc.js +75 -0
  45. package/build/lib/commands/misc.js.map +1 -0
  46. package/build/lib/commands/navigation.d.ts +20 -0
  47. package/build/lib/commands/navigation.d.ts.map +1 -0
  48. package/build/lib/commands/navigation.js +35 -0
  49. package/build/lib/commands/navigation.js.map +1 -0
  50. package/build/lib/commands/screenshot.d.ts +24 -1
  51. package/build/lib/commands/screenshot.d.ts.map +1 -1
  52. package/build/lib/commands/screenshot.js +87 -64
  53. package/build/lib/commands/screenshot.js.map +1 -1
  54. package/build/lib/commands/touch.d.ts +81 -0
  55. package/build/lib/commands/touch.d.ts.map +1 -1
  56. package/build/lib/commands/touch.js +158 -41
  57. package/build/lib/commands/touch.js.map +1 -1
  58. package/build/lib/commands/viewport.d.ts +37 -1
  59. package/build/lib/commands/viewport.d.ts.map +1 -1
  60. package/build/lib/commands/viewport.js +80 -36
  61. package/build/lib/commands/viewport.js.map +1 -1
  62. package/build/lib/driver.d.ts +94 -24
  63. package/build/lib/driver.d.ts.map +1 -1
  64. package/build/lib/driver.js +114 -28
  65. package/build/lib/driver.js.map +1 -1
  66. package/build/lib/helpers.d.ts +12 -6
  67. package/build/lib/helpers.d.ts.map +1 -1
  68. package/build/lib/helpers.js +18 -18
  69. package/build/lib/helpers.js.map +1 -1
  70. package/build/lib/method-map.d.ts +0 -23
  71. package/build/lib/method-map.d.ts.map +1 -1
  72. package/build/lib/uiautomator2.js +3 -3
  73. package/build/lib/uiautomator2.js.map +1 -1
  74. package/build/tsconfig.tsbuildinfo +1 -1
  75. package/lib/commands/actions.js +37 -114
  76. package/lib/commands/alert.js +51 -37
  77. package/lib/commands/app-management.js +42 -0
  78. package/lib/commands/app-strings.js +9 -89
  79. package/lib/commands/battery.js +16 -26
  80. package/lib/commands/element.js +235 -214
  81. package/lib/commands/execute.js +120 -0
  82. package/lib/commands/find.js +31 -37
  83. package/lib/commands/gestures.js +252 -234
  84. package/lib/commands/keyboard.js +103 -0
  85. package/lib/commands/misc.js +106 -0
  86. package/lib/commands/navigation.js +31 -0
  87. package/lib/commands/screenshot.js +96 -77
  88. package/lib/commands/touch.js +190 -48
  89. package/lib/commands/viewport.js +100 -50
  90. package/lib/driver.ts +225 -36
  91. package/lib/helpers.js +15 -22
  92. package/lib/uiautomator2.js +3 -3
  93. package/npm-shrinkwrap.json +34 -34
  94. package/package.json +2 -2
  95. package/build/lib/commands/general.d.ts +0 -4
  96. package/build/lib/commands/general.d.ts.map +0 -1
  97. package/build/lib/commands/general.js +0 -214
  98. package/build/lib/commands/general.js.map +0 -1
  99. package/build/lib/commands/index.d.ts +0 -2
  100. package/build/lib/commands/index.d.ts.map +0 -1
  101. package/build/lib/commands/index.js +0 -14
  102. package/build/lib/commands/index.js.map +0 -1
  103. package/build/lib/commands/mixins.d.ts +0 -87
  104. package/build/lib/commands/mixins.d.ts.map +0 -1
  105. package/build/lib/commands/mixins.js +0 -26
  106. package/build/lib/commands/mixins.js.map +0 -1
  107. package/build/lib/utils.d.ts +0 -10
  108. package/build/lib/utils.d.ts.map +0 -1
  109. package/build/lib/utils.js +0 -26
  110. package/build/lib/utils.js.map +0 -1
  111. package/lib/commands/general.js +0 -289
  112. package/lib/commands/index.js +0 -11
  113. package/lib/commands/mixins.ts +0 -169
  114. package/lib/utils.js +0 -19
@@ -1,124 +1,47 @@
1
- // @ts-check
2
-
3
- import {mixin} from './mixins';
4
-
5
1
  /**
6
- * @type {import('./mixins').UIA2ActionsMixin}
7
- * @satisfies {import('@appium/types').ExternalDriver}
2
+ * See https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
3
+ * @this {AndroidUiautomator2Driver}
4
+ * @param {Record<string, any>} [opts={}]
5
+ * @returns {Promise<any>}
8
6
  */
9
- const ActionsMixin = {
10
- async pressKeyCode(keycode, metastate, flags) {
11
- await this.uiautomator2.jwproxy.command(
12
- '/appium/device/press_keycode',
13
- 'POST',
14
- {
15
- keycode,
16
- metastate,
17
- flags,
18
- }
19
- );
20
- },
21
-
22
- async longPressKeyCode(keycode, metastate, flags) {
23
- await this.uiautomator2.jwproxy.command(
24
- '/appium/device/long_press_keycode',
25
- 'POST',
26
- {
27
- keycode,
28
- metastate,
29
- flags,
30
- }
31
- );
32
- },
33
-
34
- async doSwipe(swipeOpts) {
35
- await this.uiautomator2.jwproxy.command(
36
- `/touch/perform`,
37
- 'POST',
38
- swipeOpts
39
- );
40
- },
41
-
42
- async doDrag(dragOpts) {
43
- await this.uiautomator2.jwproxy.command(
44
- `/touch/drag`,
45
- 'POST',
46
- dragOpts
47
- );
48
- },
49
-
50
- async getOrientation() {
51
- return /** @type {import('@appium/types').Orientation} */ (
52
- await this.uiautomator2.jwproxy.command(
53
- `/orientation`,
54
- 'GET',
55
- {}
56
- )
57
- );
58
- },
59
-
60
- async setOrientation(orientation) {
61
- orientation = /** @type {import('@appium/types').Orientation} */ (orientation.toUpperCase());
62
- await this.uiautomator2.jwproxy.command(
63
- `/orientation`,
64
- 'POST',
65
- {orientation}
66
- );
67
- },
68
-
69
- async mobilePressKey(opts) {
70
- const {keycode, metastate, flags, isLongPress = false} = opts;
7
+ export async function mobileScheduleAction(opts = {}) {
8
+ return await this.uiautomator2.jwproxy.command(
9
+ '/appium/schedule_action',
10
+ 'POST',
11
+ opts
12
+ );
13
+ }
71
14
 
15
+ /**
16
+ * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
17
+ * @this {AndroidUiautomator2Driver}
18
+ * @param {import('./types').ActionArgs} [opts={}]
19
+ * @returns {Promise<import('./types').ActionResult>}
20
+ */
21
+ export async function mobileGetActionHistory(opts) {
22
+ return /** @type {import('./types').ActionResult} */ (
72
23
  await this.uiautomator2.jwproxy.command(
73
- `/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
74
- 'POST',
75
- {
76
- keycode,
77
- metastate,
78
- flags,
79
- }
80
- );
81
- },
82
-
83
- /**
84
- * See https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
85
- * @param {Record<string, any>} opts
86
- */
87
- async mobileScheduleAction(opts = {}) {
88
- return await this.uiautomator2.jwproxy.command(
89
- '/appium/schedule_action',
90
- 'POST',
91
- opts
92
- );
93
- },
94
-
95
- /**
96
- * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
97
- */
98
- async mobileGetActionHistory(opts) {
99
- return /** @type {import('./types').ActionResult} */ (
100
- await this.uiautomator2.jwproxy.command(
101
- '/appium/action_history',
102
- 'POST',
103
- opts ?? {}
104
- )
105
- );
106
- },
107
-
108
- /**
109
- * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
110
- */
111
- async mobileUnscheduleAction(opts) {
112
- return await this.uiautomator2.jwproxy.command(
113
- '/appium/unschedule_action',
24
+ '/appium/action_history',
114
25
  'POST',
115
26
  opts ?? {}
116
- );
117
- },
118
- };
27
+ )
28
+ );
29
+ }
119
30
 
120
- mixin(ActionsMixin);
31
+ /**
32
+ * @this {AndroidUiautomator2Driver}
33
+ * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
34
+ * @param {import('./types').ActionArgs} [opts={}]
35
+ * @returns {Promise<any>}
36
+ */
37
+ export async function mobileUnscheduleAction(opts) {
38
+ return await this.uiautomator2.jwproxy.command(
39
+ '/appium/unschedule_action',
40
+ 'POST',
41
+ opts ?? {}
42
+ );
43
+ }
121
44
 
122
45
  /**
123
- * @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
46
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
124
47
  */
@@ -1,45 +1,59 @@
1
- // @ts-check
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
+ }
2
14
 
3
- import {mixin} from './mixins';
15
+ /**
16
+ * @this {AndroidUiautomator2Driver}
17
+ * @param {import('./types').AcceptAlertOptions} [opts={}]
18
+ * @returns {Promise<void>}
19
+ */
20
+ export async function mobileAcceptAlert(opts = {}) {
21
+ await this.uiautomator2.jwproxy.command(
22
+ '/alert/accept',
23
+ 'POST',
24
+ opts
25
+ );
26
+ }
4
27
 
5
28
  /**
6
- * @type {import('./mixins').UIA2AlertMixin}
7
- * @satisfies {import('@appium/types').ExternalDriver}
29
+ * @this {AndroidUiautomator2Driver}
30
+ * @returns {Promise<void>}
8
31
  */
9
- const AlertMixin = {
10
- async getAlertText() {
11
- return String(
12
- await this.uiautomator2.jwproxy.command(
13
- '/alert/text',
14
- 'GET',
15
- {}
16
- )
17
- );
18
- },
19
- async mobileAcceptAlert(opts = {}) {
20
- await this.uiautomator2.jwproxy.command(
21
- '/alert/accept',
22
- 'POST',
23
- opts
24
- );
25
- },
26
- async postAcceptAlert() {
27
- await this.mobileAcceptAlert();
28
- },
29
- async mobileDismissAlert(opts = {}) {
30
- await this.uiautomator2.jwproxy.command(
31
- '/alert/dismiss',
32
- 'POST',
33
- opts
34
- );
35
- },
36
- async postDismissAlert() {
37
- await this.mobileDismissAlert();
38
- },
39
- };
32
+ export async function postAcceptAlert() {
33
+ await this.mobileAcceptAlert();
34
+ }
35
+
36
+ /**
37
+ * @this {AndroidUiautomator2Driver}
38
+ * @param {import('./types').DismissAlertOptions} [opts={}]
39
+ * @returns {Promise<void>}
40
+ */
41
+ export async function mobileDismissAlert(opts = {}) {
42
+ await this.uiautomator2.jwproxy.command(
43
+ '/alert/dismiss',
44
+ 'POST',
45
+ opts
46
+ );
47
+ }
40
48
 
41
- mixin(AlertMixin);
49
+ /**
50
+ * @this {AndroidUiautomator2Driver}
51
+ * @returns {Promise<void>}
52
+ */
53
+ export async function postDismissAlert() {
54
+ await this.mobileDismissAlert();
55
+ }
42
56
 
43
57
  /**
44
- * @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
58
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
45
59
  */
@@ -0,0 +1,42 @@
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 {import('./types').InstallMultipleApksOptions} opts
10
+ * @throws {Error} if an error occured while installing the given APKs.
11
+ * @returns {Promise<void>}
12
+ */
13
+ export async function mobileInstallMultipleApks(opts) {
14
+ if (!_.isArray(opts.apks) || _.isEmpty(opts.apks)) {
15
+ throw new errors.InvalidArgumentError('No apks are given to install');
16
+ }
17
+ const apks = await B.all(
18
+ opts.apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
19
+ );
20
+ await this.adb.installMultipleApks(apks, opts.options);
21
+ }
22
+
23
+ /**
24
+ * Puts the app to background and waits the given number of seconds Then restores the app
25
+ * if necessary. The call is blocking.
26
+ * @this {AndroidUiautomator2Driver}=
27
+ * @param {import('./types').BackgroundAppOptions} [opts={}]
28
+ * @returns {Promise<void>}
29
+ */
30
+ export async function mobileBackgroundApp(opts = {}) {
31
+ const {seconds = -1} = opts;
32
+ await this.background(seconds);
33
+ }
34
+
35
+ /**
36
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
37
+ */
38
+
39
+ /**
40
+ * @template [T=any]
41
+ * @typedef {import('@appium/types').StringRecord<T>} StringRecord
42
+ */
@@ -1,96 +1,16 @@
1
- // @ts-check
2
-
3
- import {mixin} from './mixins';
4
- import _ from 'lodash';
5
- import {fs, tempDir} from 'appium/support';
6
-
7
1
  /**
8
- * @type {import('./mixins').UIA2AppStringsMixin}
9
- * @satisfies {import('@appium/types').ExternalDriver}
2
+ * Retrives app strings from its resources for the given language
3
+ * or the default device language.
4
+ * @this {AndroidUiautomator2Driver}
5
+ * @param {import('./types').GetAppStringsOptions} [opts={}]
6
+ * @returns {Promise<StringRecord>}
10
7
  */
11
- const AppStringsMixin = {
12
- async getStrings(language) {
13
- if (!language) {
14
- language = await this.adb.getDeviceLanguage();
15
- this.log.info(`No language specified, returning strings for: ${language}`);
16
- }
17
-
18
- /**
19
- * Clients require the resulting mapping to have both keys
20
- * and values of type string
21
- * @param {StringRecord} mapping
22
- */
23
- const preprocessStringsMap = function (mapping) {
24
- /** @type {StringRecord} */
25
- const result = {};
26
- for (const [key, value] of _.toPairs(mapping)) {
27
- result[key] = _.isString(value) ? value : JSON.stringify(value);
28
- }
29
- return result;
30
- };
31
-
32
- if (this.apkStrings[language]) {
33
- // Return cached strings
34
- return preprocessStringsMap(this.apkStrings[language]);
35
- }
36
-
37
- if (!this.opts.app && !this.opts.appPackage) {
38
- this.log.errorAndThrow("One of 'app' or 'appPackage' capabilities should must be specified");
39
- throw new Error(); // unreachable
40
- }
41
-
42
- let app = this.opts.app;
43
- const tmpRoot = await tempDir.openDir();
44
- try {
45
- if (!app) {
46
- try {
47
- app = await this.adb.pullApk(/** @type {string} */ (this.opts.appPackage), tmpRoot);
48
- } catch (err) {
49
- this.log.errorAndThrow(
50
- `Failed to pull an apk from '${this.opts.appPackage}'. Original error: ${
51
- /** @type {Error} */ (err).message
52
- }`
53
- );
54
- throw new Error(); // unreachable
55
- }
56
- }
57
-
58
- if (!(await fs.exists(app))) {
59
- this.log.errorAndThrow(`The app at '${app}' does not exist`);
60
- throw new Error(); // unreachable
61
- }
62
-
63
- try {
64
- const {apkStrings} = await this.adb.extractStringsFromApk(app, language, tmpRoot);
65
- this.apkStrings[language] = apkStrings;
66
- return preprocessStringsMap(apkStrings);
67
- } catch (err) {
68
- this.log.errorAndThrow(
69
- `Cannot extract strings from '${app}'. Original error: ${
70
- /** @type {Error} */ (err).message
71
- }`
72
- );
73
- throw new Error(); // unreachable
74
- }
75
- } finally {
76
- await fs.rimraf(tmpRoot);
77
- }
78
- },
79
-
80
- /**
81
- * Retrives app strings from its resources for the given language
82
- * or the default device language.
83
- *
84
- * @returns App strings map
85
- */
86
- async mobileGetAppStrings(opts) {
87
- return await this.getStrings(opts?.language);
88
- },
89
- };
90
-
91
- mixin(AppStringsMixin);
8
+ export async function mobileGetAppStrings(opts) {
9
+ return await this.getStrings(opts?.language);
10
+ }
92
11
 
93
12
  /**
94
13
  * @typedef {import('appium-adb').ADB} ADB
95
14
  * @typedef {import('@appium/types').StringRecord} StringRecord
15
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
96
16
  */
@@ -1,33 +1,23 @@
1
- // @ts-check
2
-
3
- import {mixin} from './mixins';
4
1
 
5
2
  /**
6
- * @type {import('./mixins').UIA2BatteryMixin}
7
- * @satisfies {import('@appium/types').ExternalDriver}
3
+ * Reads the battery information from the device under test.
4
+ * @this {AndroidUiautomator2Driver}
5
+ * @returns {Promise<import('./types').BatteryInfo>} The actual battery info
8
6
  */
9
- const BatteryMixin = {
10
- /**
11
- * Reads the battery information from the device under test.
12
- *
13
- * @returns The actual battery info
14
- */
15
- async mobileGetBatteryInfo() {
16
- const result = /** @type {import('./types').MapKey<BatteryInfo, 'state', 'status'>} */ (
17
- await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
18
- this.uiautomator2
19
- ).jwproxy.command('/appium/device/battery_info', 'GET', {})
20
- );
21
- const batteryInfo = /** @type {any} */ (result);
22
- // Give it the same name as in iOS
23
- batteryInfo.state = result.status;
24
- delete batteryInfo.status;
25
- return /** @type {BatteryInfo} */ (batteryInfo);
26
- },
27
- };
28
-
29
- mixin(BatteryMixin);
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
+ }
30
19
 
31
20
  /**
32
21
  * @typedef {import('./types').BatteryInfo} BatteryInfo
22
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
33
23
  */