appium-uiautomator2-driver
Version:
UiAutomator2 integration for Appium
44 lines • 1.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWriteable = isWriteable;
exports.signApp = signApp;
const node_path_1 = __importDefault(require("node:path"));
const support_1 = require("appium/support");
/**
* @param filePath - Path to check
* @returns Whether the file is writeable by the current process
*/
async function isWriteable(filePath) {
try {
await support_1.fs.access(filePath, support_1.fs.constants.W_OK);
if (support_1.system.isWindows()) {
// On operating systems, where access-control policies may
// limit access to the file system, `fs.access` does not work
// as expected. See https://groups.google.com/forum/#!topic/nodejs/qmZtIwDRSYo
// for more details
await support_1.fs.close(await support_1.fs.open(filePath, 'r+'));
}
return true;
}
catch {
return false;
}
}
/**
* Ensures the app at `appPath` is writeable, then signs it with the given ADB instance.
*
* @param adb - ADB instance used to sign the APK
* @param appPath - Path to the application package
*/
async function signApp(adb, appPath) {
if (!(await isWriteable(appPath))) {
throw new Error(`The application at '${appPath}' is not writeable. ` +
`Please grant write permissions to this file or to its parent folder '${node_path_1.default.dirname(appPath)}' ` +
`for the Appium process, so it could sign the application`);
}
await adb.sign(appPath);
}
//# sourceMappingURL=app.js.map