appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
71 lines • 3.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobileResetPermission = mobileResetPermission;
exports.mobileGetPermission = mobileGetPermission;
exports.mobileSetPermissions = mobileSetPermissions;
const lodash_1 = __importDefault(require("lodash"));
const enum_1 = require("./enum");
const utils_1 = require("../utils");
/**
* Resets the given permission for the active application under test.
* Works for both Simulator and real devices using Xcode SDK 11.4+
*
* @param service - One of the available service names. This could also be an integer protected resource identifier; see [this list](https://developer.apple.com/documentation/xctest/xcuiprotectedresource?language=objc)
* @throws If permission reset fails on the device.
*/
async function mobileResetPermission(service) {
if (!service) {
throw new Error(`The 'service' option is expected to be present`);
}
let resource;
if (lodash_1.default.isString(service)) {
resource = enum_1.PermissionService[lodash_1.default.toLower(service)];
if (!resource) {
throw new Error(`The 'service' value must be one of ` + `${JSON.stringify(lodash_1.default.keys(enum_1.PermissionService))}`);
}
}
else if (lodash_1.default.isInteger(service)) {
resource = service;
}
else {
throw new Error(`The 'service' value must be either a string or an integer. ` +
`'${service}' is passed instead`);
}
await this.proxyCommand('/wda/resetAppAuth', 'POST', { resource });
}
/**
* Gets application permission state on a simulated device.
*
* **This method requires [WIX applesimutils](https://github.com/wix/AppleSimulatorUtils) to be installed on the Appium server host.**
*
* @param bundleId - Bundle identifier of the target application
* @param service - Service name
* @returns Either 'yes', 'no', 'unset' or 'limited'
* @throws If permission getting fails or the device is not a Simulator.
* @group Simulator Only
*/
async function mobileGetPermission(bundleId, service) {
if (!service) {
throw new Error(`The 'service' option is expected to be present`);
}
return (await (0, utils_1.requireSimulator)(this, 'Getting permission').getPermission(bundleId, String(service)));
}
/**
* Set application permission state on Simulator.
*
* @param access - One or more access rules to set.
* @param bundleId - Bundle identifier of the target application
* @since Xcode SDK 11.4
* @throws If permission setting fails or the device is not a Simulator.
* @group Simulator Only
*/
async function mobileSetPermissions(access, bundleId) {
if (!lodash_1.default.isPlainObject(access)) {
throw new Error(`The 'access' option is expected to be a map`);
}
await (0, utils_1.requireSimulator)(this, 'Setting permissions').setPermissions(bundleId, access);
}
//# sourceMappingURL=permissions.js.map