cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alsoro...@apache.org
Subject cordova-medic git commit: CB-10638 Appium runner: Fixed build command on OSX, Refactored runner code, Updated Appium version to 1.5
Date Tue, 01 Mar 2016 11:01:44 GMT
Repository: cordova-medic
Updated Branches:
  refs/heads/master 48c2c28a9 -> b3ccc0748


CB-10638 Appium runner: Fixed build command on OSX,
Refactored runner code,
Updated Appium version to 1.5


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

Branch: refs/heads/master
Commit: b3ccc0748e1fc106b492741e382b6ddc14e17d59
Parents: 48c2c28
Author: Alexander Sorokin <alexander.sorokin@akvelon.com>
Authored: Wed Feb 24 14:36:36 2016 +0300
Committer: Alexander Sorokin <alexander.sorokin@akvelon.com>
Committed: Tue Mar 1 13:58:51 2016 +0300

----------------------------------------------------------------------
 buildbot-conf/cordova-config.json.sample |  11 +-
 buildbot-conf/cordova.conf               |  41 +--
 lib/medicReporter.js                     | 130 +++++++
 medic/medic-appium.js                    | 508 +++++++++++---------------
 package.json                             |   2 +-
 5 files changed, 363 insertions(+), 329 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b3ccc074/buildbot-conf/cordova-config.json.sample
----------------------------------------------------------------------
diff --git a/buildbot-conf/cordova-config.json.sample b/buildbot-conf/cordova-config.json.sample
index 6463ab0..40c167a 100644
--- a/buildbot-conf/cordova-config.json.sample
+++ b/buildbot-conf/cordova-config.json.sample
@@ -10,11 +10,12 @@
         "timeout": 600
     },
     "appium": {
-      "androidDeviceName": "api21",
-      "androidPlatformVersion": "21",
-      "iosDeviceName": "iPad 2",
-      "iosPlatformVersion": "8.1",
-      "timeout": 2400
+        "androidDeviceName":      "Galaxy_Nexus",
+        "androidPlatformVersion": "19",
+        "iosDeviceName":          "iPhone 5",
+        "iosPlatformVersion":     "8.4",
+        "timeout":                2400,
+        "screenshotPath":         "appium_screenshots"
     },
     "blackberry": {
         "devices": {

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b3ccc074/buildbot-conf/cordova.conf
----------------------------------------------------------------------
diff --git a/buildbot-conf/cordova.conf b/buildbot-conf/cordova.conf
index 0af756a..d66cb07 100644
--- a/buildbot-conf/cordova.conf
+++ b/buildbot-conf/cordova.conf
@@ -47,10 +47,11 @@ COUCHDB_URI             = medic_config['couchdb']['uri']
 ENTRY_POINT             = medic_config['app']['entry']
 TEST_RUN_TIMEOUT        = medic_config['app']['timeout'] # in seconds
 ANDROID_APPIUM_NAME     = medic_config['appium']['androidDeviceName']
-ANDROID_APPIUM_PALTFORM = medic_config['appium']['androidPlatformVersion']
+ANDROID_APPIUM_PLATFORM = medic_config['appium']['androidPlatformVersion']
 IOS_APPIUM_NAME         = medic_config['appium']['iosDeviceName']
 IOS_APPIUM_PLATFORM     = medic_config['appium']['iosPlatformVersion']
 APPIUM_RUN_TIMEOUT      = medic_config['appium']['timeout']
+APPIUM_SCREENSHOT_PATH  = medic_config['appium']['screenshotPath']
 LOG_GETTING_TIMEOUT     = 30 # in seconds
 TEST_SUMMARY_FILE_NAME  = 'test_summary.json'
 MASTER_HOSTNAME         = socket.gethostname()
@@ -264,7 +265,7 @@ CORDOVA_STEPS_SET_SETTINGS = [
 ]
 
 CORDOVA_STEPS_CLEAN_UP = [
-    SH(command=['node', 'cordova-medic/medic/medic.js', 'clean', '.', '--exclude', 'cordova-medic',
'--exclude', NPM_CACHE_DIR_NAME], description='cleaning workspace'),
+    SH(command=['node', 'cordova-medic/medic/medic.js', 'clean', '.', '--exclude', 'cordova-medic',
'--exclude', NPM_CACHE_DIR_NAME, '--exclude', APPIUM_SCREENSHOT_PATH], description='cleaning
workspace'),
 ]
 
 CORDOVA_STEPS_GET_MEDIC = [
@@ -403,7 +404,14 @@ def cordova_steps_run_tests(platform, extra_args=list()):
     ]
 
 def cordova_steps_run_appium(platform):
-    if platform == 'android':
+    pluginsString = ' '.join(CORE_PLUGINS)
+    if platform in ('android', 'ios'):
+        if platform == 'android':
+            APPIUM_NAME = ANDROID_APPIUM_NAME
+            APPIUM_PLATFORM = ANDROID_APPIUM_PLATFORM
+        elif platform == 'ios':
+            APPIUM_NAME = IOS_APPIUM_NAME
+            APPIUM_PLATFORM = IOS_APPIUM_PLATFORM
         return [
             SH(
                 command = [
@@ -412,31 +420,18 @@ def cordova_steps_run_appium(platform):
                     'appium',
                     '--platform', platform,
                     '--app', TEST_APP_NAME,
-                    '--device-name', ANDROID_APPIUM_NAME,
-                    '--platform-version', ANDROID_APPIUM_PALTFORM
+                    '--deviceName', APPIUM_NAME,
+                    '--platformVersion', APPIUM_PLATFORM,
+                    '--plugins', pluginsString,
+                    '--screenshotPath', APPIUM_SCREENSHOT_PATH,
                 ],
                 description='running Appium tests',
                 timeout = APPIUM_RUN_TIMEOUT,
+                haltOnFailure = False,
+                flunkOnFailure = False,
             ),
         ]
-    elif platform == 'ios':
-        return [
-            SH(
-                command = [
-                    'node',
-                    'cordova-medic/medic/medic.js',
-                    'appium',
-                    '--platform', platform,
-                    '--app', TEST_APP_NAME,
-                    '--device-name', IOS_APPIUM_NAME,
-                    '--platform-version', IOS_APPIUM_PLATFORM
-                ],
-                description = 'running Appium tests',
-                timeout = APPIUM_RUN_TIMEOUT,
-            ),
-        ]
-    else :
-        return []
+    return []
 
 def makeRunSteps(platform, extra_args=list()):
 

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b3ccc074/lib/medicReporter.js
----------------------------------------------------------------------
diff --git a/lib/medicReporter.js b/lib/medicReporter.js
new file mode 100644
index 0000000..eabd86a
--- /dev/null
+++ b/lib/medicReporter.js
@@ -0,0 +1,130 @@
+/* jshint node: true */
+
+"use strict";
+
+var util = require("../lib/util");
+
+var OFFSET = "    ";
+
+function plural(str, count) {
+    return count === 1 ? str : str + "s";
+}
+
+function repeat(thing, times) {
+    var arr = [];
+    for (var i = 0; i < times; i++) {
+        arr.push(thing);
+    }
+    return arr;
+}
+
+function indent(str, spaces) {
+    var lines = (str || "").split("\n");
+    var newArr = [];
+
+    for (var i = 0; i < lines.length; i++) {
+        newArr.push(repeat(" ", spaces).join("") + lines[i]);
+    }
+    return newArr.join("\n");
+}
+
+function specFailureDetails(result, failedSpecNumber) {
+    var failedExpectation;
+
+    console.log(failedSpecNumber + ") ");
+    console.log(result.fullName);
+
+    for (var i = 0; i < result.failedExpectations.length; i++) {
+        failedExpectation = result.failedExpectations[i];
+        console.log(indent("Message:", 2));
+        console.log(failedExpectation.message);
+        console.log(indent("Stack:", 2));
+        console.log(indent(failedExpectation.stack, 4));
+    }
+}
+
+function pendingSpecDetails(result, pendingSpecNumber) {
+    console.log(pendingSpecNumber + ") ");
+    console.log(result.fullName);
+    var pendingReason = "No reason given";
+    if (result.pendingReason && result.pendingReason !== "") {
+        pendingReason = result.pendingReason;
+    }
+    console.log(indent(pendingReason, 2));
+}
+
+function MedicReporter(callback) {
+    this.allDoneCallback = callback;
+    this.failedSpecs = [];
+    this.pendingSpecs = [];
+    this.results = {
+        total: 0,
+        failed: 0,
+        passed: 0,
+        warnings: 0
+    };
+
+    this.reportResults = function () {
+        var specCounts;
+
+        if (this.failedSpecs.length > 0) {
+            console.log("Failures:");
+        }
+        for (var i = 0; i < this.failedSpecs.length; i++) {
+            specFailureDetails(this.failedSpecs[i], i + 1);
+        }
+
+        if (this.pendingSpecs.length > 0) {
+            console.log("Pending:");
+        }
+        for (i = 0; i < this.pendingSpecs.length; i++) {
+            pendingSpecDetails(this.pendingSpecs[i], i + 1);
+        }
+
+        if (this.results.total > 0) {
+            specCounts = this.results.total + " " + plural("spec", this.results.total) +
", " +
+                this.results.failed + " " + plural("failure", this.results.failed);
+
+            if (this.pendingSpecs.length) {
+                specCounts += ", " + this.pendingSpecs.length + " pending " + plural("spec",
this.pendingSpecs.length);
+            }
+
+            console.log(specCounts);
+        } else {
+            console.log("No specs found");
+        }
+    };
+}
+
+MedicReporter.prototype = {
+    specStarted: function (spec) {
+        util.medicLog("Starting new spec: " + spec.description);
+    },
+    suiteDone: function (suite) {
+        util.medicLog("Suite done: " + suite.description);
+        util.medicLog("Result was: " + suite.status);
+        for (var i = 0; i < suite.failedExpectations.length; i++) {
+            util.medicLog(suite.failedExpectations[i].message);
+            util.medicLog(OFFSET + suite.failedExpectations[i].stack.replace(/(\r\n|\n|\r)/gm,
"\n" + OFFSET));
+        }
+    },
+    specDone: function (spec) {
+        util.medicLog("Spec " + spec.status + ": " + spec.description);
+        this.results.total++;
+        if (spec.status === "failed") {
+            this.failedSpecs.push(spec);
+            this.results.failed++;
+        } else if (spec.status === "pending") {
+            this.pendingSpecs.push(spec);
+            this.results.warnings++;
+        } else {
+            this.results.passed++;
+        }
+    },
+    jasmineDone: function () {
+        this.reportResults();
+        this.allDoneCallback(this.results);
+    }
+};
+
+module.exports = MedicReporter;

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b3ccc074/medic/medic-appium.js
----------------------------------------------------------------------
diff --git a/medic/medic-appium.js b/medic/medic-appium.js
index e7fd995..e7033f9 100644
--- a/medic/medic-appium.js
+++ b/medic/medic-appium.js
@@ -20,10 +20,8 @@
  */
 
 /* jshint node: true */
-/*jslint node: true, stupid: true, nomen: true, plusplus: true*/
-/*global jasmine*/
 
-'use strict';
+"use strict";
 
 // Run on iOS device:
 // node cordova-medic/medic/medic.js appium --platform ios --device --udid c1e6ec7bb72473cfa14001ad49a2ab7dbbf7d69d
--device-name "iPad 2" --platform-version "8.1" --app mobilespec
@@ -40,68 +38,56 @@
 var fs              = require("fs");
 var path            = require("path");
 var util            = require("../lib/util");
+var MedicReporter   = require("../lib/MedicReporter");
 var optimist        = require("optimist");
 var kill            = require("tree-kill");
-var cp              = require("child_process");
+var child_process   = require("child_process");
 var wd              = require("wd");
 var et              = require("expect-telnet");
 var shell           = require("shelljs");
 var Jasmine         = require("jasmine");
+var unorm           = require("unorm");
 
 var DEFAULT_APP_PATH = "mobilespec";
 var DEFAULT_IOS_DEVICE_NAME = "iPhone 5";
 var DEFAULT_ANDROID_DEVICE_NAME = "appium";
 var DEFAULT_IOS_PLATFORM_VERSION = "7.1";
 var DEFAULT_ANDROID_PLATFORM_VERSION = "19";
+var KILL_SIGNAL = "SIGINT";
+var APPIUM_IP_ADDRESS = "127.0.0.1";
+var APPIUM_PORT = 4723;
+var SMALL_BUFFER_SIZE = 1024 * 1024;
+var BIG_BUFFER_SIZE = 50 * 1024 * 1024;
+var APPIUM_SERVER_PATH = path.normalize("cordova-medic/node_modules/appium/build/lib/main.js");
+
+function getFullAppPath(appPath) {
+    return path.join(__dirname, "../..", appPath);
+}
+
+function getPackagePath(options) {
+    var fullAppPath = getFullAppPath(options.appPath);
 
-var appiumAlive = false;
-var iosProxyAlive = false;
-var platform;
-var appPath;
-var testPaths = [];
-var appiumProcess;
-var iosProxyProcess;
-var udid;
-var appiumDeviceName;
-var appiumPlatformVersion;
-var device;
-var outputPath;
-var failedSpecs = [];
-var pendingSpecs = [];
-var results = {
-    total: 0,
-    failed: 0,
-    passed: 0,
-    warnings: 0
-};
-var pluginRepos = [
-    "cordova-plugin-battery-status",
-    "cordova-plugin-camera",
-    "cordova-plugin-console",
-    "cordova-plugin-contacts",
-    "cordova-plugin-device",
-    "cordova-plugin-device-motion",
-    "cordova-plugin-device-orientation",
-    "cordova-plugin-dialogs",
-    "cordova-plugin-file",
-    "cordova-plugin-file-transfer",
-    "cordova-plugin-geolocation",
-    "cordova-plugin-globalization",
-    "cordova-plugin-inappbrowser",
-    "cordova-plugin-media",
-    "cordova-plugin-media-capture",
-    "cordova-plugin-network-information",
-    "cordova-plugin-splashscreen",
-    "cordova-plugin-statusbar",
-    "cordova-plugin-vibration",
-    "cordova-plugin-whitelist",
-];
+    switch (options.platform) {
+    case "android":
+        return path.join(fullAppPath, "/platforms/android/build/outputs/apk/android-debug.apk");
+    case "ios":
+        if (options.device) {
+            return path.join(fullAppPath, "/platforms/ios/build/device/mobilespec.ipa");
+        }
+        return path.join(fullAppPath, "/platforms/ios/build/emulator/mobilespec.app");
+    }
+}
+
+function getLocalPluginDirs() {
+    return shell.ls("cordova-plugin-*");
+}
 
 function parseArgs() {
     // get args
-    var DEFAULT_DEVICE_NAME,
-        DEFAULT_PLATFORM_VERSION,
-        argv = optimist
+    var DEFAULT_DEVICE_NAME;
+    var DEFAULT_PLATFORM_VERSION;
+    var options = {};
+    var argv = optimist
             .usage("Usage: $0 {options}")
             .demand("platform")
             .describe("platform", "A platform to run the tests on. Only \'ios\' and \'android\'
are supported.")
@@ -111,44 +97,51 @@ function parseArgs() {
             .describe("app", "Path to the test app.")
             .default("udid", "")
             .describe("udid", "UDID of the ios device. Only needed when running tests on
real iOS devices.")
-            .default("device-name", null)
-            .describe("device-name", "Name of the device to run tests on.")
-            .default("platform-version", null)
-            .describe("platform-version", "Version of the OS installed on the device or the
emulator. For example, '21' for Android or '8.1' for iOS.")
+            .default("deviceName", null)
+            .describe("deviceName", "Name of the device to run tests on.")
+            .default("platformVersion", null)
+            .describe("platformVersion", "Version of the OS installed on the device or the
emulator. For example, '21' for Android or '8.1' for iOS.")
             .default("output", path.join(__dirname, "../../test_summary.json"))
             .describe("output", "A file that will store test results")
             .describe("plugins", "A space-separated list of plugins to test.")
+            .default("screenshotPath", path.join(__dirname, "appium_screenshots"))
+            .describe("screenshotPath", "A directory to save screenshots to, either absolute
or relative to the directory containing cordova-medic.")
             .argv;
 
-    platform = argv.platform.toLowerCase();
-    appPath  = argv.app;
-    global.WD = wd;
-    global.ET = et;
-    global.SHELL = shell;
-    global.SCREENSHOT_PATH = path.join(__dirname, "../../appium_screenshots_" + (argv["build-id"]
|| "noid")) + "/";
-    fs.stat(global.SCREENSHOT_PATH, function (err) {
-        if (err) {
-            fs.mkdir(global.SCREENSHOT_PATH);
-        }
-    });
+    // filling out the options object
+    options.platform = argv.platform.toLowerCase();
+    options.appPath  = argv.app;
+    options.appiumDeviceName = argv.deviceName || DEFAULT_DEVICE_NAME;
+    options.appiumPlatformVersion = argv.platformVersion || DEFAULT_PLATFORM_VERSION;
+    options.udid = argv.udid;
+    options.device = argv.device;
+    options.outputPath = argv.output;
+    options.screenshotPath = path.normalize(argv.screenshotPath);
+
+    // accepting both "plugins" or "plugin" arguments
+    // if there is none, using default plugin list
     if (argv.plugins) {
-        pluginRepos = argv.plugins.split(" ");
+        options.pluginRepos = argv.plugins.split(" ");
     } else if (argv.plugin) {
-        pluginRepos = argv.plugin.split(" ");
+        options.pluginRepos = argv.plugin.split(" ");
+    } else {
+        options.pluginRepos = getLocalPluginDirs();
     }
-    pluginRepos.forEach(function (pluginRepo) {
-        var testPath = path.join(pluginRepo, "appium-tests", platform);
+
+    // looking for the tests
+    options.testPaths = [];
+    options.pluginRepos.forEach(function (pluginRepo) {
+        var testPath = path.join(pluginRepo, "appium-tests", options.platform);
         if (fs.existsSync(testPath)) {
             util.medicLog("Found tests in: " + testPath);
-            testPaths.push(path.join(testPath, "*.spec.js"));
+            options.testPaths.push(path.join(testPath, "*.spec.js"));
         } else {
             util.medicLog("Couldn't find tests in: " + testPath);
         }
     });
-    if (testPaths.length === 0) {
-        util.fatal("Couldn't find the tests. Please check that the plugin repos are cloned.");
-    }
-    switch (platform) {
+
+    // setting default values depending of the platform
+    switch (options.platform) {
     case "android":
         DEFAULT_DEVICE_NAME = DEFAULT_ANDROID_DEVICE_NAME;
         DEFAULT_PLATFORM_VERSION = DEFAULT_ANDROID_PLATFORM_VERSION;
@@ -156,55 +149,76 @@ function parseArgs() {
     case "ios":
         DEFAULT_DEVICE_NAME = DEFAULT_IOS_DEVICE_NAME;
         DEFAULT_PLATFORM_VERSION = DEFAULT_IOS_PLATFORM_VERSION;
-        global.unorm = require('unorm');
         break;
     default:
-        util.fatal("Unsupported platform: " + platform);
+        util.fatal("Unsupported platform: " + options.platform);
         break;
     }
-    appiumDeviceName = argv["device-name"] || DEFAULT_DEVICE_NAME;
-    global.DEVICE_NAME = appiumDeviceName;
-    appiumPlatformVersion = argv["platform-version"] || DEFAULT_PLATFORM_VERSION;
-    global.PLATFORM_VERSION = appiumPlatformVersion;
-    udid = argv.udid;
-    device = argv.device;
-    global.DEVICE = device;
-    outputPath = argv.output;
-    if (platform === "ios" && device && !udid) {
+
+
+    // fail if the user forgot to specify UDID when running on real iOS device
+    if (options.platform === "ios" && options.device && !options.udid) {
         util.fatal("Please supply device UDID by using --udid argument when running on real
iOS device." +
             "More info on finding out your UDID: https://www.innerfence.com/howto/find-iphone-unique-device-identifier-udid");
     }
-}
 
-// Save the app package path for tests to use
-function setPackagePath(callback) {
-    var appFullPath = path.join(__dirname, "../..", appPath),
-        deviceString = device ? " --device" : "",
-        buildCommand = "cordova build " + platform + deviceString;
+    // fail if we couldn't locate the tests
+    if (options.testPaths.length === 0) {
+        util.fatal("Couldn't find the tests. Please check that the plugin repos are cloned.");
+    }
 
-    // remove medic.json and (re)build
-    shell.rm(path.join(appFullPath, "www", "medic.json"));
-    util.medicLog("Building the app...");
-    cp.exec(buildCommand, { cwd: appFullPath, maxBuffer: 1024 * 1024 }, function (error)
{
-        if (error) {
-            util.fatal("Couldn't build the app: " + error);
-        } else {
-            callback();
+    // setting up the global variables so the tests could use them
+    global.WD = wd;
+    global.ET = et;
+    global.SHELL = shell;
+    global.DEVICE = options.device;
+    global.PLATFORM_VERSION = options.appiumPlatformVersion;
+    global.DEVICE_NAME = options.appiumDeviceName;
+    global.SCREENSHOT_PATH = options.screenshotPath;
+    if (options.platform === "ios") {
+        global.unorm = unorm;
+    }
+    global.PACKAGE_PATH = getPackagePath(options);
+
+    // creating a directory to save screenshots to
+    fs.stat(global.SCREENSHOT_PATH, function (err) {
+        if (err) {
+            fs.mkdir(global.SCREENSHOT_PATH);
         }
     });
 
-    switch (platform) {
-    case "android":
-        global.PACKAGE_PATH = path.join(appFullPath, "/platforms/android/build/outputs/apk/android-debug.apk");
-        break;
-    case "ios":
-        if (device) {
-            global.PACKAGE_PATH = path.join(appFullPath, "/platforms/ios/build/device/mobilespec.ipa");
+    return options;
+}
+
+function getLocalCLI() {
+    if (util.isWindows()) {
+        return "cordova.bat";
+    }
+    return "./cordova";
+}
+
+// remove medic.json and rebuild the app
+function prepareApp(options, callback) {
+    var fullAppPath = getFullAppPath(options.appPath);
+    var deviceString = options.device ? " --device" : "";
+    var buildCommand = getLocalCLI() + " build " + options.platform + deviceString;
+
+    // remove medic.json and (re)build
+    shell.rm(path.join(fullAppPath, "www", "medic.json"));
+    fs.stat(fullAppPath, function (error, stats) {
+        if (error || !stats.isDirectory()) {
+            util.fatal("The app directory doesn't exist: " + fullAppPath);
         } else {
-            global.PACKAGE_PATH = path.join(appFullPath, "/platforms/ios/build/emulator/mobilespec.app");
+            util.medicLog("Building the app...");
+            child_process.exec(buildCommand, { cwd: fullAppPath, maxBuffer: SMALL_BUFFER_SIZE
}, function (error) {
+                if (error) {
+                    util.fatal("Couldn't build the app: " + error);
+                } else {
+                    callback();
+                }
+            });
         }
-        break;
-    }
+    });
 }
 
 function isFailFastError(error) {
@@ -214,31 +228,19 @@ function isFailFastError(error) {
     }
 }
 
-function killIosProxy(callback) {
-    if (iosProxyAlive) {
-        iosProxyAlive = false;
+function killProcess(procObj, killSignal, callback) {
+    if (procObj.alive) {
+        procObj.alive = false;
         setTimeout(function () {
             util.medicLog("Killing ios proxy...");
-            kill(iosProxyProcess.pid, "SIGINT", callback);
-        }, 1000);
-    } else {
-        callback();
-    }
-}
-
-function killAppium(callback) {
-    if (appiumAlive) {
-        appiumAlive = false;
-        setTimeout(function () {
-            util.medicLog("Killing appium server...");
-            kill(appiumProcess.pid, "SIGINT", callback);
+            kill(procObj.process.pid, killSignal, callback);
         }, 1000);
     } else {
         callback();
     }
 }
 
-function saveResults(results, callback) {
+function saveResults(results, outputPath, callback) {
     if (typeof callback !== "function") {
         callback = function () { return; };
     }
@@ -255,13 +257,14 @@ function saveResults(results, callback) {
     }
 }
 
-function summarizeAndSaveResults(callback) {
+// TODO: use this function when we get stable Appium results
+function summarizeAndSaveResults(results, outputPath, callback) {
     fs.stat(outputPath, function (error, stats) {
         if (!error && stats.isFile()) {
             fs.readFile(outputPath, util.DEFAULT_ENCODING, function (err, data) {
                 if (!err) {
                     var obj = JSON.parse(data);
-                    util.medicLog('Found autotests results:');
+                    util.medicLog("Found autotests results:");
                     if (obj.hasOwnProperty("total")) {
                         util.medicLog("Adding " + results.total + " total from Appium to
" + obj.total + " total from autotests");
                         results.total += obj.total;
@@ -287,90 +290,10 @@ function summarizeAndSaveResults(callback) {
     });
 }
 
-
-function plural(str, count) {
-    return count === 1 ? str : str + 's';
-}
-
-function repeat(thing, times) {
-    var arr = [], i;
-    for (i = 0; i < times; i++) {
-        arr.push(thing);
-    }
-    return arr;
-}
-
-function indent(str, spaces) {
-    var lines = (str || '').split('\n'),
-        newArr = [],
-        i;
-    for (i = 0; i < lines.length; i++) {
-        newArr.push(repeat(' ', spaces).join('') + lines[i]);
-    }
-    return newArr.join('\n');
-}
-
-function specFailureDetails(result, failedSpecNumber) {
-    var i, failedExpectation;
-
-    console.log(failedSpecNumber + ') ');
-    console.log(result.fullName);
-
-    for (i = 0; i < result.failedExpectations.length; i++) {
-        failedExpectation = result.failedExpectations[i];
-        console.log(indent('Message:', 2));
-        console.log(failedExpectation.message);
-        console.log(indent('Stack:', 2));
-        console.log(indent(failedExpectation.stack, 4));
-    }
-}
-
-function pendingSpecDetails(result, pendingSpecNumber) {
-    console.log(pendingSpecNumber + ') ');
-    console.log(result.fullName);
-    var pendingReason = "No reason given";
-    if (result.pendingReason && result.pendingReason !== '') {
-        pendingReason = result.pendingReason;
-    }
-    console.log(indent(pendingReason, 2));
-}
-
-function reportResults() {
-    var i, specCounts;
-
-    if (failedSpecs.length > 0) {
-        console.log('Failures:');
-    }
-    for (i = 0; i < failedSpecs.length; i++) {
-        specFailureDetails(failedSpecs[i], i + 1);
-    }
-
-    if (pendingSpecs.length > 0) {
-        console.log("Pending:");
-    }
-    for (i = 0; i < pendingSpecs.length; i++) {
-        pendingSpecDetails(pendingSpecs[i], i + 1);
-    }
-
-    if (results.total > 0) {
-        specCounts = results.total + ' ' + plural('spec', results.total) + ', ' +
-            results.failed + ' ' + plural('failure', results.failed);
-
-        if (pendingSpecs.length) {
-            specCounts += ', ' + pendingSpecs.length + ' pending ' + plural('spec', pendingSpecs.length);
-        }
-
-        console.log(specCounts);
-    } else {
-        console.log('No specs found');
-    }
-}
-
-function startTests() {
-    var exitCode = 1,
-        offset = "    ",
-        jasmine = new Jasmine(),
-        medicReporter;
+function startTests(testPaths, appium, iosProxy) {
+    var exitCode = 1;
+    var jasmine = new Jasmine();
+    var medicReporter;
 
     util.medicLog("Running tests from:");
     testPaths.forEach(function (testPath) {
@@ -382,45 +305,17 @@ function startTests() {
         spec_files: testPaths
     });
 
-    medicReporter = {
-        specStarted: function (spec) {
-            util.medicLog("Starting new spec: " + spec.description);
-        },
-        suiteDone: function (suite) {
-            var i;
-            util.medicLog('Suite done: ' + suite.description);
-            util.medicLog('Result was: ' + suite.status);
-            for (i = 0; i < suite.failedExpectations.length; i++) {
-                util.medicLog(suite.failedExpectations[i].message);
-                util.medicLog(offset + suite.failedExpectations[i].stack.replace(/(\r\n|\n|\r)/gm,
"\n" + offset));
-            }
-        },
-        specDone: function (spec) {
-            util.medicLog("Spec " + spec.status + ": " + spec.description);
-            results.total++;
-            if (spec.status === "failed") {
-                failedSpecs.push(spec);
-                results.failed++;
-            } else if (spec.status === "pending") {
-                pendingSpecs.push(spec);
-                results.warnings++;
-            } else {
-                results.passed++;
-            }
-        },
-        jasmineDone: function () {
-            reportResults();
-            killAppium(function () {
-                exitCode = failedSpecs.length === 0 ? 0 : 1;
-                // reporting results to buildbot is disabled
-                // until we get the desired stability of tests
-                //summarizeAndSaveResults(function () {
-                    util.medicLog("Exiting with exit code " + exitCode);
-                    process.exit(exitCode);
-                //});
+    function allDoneCallback(results) {
+        killProcess(appium, KILL_SIGNAL, function () {
+            killProcess(iosProxy, KILL_SIGNAL, function () {
+                exitCode = results.failed === 0 ? 0 : 1;
+                util.medicLog("Exiting with exit code " + exitCode);
+                process.exit(exitCode);
             });
-        }
-    };
+        });
+    }
+
+    medicReporter = new MedicReporter(allDoneCallback);
 
     // don't use default reporter, it exits the process before
     // we would get the chance to kill appium server
@@ -431,88 +326,101 @@ function startTests() {
         // Launch the tests!
         jasmine.execute();
     } catch (e) {
-        killAppium(function () {
-            util.fatal("Error running tests:\n" + e.stack);
+        killProcess(appium, KILL_SIGNAL, function () {
+            killProcess(iosProxy, KILL_SIGNAL, function () {
+                util.fatal("Error running tests:\n" + e.stack);
+            });
         });
     }
 }
 
-function startAppiumServer() {
-    var appiumPlatformName,
-        appiumServerCommand,
-        avdString = "",
-        udidString = "",
-        iosProxyCommand;
-    switch (platform) {
+function startIosProxy(options) {
+    var iosProxyCommand;
+    var iosProxy = {
+        alive: false,
+        process: null
+    };
+
+    if (options.platform === "ios" && options.device && options.udid) {
+        iosProxyCommand = "ios_webkit_debug_proxy -c " + options.udid + ":27753";
+        util.medicLog("Running:");
+        util.medicLog(iosProxyCommand);
+        iosProxy.alive = true;
+        iosProxy.process = child_process.exec(iosProxyCommand, { maxBuffer: BIG_BUFFER_SIZE
}, function () {
+            iosProxy.alive = false;
+            util.medicLog("iOS proxy process exited.");
+        });
+    }
+    return iosProxy;
+}
+
+function startAppiumServer(options, callback) {
+    var appiumPlatformName;
+    var appiumServerCommand;
+    var additionalArgs = "";
+    var appium = {
+        alive: false,
+        process: null
+    };
+
+    // compose a command to run the Appium server
+    switch (options.platform) {
     case "android":
         appiumPlatformName = "Android";
-        if (!device) {
-            avdString = " --avd " + appiumDeviceName;
+        if (!options.device) {
+            additionalArgs += " --avd " + options.appiumDeviceName;
         }
-        appiumServerCommand = "node cordova-medic/node_modules/appium/bin/appium.js " +
-            "--address 127.0.0.1 " +
-            "--port 4723 " +
-            " --platform-name " + appiumPlatformName +
-            " --platform-version " + appiumPlatformVersion +
-            " --automation-name Appium --log-no-color" +
-            avdString +
-            " --device-name \"" + appiumDeviceName + "\"";
         break;
     case "ios":
         appiumPlatformName = "iOS";
-        if (udid) {
-            udidString = " --udid " + udid;
+        if (options.udid) {
+            additionalArgs += " --udid " + options.udid;
         }
-        appiumServerCommand = "node cordova-medic/node_modules/appium/bin/appium.js " +
-            "--address 127.0.0.1 " +
-            "--port 4723 " +
-            " --platform-name " + appiumPlatformName +
-            " --automation-name Appium --log-no-color" +
-            " --device-name \"" + appiumDeviceName + "\"" +
-            udidString;
         break;
     default:
-        throw new Error("Unsupported platform: " + platform);
+        throw new Error("Unsupported platform: " + options.platform);
     }
 
-    // run iOS proxy
-    if (platform === "ios" && device && udid) {
-        iosProxyCommand = "ios_webkit_debug_proxy -c " + udid + ":27753";
-        util.medicLog("Running:");
-        util.medicLog(iosProxyCommand);
-        iosProxyAlive = true;
-        iosProxyProcess = cp.exec(iosProxyCommand, { maxBuffer: 1024 * 1024 }, function ()
{
-            util.medicLog("iOS proxy process exited.");
-        });
-    }
+    appiumServerCommand = "node " + APPIUM_SERVER_PATH +
+        " --address " + APPIUM_IP_ADDRESS +
+        " --port " + APPIUM_PORT +
+        " --platform-name " + appiumPlatformName +
+        " --platform-version " + options.appiumPlatformVersion +
+        " --automation-name Appium --log-no-color" +
+        " --device-name \"" + options.appiumDeviceName + "\"" +
+        additionalArgs;
 
-    // run appium server
+    // run the Appium server
     util.medicLog("Running:");
     util.medicLog(appiumServerCommand);
-    appiumAlive = true;
-    appiumProcess = cp.exec(appiumServerCommand, { maxBuffer: 50 * 1024 * 1024 }, function
(error) {
+    appium.alive = true;
+    appium.process = child_process.exec(appiumServerCommand, { maxBuffer: BIG_BUFFER_SIZE
}, function (error) {
         util.medicLog("Appium process exited.");
-        if (appiumAlive && error) {
-            util.medicLog('Error running appium server: ' + error);
+        if (appium.alive && error) {
+            util.medicLog("Error running appium server: " + error);
             if (isFailFastError(error)) {
                 process.exit(1);
             }
         }
-        appiumAlive = false;
+        appium.alive = false;
     });
 
-    // Wait for appium server to start up, then start tests
-    appiumProcess.stdout.on("data", function (data) {
+    // Wait for the Appium server to start up
+    appium.process.stdout.on("data", function (data) {
         if (data.indexOf("Appium REST http interface listener started") > -1) {
-            startTests();
+            callback(appium);
         }
     });
 }
 
 function main() {
-    parseArgs();
-    setPackagePath(function () {
-        startAppiumServer();
+    var options = parseArgs();
+
+    prepareApp(options, function () {
+        var iosProxy = startIosProxy(options);
+        startAppiumServer(options, function (appium) {
+            startTests(options.testPaths, appium, iosProxy);
+        });
     });
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b3ccc074/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index d39b3fb..d36ab57 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
     "medic": "./medic/medic.js"
   },
   "dependencies": {
-    "appium": "^1.4.15",
+    "appium": "^1.5.0",
     "commander": "^2.8.1",
     "expect-telnet": "^0.5.2",
     "follow": "^0.11.4",


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


Mime
View raw message