appium-uiautomator2-driver 3.0.6 → 3.0.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.
- package/CHANGELOG.md +7 -0
- package/build/lib/constraints.d.ts +3 -0
- package/build/lib/constraints.d.ts.map +1 -1
- package/build/lib/uiautomator2.d.ts +9 -5
- package/build/lib/uiautomator2.d.ts.map +1 -1
- package/build/lib/uiautomator2.js +49 -69
- package/build/lib/uiautomator2.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/uiautomator2.js +52 -75
- package/npm-shrinkwrap.json +354 -375
- package/package.json +3 -3
package/lib/uiautomator2.js
CHANGED
|
@@ -6,13 +6,9 @@ import {
|
|
|
6
6
|
TEST_APK_PATH as testApkPath,
|
|
7
7
|
version as serverVersion
|
|
8
8
|
} from 'appium-uiautomator2-server';
|
|
9
|
-
import {
|
|
10
|
-
util, logger, tempDir, fs, timing
|
|
11
|
-
} from 'appium/support';
|
|
9
|
+
import { util, logger, timing } from 'appium/support';
|
|
12
10
|
import B from 'bluebird';
|
|
13
|
-
import {isWriteable, signApp} from './helpers';
|
|
14
11
|
import axios from 'axios';
|
|
15
|
-
import path from 'path';
|
|
16
12
|
|
|
17
13
|
const REQD_PARAMS = ['adb', 'tmpDir', 'host', 'systemPort', 'devicePort', 'disableWindowAnimation'];
|
|
18
14
|
const SERVER_LAUNCH_TIMEOUT = 30000;
|
|
@@ -78,30 +74,18 @@ class UiAutomator2Server {
|
|
|
78
74
|
this.jwproxy.didInstrumentationExit = false;
|
|
79
75
|
}
|
|
80
76
|
|
|
81
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} appPath
|
|
79
|
+
* @param {string} appId
|
|
80
|
+
* @returns {Promise<{installState: import('appium-adb').InstallState, appPath: string; appId: string}>}
|
|
81
|
+
*/
|
|
82
|
+
async prepareServerPackage(appPath, appId) {
|
|
82
83
|
const resultInfo = {
|
|
83
|
-
wasSigned: false,
|
|
84
84
|
installState: this.adb.APP_INSTALL_STATE.NOT_INSTALLED,
|
|
85
85
|
appPath,
|
|
86
86
|
appId,
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
if (await this.adb.checkApkCert(resultInfo.appPath, appId)) {
|
|
90
|
-
resultInfo.wasSigned = true;
|
|
91
|
-
} else {
|
|
92
|
-
if (!await isWriteable(appPath)) {
|
|
93
|
-
this.log.warn(
|
|
94
|
-
`Server package at '${appPath}' is not writeable. ` +
|
|
95
|
-
`Will copy it into the temporary location at '${tmpRoot}' as a workaround. ` +
|
|
96
|
-
`Consider making this file writeable manually in order to improve the performance of session startup.`
|
|
97
|
-
);
|
|
98
|
-
const dstPath = path.resolve(tmpRoot, path.basename(appPath));
|
|
99
|
-
await fs.copyFile(appPath, dstPath);
|
|
100
|
-
resultInfo.appPath = dstPath;
|
|
101
|
-
}
|
|
102
|
-
await signApp(this.adb, resultInfo.appPath);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
89
|
if (appId === SERVER_TEST_PACKAGE_ID && await this.adb.isAppInstalled(appId)) {
|
|
106
90
|
// There is no point in getting the state for the test server,
|
|
107
91
|
// since it does not contain any version info
|
|
@@ -119,59 +103,52 @@ class UiAutomator2Server {
|
|
|
119
103
|
* @param {number} installTimeout - Installation timeout
|
|
120
104
|
*/
|
|
121
105
|
async installServerApk (installTimeout = SERVER_INSTALL_RETRIES * 1000) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
].map(({appPath, appId}) => this.prepareServerPackage(appPath, appId, tmpRoot))
|
|
134
|
-
);
|
|
106
|
+
const packagesInfo = await B.all(
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
appPath: apkPath,
|
|
110
|
+
appId: SERVER_PACKAGE_ID,
|
|
111
|
+
}, {
|
|
112
|
+
appPath: testApkPath,
|
|
113
|
+
appId: SERVER_TEST_PACKAGE_ID,
|
|
114
|
+
},
|
|
115
|
+
].map(({appPath, appId}) => this.prepareServerPackage(appPath, appId))
|
|
116
|
+
);
|
|
135
117
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.log.info(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
await B.all(packagesInfo.map(({appPath}) => installPkg(appPath)));
|
|
172
|
-
}
|
|
173
|
-
} finally {
|
|
174
|
-
await fs.rimraf(tmpRoot);
|
|
118
|
+
this.log.debug(`Server packages status: ${JSON.stringify(packagesInfo)}`);
|
|
119
|
+
// Enforce server packages reinstall if any of the packages is not installed, while the other is
|
|
120
|
+
const shouldUninstallServerPackages = (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED)
|
|
121
|
+
&& !packagesInfo.every(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED));
|
|
122
|
+
// Install must always follow uninstall. Also, perform the install if
|
|
123
|
+
// any of server packages is not installed or is outdated
|
|
124
|
+
const shouldInstallServerPackages = shouldUninstallServerPackages || packagesInfo.some(({installState}) => [
|
|
125
|
+
this.adb.APP_INSTALL_STATE.NOT_INSTALLED,
|
|
126
|
+
this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED,
|
|
127
|
+
].includes(installState));
|
|
128
|
+
this.log.info(`Server packages are ${shouldInstallServerPackages ? '' : 'not '}going to be (re)installed`);
|
|
129
|
+
if (shouldInstallServerPackages && shouldUninstallServerPackages) {
|
|
130
|
+
this.log.info('Full packages reinstall is going to be performed');
|
|
131
|
+
}
|
|
132
|
+
if (shouldUninstallServerPackages) {
|
|
133
|
+
const silentUninstallPkg = async (pkgId) => {
|
|
134
|
+
try {
|
|
135
|
+
await this.adb.uninstallApk(pkgId);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
this.log.info(`Cannot uninstall '${pkgId}': ${err.message}`);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
await B.all(packagesInfo.map(({appId}) => silentUninstallPkg(appId)));
|
|
141
|
+
}
|
|
142
|
+
if (shouldInstallServerPackages) {
|
|
143
|
+
const installPkg = async (pkgPath) => {
|
|
144
|
+
await this.adb.install(pkgPath, {
|
|
145
|
+
noIncremental: true,
|
|
146
|
+
replace: true,
|
|
147
|
+
timeout: installTimeout,
|
|
148
|
+
timeoutCapName: 'uiautomator2ServerInstallTimeout'
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
await B.all(packagesInfo.map(({appPath}) => installPkg(appPath)));
|
|
175
152
|
}
|
|
176
153
|
|
|
177
154
|
await this.verifyServicesAvailability();
|