From 82875e75313e0bed17060e7a4a264b29983ef184 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Thu, 23 Jan 2014 15:20:02 -0800 Subject: [PATCH] make settings app a first-class appium-supported ios app --- lib/appium.js | 37 ++++++++++++++++++++++++++++++++++ lib/helpers.js | 7 ++++++- test/functional/prefs/prefs.js | 18 +++-------------- test/helpers/driverblock.js | 9 +++++++++ 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/lib/appium.js b/lib/appium.js index d1034575c66..58e446eebd2 100644 --- a/lib/appium.js +++ b/lib/appium.js @@ -9,6 +9,7 @@ var routing = require('./server/routing.js') , unzipApp = helpers.unzipApp , checkSafari = helpers.checkSafari , cleanSafari = helpers.cleanSafari + , checkPreferencesApp = helpers.checkPreferencesApp , copyLocalZip = helpers.copyLocalZip , getiOSSDKVersion = helpers.getiOSSDKVersion , UUID = require('uuid-js') @@ -133,6 +134,8 @@ Appium.prototype.getDeviceTypeFromApp = function(app) { return "android"; } else if ((app && app.toLowerCase() === "safari") || this.args.safari) { return "ios"; + } else if ((app && app.toLowerCase() === "settings")) { + return "ios"; } throw new Error("Could not determine your device type from --app"); }; @@ -261,6 +264,8 @@ Appium.prototype.configureApp = function(desiredCaps, hasAppInCaps, cb) { this.desiredCapabilities.iwebview = true; this.configureLocalApp(path.resolve(__dirname, "../build/WebViewApp/WebViewApp.app"), origin, cb); + } else if (this.isIos() && appPath.toLowerCase() === "settings") { + this.configurePreferences(desiredCaps, cb); } else if (this.isIos() && isPackageOrBundle) { // we have a bundle ID logger.info("App is an iOS bundle, will attempt to run as pre-existing"); @@ -408,6 +413,38 @@ Appium.prototype.configureSafariForLauncher = function (desiredCaps, cb) { }); }; +Appium.prototype.configurePreferences = function(desiredCaps, cb) { + logger.info("Configuring settings app"); + var prefsVer = null; + if (typeof desiredCaps.version !== "undefined" && desiredCaps.version) { + prefsVer = desiredCaps.version; + } + + var sdkNext = function(prefsVer) { + logger.info("Trying to use settings app, version " + prefsVer); + checkPreferencesApp(prefsVer, function(err, attemptedApp, origApp) { + if (err) { + logger.error("Could not prepare settings app with version '" + + prefsVer + "': " + err); + return cb(err); + } + logger.info("Using settings app at " + attemptedApp); + this.args.app = attemptedApp; + this.origAppPath = origApp; + cb(); + }.bind(this)); + }.bind(this); + + if (prefsVer === null) { + getiOSSDKVersion(function(err, prefsVer) { + if (err) return cb(err); + sdkNext(prefsVer); + }); + } else { + sdkNext(prefsVer); + } +}; + Appium.prototype.configureChromeAndroid = function(appPath) { logger.info("Looks like we want chrome on android"); this.deviceType = "android"; diff --git a/lib/helpers.js b/lib/helpers.js index f0c51356346..2f9595ed177 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -146,8 +146,13 @@ exports.checkBuiltInApp = function(appName, version, cb) { var appPath = path.resolve(appDir, appName + ".app"); fs.stat(appPath, function(err, s) { if (err && err.message.indexOf("ENOENT") !== -1) { + logger.info("App is not at " + appPath); fs.stat(newAppDir, function(err, s) { - if (err) return cb(err); + if (err) { + logger.warn("App is also not at " + newAppDir); + return cb(new Error("Couldn't find built in app in its home " + + "or temp dir!")); + } if (checkApp(s, appPath, cb)) { logger.info("Couldn't find original app, but found the temp " + "Appium one so using that"); diff --git a/test/functional/prefs/prefs.js b/test/functional/prefs/prefs.js index 0604d401386..b6d8e460066 100644 --- a/test/functional/prefs/prefs.js +++ b/test/functional/prefs/prefs.js @@ -1,22 +1,10 @@ -/*global describe:true */ "use strict"; -var checkPreferencesApp = require("../../../lib/helpers").checkPreferencesApp - , chai = require('chai') - , should = chai.should() - , appPath = '/tmp/Appium-Preferences.app' - , describeWd = require("../../helpers/driverblock.js").describeForApp(appPath) +var chai = require('chai') + , describeWd = require("../../helpers/driverblock.js").describeForSettings , it = require("../../helpers/driverblock.js").it; -describe('settings app', function() { - it('should copy app correctly', function(done) { - checkPreferencesApp('6.1', function(err, actualAppPath) { - should.not.exist(err); - appPath.should.eql(actualAppPath); - done(); - }); - }); -}); +chai.should(); describeWd('settings app', function(h) { it('should turn off autocomplete', function(done) { diff --git a/test/helpers/driverblock.js b/test/helpers/driverblock.js index 4a508e1f0f7..c654a037f32 100644 --- a/test/helpers/driverblock.js +++ b/test/helpers/driverblock.js @@ -132,6 +132,14 @@ describeForSafari.only = function() { return describeForSafari(true); }; +var describeForSettings = function(desc, tests, host, port, extraCaps) { + var caps = { + app: 'settings' + , device: 'iPhone Simulator' + }; + return describeWithDriver(desc, tests, host, port, caps, extraCaps); +}; + var describeForIWebView = function() { var fn = function(desc, tests, host, port, extraCaps, onlyify) { var caps = { @@ -259,6 +267,7 @@ module.exports.describe = describeWithDriver; module.exports.describeForApp = describeForApp; module.exports.describeForSauce = describeForSauce; module.exports.describeForSafari = describeForSafari; +module.exports.describeForSettings = describeForSettings; module.exports.describeForIWebView = describeForIWebView; module.exports.describeForChrome = describeForChrome; module.exports.Q = wd.Q;