How to use driver.toggleTouchIdEnrollment method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

touch-id-e2e-specs.js

Source: touch-id-e2e-specs.js Github

copy
1// transpile:mocha
2
3import chai from 'chai';
4import chaiAsPromised from 'chai-as-promised';
5import { TOUCHIDAPP_CAPS } from '../desired';
6import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session';
7import B from 'bluebird';
8import { killAllSimulators } from 'appium-ios-simulator';
9
10chai.should();
11chai.use(chaiAsPromised);
12
13describe('touchID() ', function () {
14  this.timeout(MOCHA_TIMEOUT);
15  let caps, driver;
16
17  beforeEach(async () => {
18    await killAllSimulators();
19  });
20
21  afterEach(async () => {
22    await deleteSession();
23    await B.delay(500);
24  });
25
26  after(async () => {
27    await killAllSimulators();
28  });
29
30  it('should throw an error if allowTouchIdEnroll desired capability is not set', async () => {
31    await killAllSimulators();
32    caps = Object.assign(TOUCHIDAPP_CAPS);
33    caps.allowTouchIdEnroll = false;
34    driver = await initSession(caps);
35
36    await driver.toggleTouchIdEnrollment().should.be.rejectedWith(/enroll touchId/);
37  });
38
39  describe('touchID enrollment functional tests applied to TouchId sample app', function () {
40    beforeEach(async () => {
41      caps = Object.assign(TOUCHIDAPP_CAPS);
42      caps.allowTouchIdEnroll = true;
43      driver = await initSession(caps);
44      await B.delay(2000); // Give the app a couple seconds to open
45    });
46
47    it('should not support touchID if not enrolled', async () => {
48      let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
49      await authenticateButton.click();
50      await driver.elementByName('TouchID not supported').should.eventually.exist;
51    });
52
53    it('should accept matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {
54      await driver.toggleTouchIdEnrollment();
55      let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
56      await authenticateButton.click();
57      await driver.touchId(true);
58      try {
59        await driver.elementByName('Authenticated Successfully').should.eventually.exist;
60      } catch (ign) {
61        await driver.elementByName('TouchID not supported').should.eventually.exist;
62      }
63      await driver.toggleTouchIdEnrollment();
64    });
65
66    it('should reject not matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {
67      await driver.toggleTouchIdEnrollment();
68      let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
69      await authenticateButton.click();
70      await driver.touchId(false);
71      try {
72        await driver.elementByName('Try Again').should.eventually.exist;
73      } catch (ign) {
74        await driver.elementByName('TouchID not supported').should.eventually.exist;
75      }
76      await driver.toggleTouchIdEnrollment();
77    });
78
79    it('should enroll touchID and accept matching fingerprints then unenroll touchID and not be supported', async () => {
80      // Don't enroll
81      let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
82      await authenticateButton.click();
83      await driver.elementByName('TouchID not supported').should.eventually.exist;
84      let okButton = await driver.elementByName('OK');
85      await okButton.click();
86      await B.delay(1000);
87
88      // Enroll
89      await driver.toggleTouchIdEnrollment();
90      await authenticateButton.click();
91      await driver.touchId(true);
92      try {
93        await driver.elementByName('Authenticated Successfully').should.eventually.exist;
94      } catch (ign) {
95        return await driver.elementByName('TouchID not supported').should.eventually.exist;
96      }
97      okButton = await driver.elementByName('OK');
98      await okButton.click();
99      await B.delay(1000);
100
101      // Unenroll
102      await driver.toggleTouchIdEnrollment();
103      authenticateButton = await driver.elementByName(' Authenticate with Touch ID');
104      await authenticateButton.click();
105      await driver.elementByName('TouchID not supported').should.eventually.exist;
106    });
107  });
108
109});
110
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)