From 9badea4c9509d8d40f17530fb84ea49f223fc925 Mon Sep 17 00:00:00 2001 From: Alexander Sorokin Date: Thu, 20 Apr 2017 09:01:54 +0300 Subject: [PATCH] CB-12622: (android) Appium tests: Bust Android 6 and 7 permission dialogs --- appium-tests/android/android.spec.js | 37 +++++++++++++++++++++++++++- appium-tests/helpers/cameraHelper.js | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/appium-tests/android/android.spec.js b/appium-tests/android/android.spec.js index 34e65b5..69f7e35 100644 --- a/appium-tests/android/android.spec.js +++ b/appium-tests/android/android.spec.js @@ -225,6 +225,40 @@ describe('Camera tests Android.', function () { }) .waitForDeviceReady() .injectLibraries() + .then(function () { + var options = { + quality: 50, + allowEdit: false, + sourceType: cameraConstants.PictureSourceType.SAVEDPHOTOALBUM, + saveToPhotoAlbum: false, + targetWidth: 210, + targetHeight: 210 + }; + return driver + .then(function () { return getPicture(options, true); }) + .context(CONTEXT_NATIVE_APP) + // case insensitive select, will be handy with Android 7 support + .elementByXPath('//android.widget.Button[translate(@text, "alow", "ALOW")="ALLOW"]') + .click() + .fail(function noAlert() { }) + .deviceKeyEvent(BACK_BUTTON) + .sleep(2000) + .elementById('action_bar_title') + .then(function () { + // success means we're still in native app + return driver + .deviceKeyEvent(BACK_BUTTON); + }, function () { + // error means we're already in webview + return driver; + }); + }) + .then(function () { + // doing it inside a function because otherwise + // it would not hook up to the webviewContext var change + // in the first methods of this chain + return driver.context(webviewContext); + }) .deleteFillerImage(fillerImagePath) .then(function () { fillerImagePath = null; @@ -291,6 +325,7 @@ describe('Camera tests Android.', function () { pending('This test requires a functioning camera on the Android device/emulator, and this test suite\'s functional camera test failed on your target environment.'); } } + afterAll(function (done) { checkSession(done); driver @@ -390,7 +425,7 @@ describe('Camera tests Android.', function () { return driver .elementByAndroidUIAutomator('new UiSelector().text("Choose video")') .fail(function () { - throw 'Couldn\'t find "Choose video" element.'; + throw 'Couldn\'t find a "Choose video" element.'; }); }) .deviceKeyEvent(BACK_BUTTON) diff --git a/appium-tests/helpers/cameraHelper.js b/appium-tests/helpers/cameraHelper.js index a16916f..caf0f9e 100644 --- a/appium-tests/helpers/cameraHelper.js +++ b/appium-tests/helpers/cameraHelper.js @@ -169,6 +169,7 @@ module.exports.checkPicture = function (pid, options, cb) { return; } } + try { if (result.indexOf('file:') === 0 || result.indexOf('content:') === 0 || @@ -184,6 +185,8 @@ module.exports.checkPicture = function (pid, options, cb) { } else { verifyFile(entry); } + }, function (err) { + errorCallback(err); }); } else { displayImage(result);