You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by al...@apache.org on 2016/03/02 11:25:26 UTC

cordova-plugin-camera git commit: CB-10750 Appium tests: fail fast if session is irrecoverable

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master 2cd2528d1 -> d51e23ad7


CB-10750 Appium tests: fail fast if session is irrecoverable


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/d51e23ad
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/d51e23ad
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/d51e23ad

Branch: refs/heads/master
Commit: d51e23ad7b655171124ec43dcc559aff2796b60b
Parents: 2cd2528
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Tue Mar 1 18:27:08 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Wed Mar 2 13:23:51 2016 +0300

----------------------------------------------------------------------
 appium-tests/android/android.spec.js | 45 ++++++++++++++++++++-----------
 appium-tests/helpers/wdHelper.js     |  2 +-
 2 files changed, 30 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d51e23ad/appium-tests/android/android.spec.js
----------------------------------------------------------------------
diff --git a/appium-tests/android/android.spec.js b/appium-tests/android/android.spec.js
index ad5ffa3..e9373e9 100644
--- a/appium-tests/android/android.spec.js
+++ b/appium-tests/android/android.spec.js
@@ -26,9 +26,11 @@ describe('Camera tests Android.', function () {
     var webviewContext = DEFAULT_WEBVIEW_CONTEXT;
     // this indicates that the device library has the test picture:
     var isTestPictureSaved = false;
-    // this indicates that there was a critical error and tests cannot continue:
+    // this indicates that there was a critical error and we should try to recover:
+    var errorFlag = false;
+    // this indicates that we couldn't restore Appium session and should fail fast:
     var stopFlag = false;
-    // we need to know the screen width and height to properly click on an image in the gallery
+    // we need to know the screen width and height to properly click on an image in the gallery:
     var screenWidth = DEFAULT_SCREEN_WIDTH;
     var screenHeight = DEFAULT_SCREEN_HEIGHT;
 
@@ -168,7 +170,7 @@ describe('Camera tests Android.', function () {
                             .execute('window.location = "../index.html"')
                             .sleep(5000)
                             .fail(function () {
-                                stopFlag = true;
+                                errorFlag = true;
                                 throw 'Couldn\'t find start page.';
                             });
                     }, function () {
@@ -261,7 +263,7 @@ describe('Camera tests Android.', function () {
                         // we should try to recreate the session for the following tests
                         if (msg.indexOf('Error response status: 6') >= 0 ||
                             msg.indexOf('Error response status: 7') >= 0) {
-                            stopFlag = true;
+                            errorFlag = true;
                         }
                         return result;
                     }
@@ -271,7 +273,13 @@ describe('Camera tests Android.', function () {
     });
 
     it('camera.ui.util configuring driver and starting a session', function (done) {
-        getDriver().then(done);
+        stopFlag = true; // just in case of timeout
+        getDriver().then(function () {
+            stopFlag = false;
+        }, function (error) {
+            fail(error);
+        })
+        .finally(done);
     }, 5 * MINUTE);
 
     it('camera.ui.util determine webview context name', function (done) {
@@ -316,19 +324,14 @@ describe('Camera tests Android.', function () {
 
     describe('Specs.', function () {
         beforeEach(function (done) {
+            // prepare the app for the test
             if (!stopFlag) {
                 return driver
                     .context(webviewContext)
                     .then(function () {
                         return driver; // no-op
                     }, function (error) {
-                        if (error.message.indexOf('Error response status: 6') >= 0) {
-                            // the session has expired but we can fix this!
-                            console.log('The session has expired. Trying to start a new one...');
-                            return getDriver();
-                        } else {
-                            expect(true).toFailWithMessage(error);
-                        }
+                        expect(true).toFailWithMessage(error);
                     })
                     .execute('document.getElementById("info").innerHTML = "' + STARTING_MESSAGE + '";')
                     .finally(done);
@@ -337,20 +340,30 @@ describe('Camera tests Android.', function () {
         }, 3 * MINUTE);
 
         afterEach(function (done) {
-            if (!stopFlag) {
+            if (!errorFlag || stopFlag) {
+                // either there's no error or we've failed irrecoverably
+                // nothing to worry about!
                 done();
                 return;
             }
-            // recreate the session if there was a critical error in the spec
+            // recreate the session if there was a critical error in a previous spec
+            stopFlag = true; // we're going to set this to false if we're able to restore the session
             return driver
                 .quit()
                 .then(function () {
                     return getDriver()
                         .then(function () {
+                            errorFlag = false;
                             stopFlag = false;
-                            done();
+                        }, function (error) {
+                            fail(error);
+                            stopFlag = true;
                         });
-                });
+                }, function (error) {
+                    fail(error);
+                    stopFlag = true;
+                })
+                .finally(done);
         }, 3 * MINUTE);
 
         // getPicture() with saveToPhotoLibrary = true

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d51e23ad/appium-tests/helpers/wdHelper.js
----------------------------------------------------------------------
diff --git a/appium-tests/helpers/wdHelper.js b/appium-tests/helpers/wdHelper.js
index 8689d40..f296001 100644
--- a/appium-tests/helpers/wdHelper.js
+++ b/appium-tests/helpers/wdHelper.js
@@ -11,7 +11,7 @@ module.exports.getDriver = function (platform, callback) {
     },
         driverConfig = {
             browserName: '',
-            'appium-version': '1.3',
+            'appium-version': '1.5',
             platformName: platform,
             platformVersion: global.PLATFORM_VERSION || '',
             deviceName: global.DEVICE_NAME || '',


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org