Merge pull request #1808 from jlipps/master

better support for settings/preferences app
This commit is contained in:
Jonathan Lipps
2014-01-23 17:35:55 -08:00
4 changed files with 63 additions and 19 deletions

View File

@@ -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";

View File

@@ -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");

View File

@@ -1,31 +1,24 @@
/*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
, env = {} // anticipate @sebv changes
, 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();
});
});
});
env.DEVICE = process.env.DEVICE || "IOS6"; // anticipate @sebv changes
chai.should();
describeWd('settings app', function(h) {
it('should turn off autocomplete', function(done) {
var p = {strategy: "tag name", selector: "tableCell", index: 1};
var ios7 = env.DEVICE.indexOf("7") !== -1;
var clickGeneral = {strategy: "tag name", selector: "tableCell", index: ios7 ? 0 : 1};
var clickKeyboard = {strategy: "tag name", selector: "tableCell", index: ios7 ? 3 : 1};
var switchEl;
h.driver
.execute("mobile: findAndAct", [p])
.execute("mobile: findAndAct", [clickGeneral])
.sleep(1000)
.execute("mobile: findAndAct", [p])
.execute("mobile: findAndAct", [clickKeyboard])
.elementByXPath('//switch[@name="Auto-Correction"]')
.then(function(el) { switchEl = el; return el; })
.getValue().then(function(checked) {

View File

@@ -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;