Skip to content

Commit

Permalink
Update touch ID enrolment setting (#506)
Browse files Browse the repository at this point in the history
* Update touch ID enrolment setting

* Improve docstring

* Restore functional tests

* Skip tests without creation a sesison
  • Loading branch information
Mykola Mokhnach authored and imurchie committed Aug 17, 2017
1 parent a950ff7 commit 2438208
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 47 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ Differences noted here
|`useCarthageSsl`|Use SSL to download dependencies for WebDriverAgent. Defaults to `false`|e.g., `true`|
|`shouldUseSingletonTestManager`|Use default proxy for test management within WebDriverAgent. Setting this to `false` sometimes helps with socket hangup problems. Defaults to `true`.|e.g., `false`|
|`startIWDP`|Set this to `true` if you want to start ios_webkit_debug proxy server automatically for accessing webviews on iOS. The capatibility only works for real device automation. Defaults to `false`.|e.g., `true`|
|`allowTouchIdEnroll`|Set this to `true` if you want to enroll simulator for touch id. Defaults to `false`.|e.g., `true`|
|`calendarAccessAuthorized`|Set this to `true` if you want to enable calendar access on IOS Simulator with given bundleId. Set to `false`, if you want to disable calendar access on IOS Simulator with given bundleId. If not set, the calendar authorization status will not be set.|e.g., `true`|
|`isHeadless`|Set this capability to `true` if automated tests are running on Simulator and the device display is not needed to be visible. This only has an effect since Xcode9 and only for simulators. All running instances of Simulator UI are going to be automatically terminated if headless test is started. `false` is the default value.|e.g., `true`|

Expand Down
23 changes: 14 additions & 9 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ commands.touchId = async function (match = true) {
return await this.proxyCommand('/wda/touch_id', 'POST', {match});
};

/*
* Toggle enrollment of touchId (Simuulator only)
/**
* Toggle enrollment of touchId (Simulator only)
*
* @param {boolean} enabled - Equals to true if TouchID enrollment should be enabled.
* All the further calls to this method will only change the state of TouchID
* enrollment if _enabled_ argument value has been inverted. It is mandatory
* that Appium daemon process (or its parent process) has access to MacOS accessibility
* in System Preferences, otherwise this call will throw an error.
* @throws errors.UnknownError If current device is a real device.
* @throws Error If Simulator appication is not running or Appium process has
* no access to system accessibility.
*/
commands.toggleEnrollTouchId = async function () {
if (!this.opts.allowTouchIdEnroll) {
throw new errors.UnknownError(`Must set desired capability 'allowTouchIdEnroll = true' to enroll touchId`);
}

commands.toggleEnrollTouchId = async function (enabled = true) {
if (!this.isSimulator()) {
throw new errors.UnknownError('Touch ID simulation not supported on real devices');
} else {
await this.opts.device.enrollTouchID();
}

await this.opts.device.enrollTouchID(enabled);
};

commands.getWindowSize = async function (windowHandle = 'current') {
Expand Down
3 changes: 0 additions & 3 deletions lib/desired-caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ let desiredCapConstraints = _.defaults({
nativeTyping: {
isBoolean: true
},
allowTouchIdEnroll: {
isBoolean: true
},
simpleIsVisibleCheck: {
isBoolean: true
},
Expand Down
6 changes: 0 additions & 6 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,16 +632,10 @@ class XCUITestDriver extends BaseDriver {

async startSim () {
await this.opts.device.run({
allowTouchIdEnroll: !!this.opts.allowTouchIdEnroll,
scaleFactor: this.opts.scaleFactor,
connectHardwareKeyboard: !!this.opts.connectHardwareKeyboard,
isHeadless: !!this.opts.isHeadless,
});

// Enable toggleEnrollTouchId initially
if (this.opts.allowTouchIdEnroll && await this.opts.device.isUIClientRunning()) {
await this.toggleEnrollTouchId();
}
}

async createSim () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"lib": "lib"
},
"dependencies": {
"appium-base-driver": "^2.11.1",
"appium-base-driver": "^2.14.0",
"appium-ios-driver": "^1.26.1",
"appium-ios-simulator": "^2.0.0",
"appium-ios-simulator": "^2.2.2",
"appium-support": "^2.4.0",
"appium-xcode": "^3.2.0",
"asyncbox": "^2.3.1",
Expand Down
40 changes: 19 additions & 21 deletions test/functional/basic/touch-id-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (!process.env.REAL_DEVICE) {
describe('touchID() ', function () {
this.timeout(MOCHA_TIMEOUT * 2);
this.retries(MOCHA_RETRIES);
let caps, driver;
let driver;

beforeEach(async () => {
await killAllSimulators();
Expand All @@ -32,29 +32,26 @@ if (!process.env.REAL_DEVICE) {
await killAllSimulators();
});

it('should throw an error if allowTouchIdEnroll desired capability is not set', async () => {
caps = Object.assign(TOUCHIDAPP_CAPS);
caps.allowTouchIdEnroll = false;
driver = await initSession(caps);

await driver.toggleTouchIdEnrollment().should.be.rejectedWith(/enroll touchId/);
});

describe('touchID enrollment functional tests applied to TouchId sample app', function () {
beforeEach(async () => {
caps = Object.assign(TOUCHIDAPP_CAPS);
caps.allowTouchIdEnroll = true;
driver = await initSession(caps);
beforeEach(async function () {
if (process.env.TRAVIS) {
// ignore tests on Travis, since Appium process does not have access to
// system Accessibility there
return this.skip();
}
driver = await initSession(TOUCHIDAPP_CAPS);
await B.delay(2000); // Give the app a couple seconds to open
});

it('should not support touchID if not enrolled', async () => {
it('should not support touchID if not enrolled', async function () {
await driver.toggleTouchIdEnrollment(false);
let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
await authenticateButton.click();
await driver.elementByName('TouchID not supported').should.eventually.exist;
});

it('should accept matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {
it('should accept matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async function () {
await driver.toggleTouchIdEnrollment(true);
let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
await authenticateButton.click();
await driver.touchId(true);
Expand All @@ -65,7 +62,8 @@ if (!process.env.REAL_DEVICE) {
}
});

it('should reject not matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {
it('should reject not matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async function () {
await driver.toggleTouchIdEnrollment(true);
let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
await authenticateButton.click();
await driver.touchId(false);
Expand All @@ -76,9 +74,9 @@ if (!process.env.REAL_DEVICE) {
}
});

it('should enroll touchID and accept matching fingerprints then unenroll touchID and not be supported', async () => {
it('should enroll touchID and accept matching fingerprints then unenroll touchID and not be supported', async function () {
//Unenroll
await driver.toggleTouchIdEnrollment();
await driver.toggleTouchIdEnrollment(false);
let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
await authenticateButton.click();
await driver.elementByName('TouchID not supported').should.eventually.exist;
Expand All @@ -87,7 +85,7 @@ if (!process.env.REAL_DEVICE) {
await B.delay(1000);

// Re-enroll
await driver.toggleTouchIdEnrollment();
await driver.toggleTouchIdEnrollment(true);
await authenticateButton.click();
await driver.touchId(true);
try {
Expand All @@ -100,11 +98,11 @@ if (!process.env.REAL_DEVICE) {
await B.delay(1000);

// Unenroll again
await driver.toggleTouchIdEnrollment();
await driver.toggleTouchIdEnrollment(false);
authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
await authenticateButton.click();
await driver.elementByName('TouchID not supported').should.eventually.exist;
});
});
});
}
}
5 changes: 0 additions & 5 deletions test/unit/commands/general-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ describe('general commands', () => {
enrollTouchIDSpy.restore();
});

it('should throw exception if allowTouchIdEnroll is not set', async () => {
optsStub.object.realDevice = false;
await driver.toggleEnrollTouchId().should.be.rejectedWith(/enroll touchId/);
});

it('should be called on a Simulator', async () => {
deviceStub.object.realDevice = false;
deviceStub.object.allowTouchIdEnroll = true;
Expand Down

0 comments on commit 2438208

Please sign in to comment.