appium-android-driver 6.0.0 → 7.0.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 (112) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -105
  3. package/build/lib/commands/actions.d.ts +0 -1
  4. package/build/lib/commands/actions.d.ts.map +1 -1
  5. package/build/lib/commands/actions.js +14 -139
  6. package/build/lib/commands/actions.js.map +1 -1
  7. package/build/lib/commands/context.d.ts.map +1 -1
  8. package/build/lib/commands/context.js +0 -1
  9. package/build/lib/commands/context.js.map +1 -1
  10. package/build/lib/commands/element.d.ts +0 -1
  11. package/build/lib/commands/element.d.ts.map +1 -1
  12. package/build/lib/commands/element.js +14 -48
  13. package/build/lib/commands/element.js.map +1 -1
  14. package/build/lib/commands/execute.d.ts.map +1 -1
  15. package/build/lib/commands/execute.js +0 -1
  16. package/build/lib/commands/execute.js.map +1 -1
  17. package/build/lib/commands/find.d.ts.map +1 -1
  18. package/build/lib/commands/find.js +1 -1
  19. package/build/lib/commands/find.js.map +1 -1
  20. package/build/lib/commands/general.d.ts +0 -1
  21. package/build/lib/commands/general.d.ts.map +1 -1
  22. package/build/lib/commands/general.js +6 -11
  23. package/build/lib/commands/general.js.map +1 -1
  24. package/build/lib/commands/index.d.ts +23 -23
  25. package/build/lib/commands/mixins.d.ts +2 -6
  26. package/build/lib/commands/mixins.d.ts.map +1 -1
  27. package/build/lib/commands/mixins.js.map +1 -1
  28. package/build/lib/commands/network.d.ts.map +1 -1
  29. package/build/lib/commands/network.js +27 -55
  30. package/build/lib/commands/network.js.map +1 -1
  31. package/build/lib/commands/performance.d.ts +4 -4
  32. package/build/lib/commands/performance.d.ts.map +1 -1
  33. package/build/lib/commands/performance.js +0 -4
  34. package/build/lib/commands/performance.js.map +1 -1
  35. package/build/lib/commands/touch.d.ts +0 -1
  36. package/build/lib/commands/touch.d.ts.map +1 -1
  37. package/build/lib/commands/touch.js +1 -15
  38. package/build/lib/commands/touch.js.map +1 -1
  39. package/build/lib/constraints.d.ts +0 -9
  40. package/build/lib/constraints.d.ts.map +1 -1
  41. package/build/lib/constraints.js +0 -9
  42. package/build/lib/constraints.js.map +1 -1
  43. package/build/lib/driver.d.ts +2 -50
  44. package/build/lib/driver.d.ts.map +1 -1
  45. package/build/lib/driver.js +1 -476
  46. package/build/lib/driver.js.map +1 -1
  47. package/build/lib/helpers/android.d.ts +0 -2
  48. package/build/lib/helpers/android.d.ts.map +1 -1
  49. package/build/lib/helpers/android.js +0 -2
  50. package/build/lib/helpers/android.js.map +1 -1
  51. package/build/lib/helpers/webview.js.map +1 -1
  52. package/build/lib/stubs.d.ts +0 -1
  53. package/build/lib/stubs.d.ts.map +1 -1
  54. package/build/lib/stubs.js +0 -1
  55. package/build/lib/stubs.js.map +1 -1
  56. package/build/lib/utils.d.ts +3 -4
  57. package/build/lib/utils.d.ts.map +1 -1
  58. package/build/lib/utils.js +3 -4
  59. package/build/lib/utils.js.map +1 -1
  60. package/lib/commands/actions.js +15 -163
  61. package/lib/commands/context.js +0 -1
  62. package/lib/commands/element.js +14 -68
  63. package/lib/commands/execute.js +0 -1
  64. package/lib/commands/find.ts +1 -2
  65. package/lib/commands/general.js +6 -11
  66. package/lib/commands/mixins.ts +0 -6
  67. package/lib/commands/network.js +28 -61
  68. package/lib/commands/performance.js +0 -4
  69. package/lib/commands/touch.js +1 -20
  70. package/lib/constraints.ts +0 -9
  71. package/lib/driver.ts +7 -595
  72. package/lib/helpers/android.ts +0 -4
  73. package/lib/helpers/webview.ts +1 -1
  74. package/lib/stubs.ts +0 -1
  75. package/lib/utils.js +4 -5
  76. package/package.json +2 -5
  77. package/bootstrap/README.md +0 -19
  78. package/bootstrap/bin/AppiumBootstrap.jar +0 -0
  79. package/build/index.d.ts +0 -282
  80. package/build/index.d.ts.map +0 -1
  81. package/build/index.js +0 -51
  82. package/build/index.js.map +0 -1
  83. package/build/lib/android-helpers.d.ts +0 -136
  84. package/build/lib/android-helpers.d.ts.map +0 -1
  85. package/build/lib/android-helpers.js +0 -855
  86. package/build/lib/android-helpers.js.map +0 -1
  87. package/build/lib/bootstrap.d.ts +0 -29
  88. package/build/lib/bootstrap.d.ts.map +0 -1
  89. package/build/lib/bootstrap.js +0 -213
  90. package/build/lib/bootstrap.js.map +0 -1
  91. package/build/lib/commands/coverage.d.ts +0 -5
  92. package/build/lib/commands/coverage.d.ts.map +0 -1
  93. package/build/lib/commands/coverage.js +0 -19
  94. package/build/lib/commands/coverage.js.map +0 -1
  95. package/build/lib/desired-caps.d.ts +0 -353
  96. package/build/lib/desired-caps.d.ts.map +0 -1
  97. package/build/lib/desired-caps.js +0 -299
  98. package/build/lib/desired-caps.js.map +0 -1
  99. package/build/lib/uiautomator.d.ts +0 -24
  100. package/build/lib/uiautomator.d.ts.map +0 -1
  101. package/build/lib/uiautomator.js +0 -102
  102. package/build/lib/uiautomator.js.map +0 -1
  103. package/build/lib/unlock-helpers.d.ts +0 -38
  104. package/build/lib/unlock-helpers.d.ts.map +0 -1
  105. package/build/lib/unlock-helpers.js +0 -266
  106. package/build/lib/unlock-helpers.js.map +0 -1
  107. package/build/lib/webview-helpers.d.ts +0 -224
  108. package/build/lib/webview-helpers.d.ts.map +0 -1
  109. package/build/lib/webview-helpers.js +0 -528
  110. package/build/lib/webview-helpers.js.map +0 -1
  111. package/lib/bootstrap.js +0 -227
  112. package/lib/uiautomator.js +0 -109
package/lib/bootstrap.js DELETED
@@ -1,227 +0,0 @@
1
- import UiAutomator from './uiautomator';
2
- import net from 'net';
3
- import path from 'path';
4
- import _ from 'lodash';
5
- import { errorFromCode } from 'appium/driver';
6
- import B from 'bluebird';
7
- import { logger, fs } from '@appium/support';
8
-
9
-
10
- const log = logger.getLogger('AndroidBootstrap');
11
- const COMMAND_TYPES = {
12
- ACTION: 'action',
13
- SHUTDOWN: 'shutdown'
14
- };
15
- const SEND_COMMAND_TIMEOUT = 1 * 60 * 1000;
16
-
17
- /**
18
- * Calculates the path to the current module's root folder
19
- *
20
- * @returns {string} The full path to module root
21
- * @throws {Error} If the current module root folder cannot be determined
22
- */
23
- const getModuleRoot = _.memoize(async function getModuleRoot () {
24
- let currentDir = path.dirname(path.resolve(__filename));
25
- let isAtFsRoot = false;
26
- while (!isAtFsRoot) {
27
- const manifestPath = path.join(currentDir, 'package.json');
28
- try {
29
- if (await fs.exists(manifestPath) &&
30
- JSON.parse(await fs.readFile(manifestPath, 'utf8')).name === 'appium-android-driver') {
31
- return currentDir;
32
- }
33
- } catch (ign) {}
34
- currentDir = path.dirname(currentDir);
35
- isAtFsRoot = currentDir.length <= path.dirname(currentDir).length;
36
- }
37
- throw new Error('Cannot find the root folder of the appium-android-driver Node.js module');
38
- });
39
-
40
- class AndroidBootstrap {
41
- constructor (adb, systemPort = 4724, webSocket = undefined) {
42
- this.adb = adb;
43
- this.systemPort = systemPort;
44
- this.webSocket = webSocket;
45
- this.ignoreUnexpectedShutdown = false;
46
- }
47
-
48
- get onUnexpectedShutdown () {
49
- if (!this._onUnexpectedShutdownPromise) {
50
- let reject;
51
- this._onUnexpectedShutdownPromise = new B(function _onUnexpectedShutdownPromise (_resolve, _reject) {
52
- reject = _reject;
53
- });
54
- this._onUnexpectedShutdownPromise.cancel = reject;
55
- }
56
- return this._onUnexpectedShutdownPromise;
57
- }
58
-
59
- async start (appPackage, disableAndroidWatchers = false, acceptSslCerts = false) {
60
- try {
61
- const startDetector = (s) => /Appium Socket Server Ready/.test(s);
62
- const bootstrapJar = path.resolve(await getModuleRoot(), 'bootstrap', 'bin', 'AppiumBootstrap.jar');
63
-
64
- await this.init();
65
- await this.adb.forwardPort(this.systemPort, 4724);
66
- this.process = await this.uiAutomator.start(
67
- bootstrapJar, 'io.appium.android.bootstrap.Bootstrap',
68
- startDetector,
69
- '-e', 'pkg', appPackage,
70
- '-e', 'disableAndroidWatchers', disableAndroidWatchers,
71
- '-e', 'acceptSslCerts', acceptSslCerts
72
- );
73
-
74
- // process the output
75
- this.process.on('output', (stdout, stderr) => {
76
- const alertRe = /Emitting system alert message/;
77
- if (alertRe.test(stdout)) {
78
- log.debug('Emitting alert message...');
79
- if (this.webSocket) {
80
- this.webSocket.sockets.emit('alert', {message: stdout});
81
- }
82
- }
83
-
84
- // the bootstrap logger wraps its own log lines with
85
- // [APPIUM-UIAUTO] ... [APPIUM-UIAUTO]
86
- // and leaves actual UiAutomator logs as they are
87
- let stdoutLines = (stdout || '').split('\n');
88
- const uiautoLog = /\[APPIUM-UIAUTO\](.+)\[\/APPIUM-UIAUTO\]/;
89
- for (let line of stdoutLines) {
90
- if (line.trim()) {
91
- if (uiautoLog.test(line)) {
92
- let innerLine = uiautoLog.exec(line)[1].trim();
93
- let logMethod = log.info.bind(log);
94
- // if the bootstrap log considers something debug, log that as
95
- // debug and not info
96
- if (/\[debug\]/.test(innerLine)) {
97
- logMethod = log.debug.bind(log);
98
- }
99
- logMethod(`[BOOTSTRAP LOG] ${innerLine}`);
100
- } else {
101
- log.debug(`[UIAUTO STDOUT] ${line}`);
102
- }
103
- }
104
- }
105
-
106
- let stderrLines = (stderr || '').split('\n');
107
- for (let line of stderrLines) {
108
- if (line.trim()) {
109
- log.debug(`[UIAUTO STDERR] ${line}`);
110
- }
111
- }
112
- });
113
-
114
- // only return when the socket client has connected
115
- return await new B((resolve, reject) => {
116
- try {
117
- this.socketClient = net.connect(this.systemPort, '127.0.0.1');
118
- // Windows: the socket errors out when ADB restarts. Let's catch it to avoid crashing.
119
- this.socketClient.on('error', (err) => {
120
- if (!this.ignoreUnexpectedShutdown) {
121
- throw new Error(`Android bootstrap socket crashed: ${err}`);
122
- }
123
- });
124
- this.socketClient.once('connect', () => {
125
- log.info('Android bootstrap socket is now connected');
126
- resolve();
127
- });
128
- } catch (err) {
129
- reject(err);
130
- }
131
- });
132
- } catch (err) {
133
- log.errorAndThrow(`Error occured while starting AndroidBootstrap. Original error: ${err}`);
134
- }
135
- }
136
-
137
- async sendCommand (type, extra = {}) {
138
- if (!this.socketClient) {
139
- throw new Error('Socket connection closed unexpectedly');
140
- }
141
-
142
- return await new B((resolve, reject) => {
143
- let cmd = Object.assign({cmd: type}, extra);
144
- let cmdJson = `${JSON.stringify(cmd)} \n`;
145
- log.debug(`Sending command to android: ${_.truncate(cmdJson, {length: 1000}).trim()}`);
146
- this.socketClient.write(cmdJson);
147
- this.socketClient.setEncoding('utf8');
148
- let streamData = '';
149
- let sendCommandTimeoutHandler = null;
150
- this.socketClient.on('data', (data) => {
151
- if (sendCommandTimeoutHandler) {
152
- clearTimeout(sendCommandTimeoutHandler);
153
- }
154
- log.debug('Received command result from bootstrap');
155
- try {
156
- streamData = JSON.parse(streamData + data);
157
- // we successfully parsed JSON so we've got all the data,
158
- // remove the socket listener and evaluate
159
- this.socketClient.removeAllListeners('data');
160
- if (streamData.status === 0) {
161
- return resolve(streamData.value);
162
- }
163
- reject(errorFromCode(streamData.status, streamData.value));
164
- } catch (err) {
165
- if (!_.isString(streamData)) {
166
- log.error('Got an unexpected error inside socket listener');
167
- log.error(err.stack);
168
- return reject(errorFromCode(13, err.message));
169
- }
170
- log.debug(`Stream still not complete, waiting up to ${SEND_COMMAND_TIMEOUT}ms for the data to arrive`);
171
- streamData += data;
172
- sendCommandTimeoutHandler = setTimeout(() => {
173
- const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
174
- log.error(errMsg);
175
- this.socketClient.removeAllListeners('data');
176
- reject(errorFromCode(13, errMsg));
177
- }, SEND_COMMAND_TIMEOUT);
178
- }
179
- });
180
- });
181
- }
182
-
183
- async sendAction (action, params = {}) {
184
- let extra = {action, params};
185
- return await this.sendCommand(COMMAND_TYPES.ACTION, extra);
186
- }
187
-
188
- async shutdown () {
189
- if (!this.uiAutomator) {
190
- log.warn('Cannot shut down Android bootstrap; it has already shut down');
191
- return;
192
- }
193
-
194
- // remove listners so we don't trigger unexpected shutdown
195
- this.uiAutomator.removeAllListeners(UiAutomator.EVENT_CHANGED);
196
- if (this.socketClient) {
197
- await this.sendCommand(COMMAND_TYPES.SHUTDOWN);
198
- }
199
- await this.uiAutomator.shutdown();
200
- this.uiAutomator = null;
201
- }
202
-
203
- // this helper function makes unit testing easier.
204
- async init () { // eslint-disable-line require-await
205
- this.uiAutomator = new UiAutomator(this.adb);
206
-
207
- // Handle unexpected UiAutomator shutdown
208
- this.uiAutomator.on(UiAutomator.EVENT_CHANGED, (msg) => {
209
- if (msg.state === UiAutomator.STATE_STOPPED) {
210
- this.uiAutomator = null;
211
- this.onUnexpectedShutdown.cancel(new Error('UiAUtomator shut down unexpectedly'));
212
- }
213
- });
214
- }
215
-
216
- set ignoreUnexpectedShutdown (ignore) {
217
- log.debug(`${ignore ? 'Ignoring' : 'Watching for'} bootstrap disconnect`);
218
- this._ignoreUnexpectedShutdown = ignore;
219
- }
220
-
221
- get ignoreUnexpectedShutdown () {
222
- return this._ignoreUnexpectedShutdown;
223
- }
224
- }
225
-
226
- export { AndroidBootstrap, COMMAND_TYPES };
227
- export default AndroidBootstrap;
@@ -1,109 +0,0 @@
1
- import events from 'events';
2
- import { logger } from '@appium/support';
3
-
4
-
5
- const log = logger.getLogger('UiAutomator');
6
-
7
- class UiAutomator extends events.EventEmitter {
8
- constructor (adb) {
9
- if (!adb) {
10
- log.errorAndThrow('adb is required to instantiate UiAutomator');
11
- }
12
- super();
13
- this.adb = adb;
14
- this.tempPath = '/data/local/tmp/';
15
- }
16
-
17
- async start (uiAutomatorBinaryPath, className, startDetector, ...extraParams) {
18
- let processIsAlive;
19
- try {
20
- log.debug('Starting UiAutomator');
21
- this.changeState(UiAutomator.STATE_STARTING);
22
-
23
- log.debug('Parsing uiautomator jar');
24
- // expecting a path like /ads/ads/foo.jar or \asd\asd\foo.jar
25
- let jarName = this.parseJarNameFromPath(uiAutomatorBinaryPath);
26
- await this.adb.push(uiAutomatorBinaryPath, this.tempPath);
27
-
28
- // killing any uiautomator existing processes
29
- await this.killUiAutomatorOnDevice();
30
-
31
- log.debug('Starting UIAutomator');
32
- let args = ['shell', 'uiautomator', 'runtest', jarName, '-c', className, ...extraParams];
33
- this.proc = this.adb.createSubProcess(args);
34
-
35
- // handle out-of-bound exit by simply emitting a stopped state
36
- this.proc.on('exit', (code, signal) => {
37
- processIsAlive = false;
38
- // cleanup
39
- if (this.state !== UiAutomator.STATE_STOPPED &&
40
- this.state !== UiAutomator.STATE_STOPPING) {
41
- let msg = `UiAutomator exited unexpectedly with code ${code}, ` +
42
- `signal ${signal}`;
43
- log.error(msg);
44
- } else if (this.state === UiAutomator.STATE_STOPPING) {
45
- log.debug('UiAutomator shut down normally');
46
- }
47
- this.changeState(UiAutomator.STATE_STOPPED);
48
- });
49
-
50
- await this.proc.start(startDetector);
51
- processIsAlive = true;
52
- this.changeState(UiAutomator.STATE_ONLINE);
53
- return this.proc;
54
- } catch (e) {
55
- this.emit(UiAutomator.EVENT_ERROR, e);
56
- if (processIsAlive) {
57
- await this.killUiAutomatorOnDevice();
58
- await this.proc.stop();
59
- }
60
- log.errorAndThrow(e);
61
- }
62
- }
63
-
64
- async shutdown () {
65
- log.debug('Shutting down UiAutomator');
66
- if (this.state !== UiAutomator.STATE_STOPPED) {
67
- this.changeState(UiAutomator.STATE_STOPPING);
68
- await this.proc.stop();
69
- }
70
- await this.killUiAutomatorOnDevice();
71
- this.changeState(UiAutomator.STATE_STOPPED);
72
- }
73
-
74
- parseJarNameFromPath (binaryPath) {
75
- let reTest = /.*(\/|\\)(.*\.jar)/.exec(binaryPath);
76
- if (!reTest) {
77
- throw new Error(`Unable to parse jar name from ${binaryPath}`);
78
- }
79
- let jarName = reTest[2];
80
- log.debug(`Found jar name: '${jarName}'`);
81
- return jarName;
82
- }
83
-
84
- changeState (state) {
85
- log.debug(`Moving to state '${state}'`);
86
- this.state = state;
87
- this.emit(UiAutomator.EVENT_CHANGED, {state});
88
- }
89
-
90
- async killUiAutomatorOnDevice () {
91
- try {
92
- await this.adb.killProcessesByName('uiautomator');
93
- } catch (e) {
94
- log.warn(`Error while killing uiAutomator: ${e}`);
95
- }
96
- }
97
-
98
- }
99
-
100
- UiAutomator.EVENT_ERROR = 'uiautomator_error';
101
- UiAutomator.EVENT_CHANGED = 'stateChanged';
102
- UiAutomator.STATE_STOPPING = 'stopping';
103
- UiAutomator.STATE_STOPPED = 'stopped';
104
- UiAutomator.STATE_STARTING = 'starting';
105
- UiAutomator.STATE_ONLINE = 'online';
106
-
107
-
108
- export { UiAutomator };
109
- export default UiAutomator;