Skip to content

Commit

Permalink
feat: Add mobile: function to reset permissions (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Sep 23, 2020
1 parent 39eb65a commit 67ccb36
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
11 changes: 8 additions & 3 deletions ci-jobs/pr-validation-build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Pull request validation job
variables:
- name: SHOW_XCODE_LOG
value: true

jobs:
- template: ./templates/xcuitest-e2e-template.yml
parameters:
name: iPhoneX_13_4
iosVersion: 13.4
xcodeVersion: 11.4
name: iPhoneX_13_7
iosVersion: 13.7
xcodeVersion: 11.7
deviceName: "iPhone X"
tvosVersion: 13.4
tvosName: AppleTV_13_4
tvosDeviceName: "Apple TV"
vmImage: 'macOS-10.15'
3 changes: 2 additions & 1 deletion ci-jobs/templates/xcuitest-e2e-template.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
name: ''
iosVersion: ''
tvosVersion: ''
xcodeVersion: ''
deviceName: 'iphone simulator'
skipTvOs: False
Expand Down Expand Up @@ -63,7 +64,7 @@ jobs:
- template: ./ios-e2e-template.yml
parameters:
name: e2e_tvos_${{ parameters.tvosName }}
iosVersion: ${{ parameters.iosVersion }}
iosVersion: ${{ parameters.tvosVersion }}
skipTvOs: ${{ parameters.skipTvOs }}
xcodeVersion: ${{ parameters.xcodeVersion }}
deviceName: ${{ parameters.tvosDeviceName }}
Expand Down
1 change: 1 addition & 0 deletions lib/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ extensions.executeMobile = async function executeMobile (mobileCommand, opts = {

getPermission: 'mobileGetPermission',
setPermission: 'mobileSetPermissions',
resetPermission: 'mobileResetPermission',

getAppearance: 'mobileGetAppearance',
setAppearance: 'mobileSetAppearance',
Expand Down
62 changes: 61 additions & 1 deletion lib/commands/permissions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import _ from 'lodash';


let commands = {}, helpers = {}, extensions = {};
const commands = {}, helpers = {}, extensions = {};

// https://developer.apple.com/documentation/xctest/xcuiprotectedresource?language=objc
const RESOURCE_NAME_TO_ID_MAP = {
calendar: 2,
camera: 6,
contacts: 1,
health: -0x40000003,
homekit: 8,
keyboardnet: -0x40000001,
location: -0x40000002,
medialibrary: 7,
microphone: 5,
photos: 4,
reminders: 3,
systemroot: 0x40000000,
userdesktop: 0x40000001,
userdocuments: 0x40000003,
userdownloads: 0x40000002,
bluetooth: -0x40000000,
};

function requireSimulator (driver) {
if (!driver.isSimulator()) {
Expand All @@ -17,6 +37,46 @@ function requireOptions (opts = {}) {
}


/**
* @typedef {Object} ResetPermissionOptions
*
* @property {!string|number} service - One of available service names. See the keys of
* `RESOURCE_NAME_TO_ID_MAP` to get the list of supported service names.
* This could also be an integer protected resource identifier taken from
* https://developer.apple.com/documentation/xctest/xcuiprotectedresource?language=objc
*/

/**
* Resets the given permission for the active application under test.
* Works for both Simulator and real devices using Xcode SDK 11.4+
*
* @param {ResetPermissionOptions} opts - Permission options.
* @throws {Error} If permission reset fails on the device.
*/
commands.mobileResetPermission = async function mobileResetPermission (opts = {}) {
const {
service,
} = opts;
if (!service) {
throw new Error(`The 'service' option is expected to be present`);
}
let resource;
if (_.isString(service)) {
resource = RESOURCE_NAME_TO_ID_MAP[_.toLower(service)];
if (!resource) {
throw new Error(`The 'service' value must be one of ` +
`${JSON.stringify(_.keys(RESOURCE_NAME_TO_ID_MAP))}`);
}
} else if (_.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});
};

/**
* @typedef {Object} GetPermissionOptions
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"appium-ios-simulator": "^3.24.0",
"appium-remote-debugger": "^8.13.0",
"appium-support": "^2.47.1",
"appium-webdriveragent": "^2.22.0",
"appium-webdriveragent": "^2.22.2",
"appium-xcode": "^3.8.0",
"async-lock": "^1.0.0",
"asyncbox": "^2.3.1",
Expand Down

0 comments on commit 67ccb36

Please sign in to comment.