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/06/10 15:15:06 UTC

cordova-paramedic git commit: Sauce tests: Try to poll results from all available windows if not found in the first one

Repository: cordova-paramedic
Updated Branches:
  refs/heads/master 6aeb416c6 -> f04eb3ffa


Sauce tests: Try to poll results from all available windows if not found in the first one


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

Branch: refs/heads/master
Commit: f04eb3ffa62fea251e5366641a47dd948ada9761
Parents: 6aeb416
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Fri Jun 10 17:41:57 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Fri Jun 10 17:45:40 2016 +0300

----------------------------------------------------------------------
 lib/appium/helpers/wdHelper.js | 52 ++++++++++++++++++++++++++++++++++++-
 lib/paramedic.js               | 24 ++---------------
 2 files changed, 53 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/f04eb3ff/lib/appium/helpers/wdHelper.js
----------------------------------------------------------------------
diff --git a/lib/appium/helpers/wdHelper.js b/lib/appium/helpers/wdHelper.js
index 7e867aa..ce32daa 100644
--- a/lib/appium/helpers/wdHelper.js
+++ b/lib/appium/helpers/wdHelper.js
@@ -1,5 +1,5 @@
 /* jshint node: true */
-/* global navigator, document */
+/* global navigator, document, window */
 /*
  *
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -154,6 +154,52 @@ module.exports.tapElementByXPath = function (xpath, driver) {
         });
 };
 
+module.exports.pollForEvents = function (driver, isAndroid, windowOffset) {
+    if (!windowOffset) {
+        windowOffset = 0;
+    }
+    // polling for new events
+    return driver
+    //driver.then is not a function, so
+    .sleep(0)
+    .then(function() {
+        if (!isAndroid) {
+            return driver;
+        }
+        // for some reason inappbrowser tests tend to leave an active window on android
+        // so for the polling to work correctly we need to
+        // switch back to the window where the cache is located
+        return driver
+        .windowHandles()
+        .then(function (windowHandles) {
+            if (windowOffset >= windowHandles.length) {
+                throw new Error('Cannot find a window with the event cache.');
+            }
+            return driver.window(windowHandles[windowOffset]);
+        });
+    })
+    .execute(function () {
+        if (typeof window._jasmineParamedicProxyCache === 'undefined') {
+            // wrong window
+            return null;
+        }
+        // get the results and clean up the cache
+        var result = window._jasmineParamedicProxyCache;
+        window._jasmineParamedicProxyCache = [];
+        return result;
+    }, [])
+    .then(function (result) {
+        if (Object.prototype.toString.call(result) === '[object Array]') {
+            return result;
+        }
+        if (!isAndroid) {
+            throw new Error('Cannot get the event cache: it doesn\'t exist in the app.');
+        }
+        // no luck finding the event cache in this window, let's try next
+        return module.exports.pollForEvents(driver, isAndroid, windowOffset + 1);
+    });
+};
+
 wd.addPromiseChainMethod('getWebviewContext', function (retries) {
     return module.exports.getWebviewContext(this, retries);
 });
@@ -173,3 +219,7 @@ wd.addPromiseChainMethod('injectLibraries', function () {
 wd.addPromiseChainMethod('tapElementByXPath', function (xpath) {
     return module.exports.tapElementByXPath(xpath, this);
 });
+
+wd.addPromiseChainMethod('pollForEvents', function (isAndroid) {
+    return module.exports.pollForEvents(this, isAndroid);
+});

http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/f04eb3ff/lib/paramedic.js
----------------------------------------------------------------------
diff --git a/lib/paramedic.js b/lib/paramedic.js
index 31f0857..185c6bd 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -553,30 +553,10 @@ ParamedicRunner.prototype.runSauceTests = function () {
     .then(function () {
         logger.normal('cordova-paramedic: connecting to app');
 
+        var isAndroid = self.config.getPlatformId() === 'android';
         if (!self.config.getUseTunnel()) {
             pollForResults = setInterval(function () {
-                // polling for new events
-                driver
-                //driver.then is not a function, so
-                .sleep(0)
-                .then(function() {
-                    // for some reason inappbrowser tests tend to leave an active window on android
-                    // so for the polling to work correctly we need to
-                    // switch back to the first window where the cache is located
-                    if (self.config.getPlatformId() !== 'android') {
-                        return driver;
-                    }
-                    return driver
-                    .windowHandles()
-                    .then(function (windowHandles) {
-                        return driver.window(windowHandles[0]);
-                    });
-                })
-                .execute(function () {
-                    var result = window._jasmineParamedicProxyCache;
-                    window._jasmineParamedicProxyCache = [];
-                    return result;
-                }, [])
+                driver.pollForEvents(isAndroid)
                 .then(function (events) {
                     for (var i = 0; i < events.length; i++) {
                         self.server.emit(events[i].eventName, events[i].eventObject);


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