appium-android-driver 5.7.2 → 5.8.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.
- package/CHANGELOG.md +9 -0
- package/build/index.js +1 -2
- package/build/lib/android-helpers.js +2 -26
- package/build/lib/android-helpers.js.map +1 -1
- package/build/lib/bootstrap.js +1 -8
- package/build/lib/bootstrap.js.map +1 -1
- package/build/lib/commands/actions.js +1 -2
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.js +1 -2
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-management.js +2 -16
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/context.js +1 -15
- package/build/lib/commands/context.js.map +1 -1
- package/build/lib/commands/element.js +1 -4
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/emu-console.js +1 -3
- package/build/lib/commands/emu-console.js.map +1 -1
- package/build/lib/commands/file-actions.js +1 -13
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/find.js +1 -5
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.js +1 -83
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/index.js +3 -3
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/intent.js +1 -5
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/log.js +1 -4
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-projection.js +1 -5
- package/build/lib/commands/media-projection.js.map +1 -1
- package/build/lib/commands/network.js +1 -7
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/commands/performance.js +1 -8
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.js +116 -0
- package/build/lib/commands/permissions.js.map +1 -0
- package/build/lib/commands/recordscreen.js +1 -3
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/shell.js +4 -4
- package/build/lib/commands/shell.js.map +1 -1
- package/build/lib/commands/streamscreen.js +4 -9
- package/build/lib/commands/streamscreen.js.map +1 -1
- package/build/lib/commands/system-bars.js +1 -4
- package/build/lib/commands/system-bars.js.map +1 -1
- package/build/lib/commands/touch.js +1 -9
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/desired-caps.js +2 -4
- package/build/lib/desired-caps.js.map +1 -1
- package/build/lib/driver.js +1 -20
- package/build/lib/driver.js.map +1 -1
- package/build/lib/uiautomator.js +1 -3
- package/build/lib/uiautomator.js.map +1 -1
- package/build/lib/unlock-helpers.js +1 -3
- package/build/lib/unlock-helpers.js.map +1 -1
- package/build/lib/utils.js +4 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lib/webview-helpers.js +1 -13
- package/build/lib/webview-helpers.js.map +1 -1
- package/lib/commands/general.js +0 -112
- package/lib/commands/index.js +2 -0
- package/lib/commands/permissions.js +169 -0
- package/lib/commands/shell.js +2 -3
- package/lib/utils.js +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { errors } from 'appium/driver';
|
|
3
|
+
import B from 'bluebird';
|
|
4
|
+
import { ADB_SHELL_FEATURE } from '../utils';
|
|
5
|
+
|
|
6
|
+
const commands = {};
|
|
7
|
+
|
|
8
|
+
const ALL_PERMISSIONS_MAGIC = 'all';
|
|
9
|
+
const PM_ACTION = Object.freeze({
|
|
10
|
+
GRANT: 'grant',
|
|
11
|
+
REVOKE: 'revoke',
|
|
12
|
+
});
|
|
13
|
+
const APPOPS_ACTION = Object.freeze({
|
|
14
|
+
ALLOW: 'allow',
|
|
15
|
+
DENY: 'deny',
|
|
16
|
+
IGNORE: 'ignore',
|
|
17
|
+
DEFAULT: 'default',
|
|
18
|
+
});
|
|
19
|
+
const PERMISSION_TARGET = Object.freeze({
|
|
20
|
+
PM: 'pm',
|
|
21
|
+
APPOPS: 'appops',
|
|
22
|
+
});
|
|
23
|
+
const PERMISSIONS_TYPE = Object.freeze({
|
|
24
|
+
DENIED: 'denied',
|
|
25
|
+
GRANTED: 'granted',
|
|
26
|
+
REQUESTED: 'requested',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function changePermissionsViaPm (permissions, appPackage, action) {
|
|
30
|
+
if (!_.values(PM_ACTION).includes(action)) {
|
|
31
|
+
throw new errors.InvalidArgumentError(`Unknown action '${action}'. ` +
|
|
32
|
+
`Only ${JSON.stringify(_.values(PM_ACTION))} actions are supported`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let affectedPermissions = _.isArray(permissions) ? permissions : [permissions];
|
|
36
|
+
if (_.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
|
|
37
|
+
const dumpsys = await this.adb.shell(['dumpsys', 'package', appPackage]);
|
|
38
|
+
const grantedPermissions = await this.adb.getGrantedPermissions(appPackage, dumpsys);
|
|
39
|
+
if (action === PM_ACTION.GRANT) {
|
|
40
|
+
const reqPermissons = await this.adb.getReqPermissions(appPackage, dumpsys);
|
|
41
|
+
affectedPermissions = _.difference(reqPermissons, grantedPermissions);
|
|
42
|
+
} else {
|
|
43
|
+
affectedPermissions = grantedPermissions;
|
|
44
|
+
}
|
|
45
|
+
if (_.isEmpty(affectedPermissions)) {
|
|
46
|
+
this.log.info(`'${appPackage}' contains no permissions to ${action}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (action === PM_ACTION.GRANT) {
|
|
52
|
+
await this.adb.grantPermissions(appPackage, affectedPermissions);
|
|
53
|
+
} else {
|
|
54
|
+
await B.all(affectedPermissions.map((name) => this.adb.revokePermission(appPackage, name)));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function changePermissionsViaAppops (permissions, appPackage, action) {
|
|
59
|
+
if (!_.values(APPOPS_ACTION).includes(action)) {
|
|
60
|
+
throw new errors.InvalidArgumentError(`Unknown action '${action}'. ` +
|
|
61
|
+
`Only ${JSON.stringify(_.values(APPOPS_ACTION))} actions are supported`);
|
|
62
|
+
}
|
|
63
|
+
if (_.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
|
|
64
|
+
throw new errors.InvalidArgumentError(`'${ALL_PERMISSIONS_MAGIC}' permission is only supported for ` +
|
|
65
|
+
`'${PERMISSION_TARGET.PM}' target. ` +
|
|
66
|
+
`Check AppOpsManager.java from Android platform sources to get the full list of supported AppOps permissions`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const promises = (_.isArray(permissions) ? permissions : [permissions])
|
|
70
|
+
.map((permission) => this.adb.shell(['appops', 'set', appPackage, permission, action]));
|
|
71
|
+
await B.all(promises);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {Object} ChangePermissionsOptions
|
|
76
|
+
* @property {!string|Array<string>} permissions
|
|
77
|
+
* If `target` is set to 'pm':
|
|
78
|
+
* The full name of the permission to be changed
|
|
79
|
+
* or a list of permissions. Check https://developer.android.com/reference/android/Manifest.permission
|
|
80
|
+
* to get the full list of standard Android permssion names. Mandatory argument.
|
|
81
|
+
* If 'all' magic string is passed then the chosen action is going to be applied to all
|
|
82
|
+
* permisisons requested/granted by 'appPackage'.
|
|
83
|
+
* If `target` is set to 'appops':
|
|
84
|
+
* The full name of the appops permission to be changed
|
|
85
|
+
* or a list of permissions. Check AppOpsManager.java sources to get the full list of
|
|
86
|
+
* supported appops permission names for the given Android pklatform.
|
|
87
|
+
* Examples: 'ACTIVITY_RECOGNITION', 'SMS_FINANCIAL_TRANSACTIONS', 'READ_SMS', 'ACCESS_NOTIFICATIONS'.
|
|
88
|
+
* The 'all' magic string is unsupported.
|
|
89
|
+
* @property {string} appPackage [this.opts.appPackage] The application package to set change
|
|
90
|
+
* permissions on. Defaults to the package name under test.
|
|
91
|
+
* @property {string} action [grant|allow] One of `PM_ACTION` values if `target` is set to 'pm',
|
|
92
|
+
* otherwise one of `APPOPS_ACTION` values
|
|
93
|
+
* @property {string} target [pm] Either 'pm' or 'appops'. The 'appops' one requires
|
|
94
|
+
* 'adb_shell' server security option to be enabled.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Changes package permissions in runtime.
|
|
99
|
+
*
|
|
100
|
+
* @param {?ChangePermissionsOptions} opts - Available options mapping.
|
|
101
|
+
* @throws {Error} if there was a failure while changing permissions
|
|
102
|
+
*/
|
|
103
|
+
commands.mobileChangePermissions = async function mobileChangePermissions (opts = {}) {
|
|
104
|
+
const {
|
|
105
|
+
permissions,
|
|
106
|
+
appPackage = this.opts.appPackage,
|
|
107
|
+
action = _.toLower(opts.target) === PERMISSION_TARGET.APPOPS ? APPOPS_ACTION.ALLOW : PM_ACTION.GRANT,
|
|
108
|
+
target = PERMISSION_TARGET.PM,
|
|
109
|
+
} = opts;
|
|
110
|
+
if (_.isNil(permissions)) {
|
|
111
|
+
throw new errors.InvalidArgumentError(`'permissions' argument is required`);
|
|
112
|
+
}
|
|
113
|
+
if (_.isEmpty(permissions)) {
|
|
114
|
+
throw new errors.InvalidArgumentError(`'permissions' argument must not be empty`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
switch (_.toLower(target)) {
|
|
118
|
+
case PERMISSION_TARGET.PM:
|
|
119
|
+
return await changePermissionsViaPm.bind(this)(permissions, appPackage, _.toLower(action));
|
|
120
|
+
case PERMISSION_TARGET.APPOPS:
|
|
121
|
+
this.ensureFeatureEnabled(ADB_SHELL_FEATURE);
|
|
122
|
+
return await changePermissionsViaAppops.bind(this)(permissions, appPackage, _.toLower(action));
|
|
123
|
+
default:
|
|
124
|
+
throw new errors.InvalidArgumentError(`'target' argument must be one of: ${_.values(PERMISSION_TARGET)}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {Object} GetPermissionsOptions
|
|
130
|
+
* @property {string} type [requested] - One of possible permission types to get.
|
|
131
|
+
* Can be any of `PERMISSIONS_TYPE` values.
|
|
132
|
+
* @property {string} appPackage [this.opts.appPackage] - The application package to set change
|
|
133
|
+
* permissions on. Defaults to the package name under test.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gets runtime permissions list for the given application package.
|
|
138
|
+
*
|
|
139
|
+
* @param {GetPermissionsOptions} opts - Available options mapping.
|
|
140
|
+
* @returns {Array<string>} The list of retrieved permissions for the given type
|
|
141
|
+
* (can also be empty).
|
|
142
|
+
* @throws {Error} if there was an error while getting permissions.
|
|
143
|
+
*/
|
|
144
|
+
commands.mobileGetPermissions = async function mobileGetPermissions (opts = {}) {
|
|
145
|
+
const {
|
|
146
|
+
type = PERMISSIONS_TYPE.REQUESTED,
|
|
147
|
+
appPackage = this.opts.appPackage,
|
|
148
|
+
} = opts;
|
|
149
|
+
|
|
150
|
+
let actionFunc;
|
|
151
|
+
switch (_.toLower(type)) {
|
|
152
|
+
case PERMISSIONS_TYPE.REQUESTED:
|
|
153
|
+
actionFunc = (pkg) => this.adb.getReqPermissions(pkg);
|
|
154
|
+
break;
|
|
155
|
+
case PERMISSIONS_TYPE.GRANTED:
|
|
156
|
+
actionFunc = (pkg) => this.adb.getGrantedPermissions(pkg);
|
|
157
|
+
break;
|
|
158
|
+
case PERMISSIONS_TYPE.DENIED:
|
|
159
|
+
actionFunc = (pkg) => this.adb.getDeniedPermissions(pkg);
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
throw new errors.InvalidArgumentError(`Unknown permissions type '${type}'. ` +
|
|
163
|
+
`Only ${JSON.stringify(_.values(PERMISSIONS_TYPE))} types are supported`);
|
|
164
|
+
}
|
|
165
|
+
return await actionFunc(appPackage);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export { commands };
|
|
169
|
+
export default commands;
|
package/lib/commands/shell.js
CHANGED
|
@@ -2,10 +2,9 @@ import _ from 'lodash';
|
|
|
2
2
|
import { exec } from 'teen_process';
|
|
3
3
|
import { util } from '@appium/support';
|
|
4
4
|
import { errors } from 'appium/driver';
|
|
5
|
+
import { ADB_SHELL_FEATURE } from '../utils';
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
let commands = {};
|
|
7
|
+
const commands = {};
|
|
9
8
|
|
|
10
9
|
commands.mobileShell = async function mobileShell (opts = {}) {
|
|
11
10
|
this.ensureFeatureEnabled(ADB_SHELL_FEATURE);
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { errors } from 'appium/driver';
|
|
3
3
|
|
|
4
|
+
export const ADB_SHELL_FEATURE = 'adb_shell';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Assert the presence of particular keys in the given object
|
|
@@ -16,4 +17,4 @@ export function requireArgs (argNames, opts = {}) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
return opts;
|
|
19
|
-
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"mobile",
|
|
10
10
|
"mobile testing"
|
|
11
11
|
],
|
|
12
|
-
"version": "5.
|
|
12
|
+
"version": "5.8.0",
|
|
13
13
|
"author": "Appium Contributors",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"repository": {
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"pre-commit": "^1.1.3",
|
|
117
117
|
"rimraf": "^3.0.2",
|
|
118
118
|
"semantic-release": "^19.0.2",
|
|
119
|
-
"sinon": "^
|
|
119
|
+
"sinon": "^15.0.0",
|
|
120
120
|
"xpath": "^0.x"
|
|
121
121
|
}
|
|
122
122
|
}
|