Skip to content

Commit

Permalink
make settings app a first-class appium-supported ios app
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Jan 23, 2014
1 parent 5934782 commit 82875e7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
37 changes: 37 additions & 0 deletions lib/appium.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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");
};
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion lib/helpers.js
Expand Up @@ -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");
Expand Down
18 changes: 3 additions & 15 deletions 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) {
Expand Down
9 changes: 9 additions & 0 deletions test/helpers/driverblock.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;

0 comments on commit 82875e7

Please sign in to comment.