You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2016/12/16 13:52:29 UTC
cordova-plugin-contacts git commit: [Appium] Add
forward-compatibility support for XCUITest automation in iOS. Is
backwards-compatible with UIAutomation-based test runs. Leverages finding
elements in native iOS land using the accessibility id selector, w
Repository: cordova-plugin-contacts
Updated Branches:
refs/heads/master 7c4f94f48 -> 58d4612f9
[Appium] Add forward-compatibility support for XCUITest automation in
iOS. Is backwards-compatible with UIAutomation-based test runs.
Leverages finding elements in native iOS land using the accessibility id selector, which also happens to be faster than XPath selectors.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/58d4612f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/58d4612f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/58d4612f
Branch: refs/heads/master
Commit: 58d4612f90682453fa59329892440738c73c842b
Parents: 7c4f94f
Author: filmaj <ma...@gmail.com>
Authored: Thu Dec 15 13:12:01 2016 -0800
Committer: filmaj <ma...@gmail.com>
Committed: Thu Dec 15 16:21:10 2016 -0800
----------------------------------------------------------------------
appium-tests/common/common.spec.js | 62 ++++++++++++++++++++++++++++++---
1 file changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/58d4612f/appium-tests/common/common.spec.js
----------------------------------------------------------------------
diff --git a/appium-tests/common/common.spec.js b/appium-tests/common/common.spec.js
index 956430b..3371ad6 100644
--- a/appium-tests/common/common.spec.js
+++ b/appium-tests/common/common.spec.js
@@ -112,9 +112,8 @@ describe('Contacts UI Automation Tests', function () {
switch (PLATFORM) {
case 'ios':
return driver
- .waitForElementByXPath(UNORM.nfd('//UIAStaticText[@label="' + name + '"]'), 20000)
- .elementByXPath(UNORM.nfd('//UIAStaticText[@label="' + name + '"]'))
- .elementByXPath(UNORM.nfd('//UIAStaticText[@label="' + name + '"]'));
+ .waitForElementByAccessibilityId(name, 20000)
+ .elementByAccessibilityId(name);
case 'android':
return driver
.waitForElementByXPath('//android.widget.TextView[@text="' + name + '"]', MINUTE);
@@ -244,8 +243,63 @@ describe('Contacts UI Automation Tests', function () {
.then(function () {
failedToStart = false;
}, fail)
+ .then(function () {
+ // on iOS, first interaction with contacts API will trigger the permission dialog.
+ // We will attempt to bust it manually here, by triggering the contacts API
+ // and waiting for the native dialog to show up, then dismissing the alert.
+ // This only needs to be done once.
+ // NOTE: in earlier versions of iOS (9.3 and below), using the older UI testing library
+ // (UIAutomation), Appium's autoAcceptAlerts capability handles this for us. This logic
+ // is here as a transition between UIAutomation and XCUITest and is compatible with both.
+ // More details in the comment below.
+ if (PLATFORM == 'ios') {
+ var promiseId = getNextPromiseId();
+ var contactName = contactsHelper.getContactName('Permission', 'Buster');
+ return driver
+ .context(webviewContext)
+ .execute(function (pID, contactname) {
+ navigator._appiumPromises[pID] = Q.defer();
+ navigator.contacts.create({
+ 'displayName': contactname.formatted,
+ 'name': contactname,
+ 'note': 'DeleteMe'
+ }).save(function (contact) {
+ navigator._appiumPromises[pID].resolve(contact);
+ }, function (err) {
+ navigator._appiumPromises[pID].reject(err);
+ });
+ }, [promiseId, contactName])
+ .context('NATIVE_APP')
+ .acceptAlert()
+ .then(function alertDismissed() {
+ // TODO: once we move to only XCUITest-based (which is force on you in either iOS 10+ or Xcode 8+)
+ // UI tests, we will have to:
+ // a) remove use of autoAcceptAlerts appium capability since it no longer functions in XCUITest
+ // b) can remove this entire then() clause, as we do not need to explicitly handle the acceptAlert
+ // failure callback, since we will be guaranteed to hit the permission dialog on startup.
+ }, function noAlert() {
+ // in case the contacts permission alert never showed up: no problem, don't freak out.
+ // This can happen if:
+ // a) The application-under-test already had contacts permissions granted to it
+ // b) Appium's autoAcceptAlerts capability is provided (and functioning)
+ })
+ .context(webviewContext)
+ .executeAsync(function (pID, cb) {
+ navigator._appiumPromises[pID].promise
+ .then(cb, function (err) {
+ cb('ERROR: ' + err);
+ });
+ }, [promiseId])
+ .then(function (result) {
+ if (typeof result === 'string' && result.indexOf('ERROR:') === 0) {
+ throw result;
+ }
+ return result;
+ });
+ }
+ })
.done(done);
- }, 10 * MINUTE);
+ }, 5 * MINUTE);
describe('Picking contacts', function () {
afterEach(function (done) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org