Skip to content

Commit

Permalink
add ability for testsuite to determine ios8 sim udid
Browse files Browse the repository at this point in the history
and add support for pull/pushFile in ios8
  • Loading branch information
jlipps committed Oct 13, 2014
1 parent 8304653 commit c12def3
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 61 deletions.
2 changes: 0 additions & 2 deletions lib/devices/ios/ios-controller.js
Expand Up @@ -1852,8 +1852,6 @@ iOSController.moveTo = function (element, xoffset, yoffset, cb) {
x: res.value.x + xoffset
, y: res.value.y + yoffset
};
//console.log("moving mouse to coords:");
//console.log(coords);
if (this.isWebContext()) {
this.curWebCoords = coords;
this.useAtomsElement(element, cb, function (atomsElement) {
Expand Down
75 changes: 48 additions & 27 deletions lib/devices/ios/ios.js
Expand Up @@ -215,6 +215,13 @@ IOS.prototype.configurePreferences = function (cb) {
prefsVer = this.args.platformVersion;
}

if (parseFloat(prefsVer) >= 8) {
logger.debug("We're on iOS8+ so not copying preferences app");
this.args.bundleId = "com.apple.Preferences";
this.args.app = null;
return cb();
}

var sdkNext = function (prefsVer) {
logger.debug("Trying to use settings app, version " + prefsVer);
checkPreferencesApp(prefsVer, this.args.tmpDir, function (err, attemptedApp, origApp) {
Expand Down Expand Up @@ -959,14 +966,14 @@ IOS.prototype.installIpa = function (cb) {
], cb);
};

IOS.prototype.getDeviceString = function () {
var isiPhone = this.args.forceIphone || this.args.forceIpad === null || (this.args.forceIpad !== null && !this.args.forceIpad);
IOS.getDeviceStringFromOpts = function (opts) {
var isiPhone = opts.forceIphone || opts.forceIpad === null || (opts.forceIpad !== null && !opts.forceIpad);
var isTall = isiPhone;
var isRetina = this.xcodeVersion[0] !== '4';
var isRetina = opts.xcodeVersion[0] !== '4';
var is64bit = false;
var deviceName = this.args.deviceName;
var deviceName = opts.deviceName;
var fixDevice = true;
if (deviceName && deviceName[0] === '='){
if (deviceName && deviceName[0] === '=') {
deviceName = deviceName.substring(1);
fixDevice = false;
}
Expand All @@ -977,21 +984,21 @@ IOS.prototype.getDeviceString = function () {
} else if (device.indexOf("ipad") !== -1) {
isiPhone = false;
}
if (deviceName !== this.args.platformName) {
if (deviceName !== opts.platformName) {
isTall = isiPhone && (device.indexOf("4-inch") !== -1);
isRetina = (device.indexOf("retina") !== -1);
is64bit = (device.indexOf("64-bit") !== -1);
}
}

var iosDeviceString = isiPhone ? "iPhone" : "iPad";
if (this.xcodeVersion[0] === '4') {
if (opts.xcodeVersion[0] === '4') {
if (isiPhone && isRetina) {
iosDeviceString += isTall ? " (Retina 4-inch)" : " (Retina 3.5-inch)";
} else {
iosDeviceString += isRetina ? " (Retina)" : "";
}
} else if (this.xcodeVersion[0] === '5') {
} else if (opts.xcodeVersion[0] === '5') {
iosDeviceString += isRetina ? " Retina" : "";
if (isiPhone) {
if (isRetina && isTall) {
Expand All @@ -1002,14 +1009,14 @@ IOS.prototype.getDeviceString = function () {
} else {
iosDeviceString += is64bit ? " (64-bit)" : "";
}
} else if (this.xcodeVersion[0] === '6') {
iosDeviceString = this.args.deviceName ||
} else if (opts.xcodeVersion[0] === '6') {
iosDeviceString = opts.deviceName ||
(isiPhone ? "iPhone Simulator" : "iPad Simulator");
}
var reqVersion = this.args.platformVersion || this.iOSSDKVersion;
if (this.iOSSDKVersion >= 8) {
var reqVersion = opts.platformVersion || opts.iOSSDKVersion;
if (opts.iOSSDKVersion >= 8) {
iosDeviceString += " (" + reqVersion + " Simulator)";
} else if (this.iOSSDKVersion >= 7.1) {
} else if (opts.iOSSDKVersion >= 7.1) {
iosDeviceString += " - Simulator - iOS " + reqVersion;
}
if (fixDevice) {
Expand All @@ -1032,6 +1039,15 @@ IOS.prototype.getDeviceString = function () {
return iosDeviceString;
};

IOS.prototype.getDeviceString = function () {
var opts = _.clone(this.args);
_.extend(opts, {
xcodeVersion: this.xcodeVersion,
iOSSDKVersion: this.iOSSDKVersion
});
return IOS.getDeviceStringFromOpts(opts);
};

IOS.prototype.setDeviceTypeInInfoPlist = function (cb) {
var plist = path.resolve(this.args.app, "Info.plist");
var dString = this.getDeviceString();
Expand Down Expand Up @@ -1075,6 +1091,22 @@ IOS.prototype.getBundleIdFromApp = function (cb) {
}.bind(this));
};

IOS.getSimForDeviceString = function (dString, availDevices) {
var matchedDevice = null;
var matchedUdid = null;
_.each(availDevices, function (device) {
if (device.indexOf(dString) !== -1) {
matchedDevice = device;
try {
matchedUdid = /.+\[([^\]]+)\]/.exec(device)[1];
} catch (e) {
matchedUdid = null;
}
}
});
return [matchedDevice, matchedUdid];
};

IOS.prototype.checkDeviceAvailable = function (cb) {
if (this.iOSSDKVersion >= 7.1) {
logger.debug("Checking whether instruments supports our device string");
Expand All @@ -1089,22 +1121,11 @@ IOS.prototype.checkDeviceAvailable = function (cb) {
};
var dString = this.getDeviceString();
if (this.iOSSDKVersion >= 8) {
var matchedDevice = null;
var matchedUdid = null;
_.each(availDevices, function (device) {
if (device.indexOf(dString) !== -1) {
matchedDevice = device;
try {
matchedUdid = /.+\[([^\]]+)\]/.exec(device)[1];
} catch (e) {
matchedUdid = null;
}
}
}.bind(this));
if (matchedDevice === null || matchedUdid === null) {
var sim = IOS.getSimForDeviceString(dString, availDevices);
if (sim[0] === null || sim[1] === null) {
return noDevicesError();
}
this.iOSSimUdid = matchedUdid;
this.iOSSimUdid = sim[1];
logger.debug("iOS8 sim UDID is " + this.iOSSimUdid);
return cb();
} else if (!_.contains(availDevices, dString)) {
Expand Down
55 changes: 38 additions & 17 deletions test/functional/ios/file-movement-specs.js
Expand Up @@ -8,12 +8,13 @@ var setup = require("../common/setup-base")
, Readable = require('stream').Readable
, iOSSettings = require('../../../lib/devices/ios/settings.js')
, exec = require('child_process').exec
, getSimUdid = require('../../helpers/sim-udid.js').getSimUdid
, Unzip = require('unzip');

describe('file movements - pullFile and pushFile', function () {
var driver;
var desired = {
app: getAppPath('testapp')
app: getAppPath('TestApp')
};
setup(this, desired).then(function (d) { driver = d; });

Expand Down Expand Up @@ -54,21 +55,41 @@ describe('file movements - pullFile and pushFile', function () {
var fullPath = "";
before(function (done) {
var pv = env.CAPS.platformVersion || '7.1';
var simRoots = iOSSettings.getSimRootsWithVersion(pv);
if (simRoots.length < 1) {
return done(new Error("Didn't find any simulator directories"));
}
var basePath = path.resolve(simRoots[0], 'Applications')
.replace(/\s/g, '\\ ');
var ios8 = parseFloat(pv) >= 8;
var next = function (udid) {
var simRoots = iOSSettings.getSimRootsWithVersion(pv, udid);
if (simRoots.length < 1) {
return done(new Error("Didn't find any simulator directories"));
}
var basePath;
if (ios8) {
// ios8 apps are stored in a different directory structure, need
// to navigate down a few more here
basePath = path.resolve(simRoots[0], 'Containers', 'Bundle',
'Application');
} else {
basePath = path.resolve(simRoots[0], 'Applications');
}
basePath = basePath.replace(/\s/g, '\\ ');

var findCmd = 'find ' + basePath + ' -name "testapp.app"';
exec(findCmd, function (err, stdout) {
if (err) return done(err);
if (!stdout) return done(new Error("Could not find testapp.app"));
var appRoot = stdout.replace(/\n$/, '');
fullPath = path.resolve(appRoot, fileName);
fs.writeFile(fullPath, fileContent, done);
});
var findCmd = 'find ' + basePath + ' -name "TestApp.app"';
exec(findCmd, function (err, stdout) {
if (err) return done(err);
if (!stdout) return done(new Error("Could not find testapp.app"));
var appRoot = stdout.replace(/\n$/, '');
fullPath = path.resolve(appRoot, fileName);
fs.writeFile(fullPath, fileContent, done);
});
};

if (ios8) {
getSimUdid('6', env.CAPS, function (err, udid) {
if (err) return done(err);
next(udid);
});
} else {
next();
}
});
after(function (done) {
if (fullPath) {
Expand All @@ -78,7 +99,7 @@ describe('file movements - pullFile and pushFile', function () {
}
});
it('should be able to fetch a file from the app directory', function (done) {
var arg = path.resolve('/testapp.app', fileName);
var arg = path.resolve('/TestApp.app', fileName);
driver
.pullFile(arg)
.then(function (data) {
Expand All @@ -92,7 +113,7 @@ describe('file movements - pullFile and pushFile', function () {
it('should pull all the files in Library/AddressBook', function (done) {
var entryCount = 0;
driver.pullFolder('Library/AddressBook')
.then( function (data) {
.then(function (data) {
var zipStream = new Readable();
zipStream._read = function noop() {};
zipStream
Expand Down
18 changes: 15 additions & 3 deletions test/functional/ios/prefs/check-safari-settings.js
@@ -1,6 +1,7 @@
"use strict";

var _ = require('underscore');
var _ = require('underscore')
, getSimUdid = require('../../../helpers/sim-udid').getSimUdid;

exports.ios6 = function (driver, setting, expected, cb) {
driver
Expand All @@ -20,12 +21,12 @@ exports.ios6 = function (driver, setting, expected, cb) {
}).nodeify(cb);
};

exports.ios7 = function (setting, expected, cb) {
var ios7up = function (version, udid, setting, expected, cb) {
var settingsSets;
var foundSettings;
try {
var settingsPlists = require('../../../../lib/devices/ios/settings.js');
settingsSets = settingsPlists.getSettings('7', 'mobileSafari');
settingsSets = settingsPlists.getSettings(version, udid, 'mobileSafari');
} catch (e) {
return cb(e);
}
Expand All @@ -46,3 +47,14 @@ exports.ios7 = function (setting, expected, cb) {
}
cb();
};

exports.ios7up = function (desired, setting, expected, cb) {
if (parseFloat(desired.platformVersion) >= 8) {
getSimUdid('6', desired, function (err, udid) {
if (err) return cb(err);
ios7up(desired.platformVersion, udid, setting, expected, cb);
});
} else {
ios7up(desired.platformVersion, null, setting, expected, cb);
}
};
14 changes: 9 additions & 5 deletions test/functional/ios/prefs/safari-allows-popup-specs.js
Expand Up @@ -36,19 +36,21 @@ if (env.IOS6) {
});
});
});
} else if (env.IOS7) {
describe('safari ios7 prefs @skip-ci', function () {
} else if (env.IOS7 || env.IOS8) {
describe('safari ios7/8 prefs @skip-ci', function () {
// TODO modify the test to enable ci, right know it is checking a local file,
// not gonna work with sauce
var checkSafariSetting = require('./check-safari-settings').ios7;
var checkSafariSetting = require('./check-safari-settings').ios7up;

describe('using safariAllowPopups', function () {
var driver;
setup(this, _.defaults({safariAllowPopups: true}, desired))
.then(function (d) { driver = d; });

it('should respond to cap when true', function (done) {
checkSafariSetting('WebKitJavaScriptCanOpenWindowsAutomatically', true, done);
checkSafariSetting(driver._origCaps,
'WebKitJavaScriptCanOpenWindowsAutomatically',
true, done);
});
});

Expand All @@ -58,7 +60,9 @@ if (env.IOS6) {
.then(function (d) { driver = d; });

it('should respond to cap when false', function (done) {
checkSafariSetting('WebKitJavaScriptCanOpenWindowsAutomatically', false, done);
checkSafariSetting(driver._origCaps,
'WebKitJavaScriptCanOpenWindowsAutomatically',
false, done);
});
});
});
Expand Down
14 changes: 8 additions & 6 deletions test/functional/ios/prefs/safari-ignore-fraud-warning-specs.js
Expand Up @@ -36,19 +36,20 @@ if (env.IOS6) {
});
});
});
} else if (env.IOS7) {
describe('safari ios7 prefs @skip-ci', function () {
} else if (env.IOS7 || env.IOS8) {
describe('safari ios7/8 prefs @skip-ci', function () {
// TODO modify the test to enable ci, right know it is checking a local file,
// not gonna work with sauce
var checkSafariSetting = require('./check-safari-settings').ios7;
var checkSafariSetting = require('./check-safari-settings').ios7up;

describe('using safariIgnoreFraudWarning', function () {
var driver;
setup(this, _.defaults({safariIgnoreFraudWarning: true}, desired))
.then(function (d) { driver = d; });

it('should respond to cap when true', function (done) {
checkSafariSetting('WarnAboutFraudulentWebsites', false, done);
checkSafariSetting(driver._origCaps, 'WarnAboutFraudulentWebsites',
false, done);
});
});

Expand All @@ -58,8 +59,9 @@ if (env.IOS6) {
.then(function (d) { driver = d; });

it('should respond to cap when false', function (done) {
checkSafariSetting('WarnAboutFraudulentWebsites', true, done);
checkSafariSetting(driver._origCaps, 'WarnAboutFraudulentWebsites',
true, done);
});
});
});
}
}
5 changes: 4 additions & 1 deletion test/helpers/session.js
Expand Up @@ -132,7 +132,10 @@ module.exports.initSession = function (desired, opts) {
return androidUninstall(desired.appPackage);
}
}).then(function () { return init(attempts); })
.then(function () { initialized = true; })
.then(function () {
initialized = true;
browser._origCaps = caps;
})
.setImplicitWaitTimeout(env.IMPLICIT_WAIT_TIMEOUT);
},
tearDown: function (passed) {
Expand Down
24 changes: 24 additions & 0 deletions test/helpers/sim-udid.js
@@ -0,0 +1,24 @@
"use strict";

var IOS = require("../../lib/devices/ios/ios")
, Instruments = require('../../lib/devices/ios/instruments');

exports.getSimUdid = function (xcodeVer, sdkVer, desired, cb) {
var opts = {
forceIphone: false,
forceIpad: false,
xcodeVersion: xcodeVer,
deviceName: desired.deviceName,
platformVersion: desired.platformVersion,
iOSSDKVersion: sdkVer
};
Instruments.getAvailableDevices(function (err, availDevices) {
if (err) return cb(err);
var dString = IOS.getDeviceStringFromOpts(opts);
var sim = IOS.getSimForDeviceString(dString, availDevices);
if (sim[1] === null) {
return cb(new Error("Could not get UDID"));
}
cb(null, sim[1]);
});
};

0 comments on commit c12def3

Please sign in to comment.