Skip to content

Commit

Permalink
check we can launch a device based on user's caps and throw a nice er…
Browse files Browse the repository at this point in the history
…ror if not (fix #2114)
  • Loading branch information
jlipps committed Mar 31, 2014
1 parent ab7b709 commit 39949dc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
25 changes: 24 additions & 1 deletion lib/devices/ios/ios.js
Expand Up @@ -266,6 +266,7 @@ IOS.prototype.start = function (cb, onDie) {
this.setLocale.bind(this),
this.setPreferences.bind(this),
this.startLogCapture.bind(this),
this.createInstruments.bind(this),
this.setDeviceAndLaunchSimulator.bind(this),
this.installToRealDevice.bind(this),
this.startInstruments.bind(this),
Expand All @@ -278,9 +279,14 @@ IOS.prototype.start = function (cb, onDie) {
});
};

IOS.prototype.startInstruments = function (cb) {
IOS.prototype.createInstruments = function (cb) {
logger.debug("Creating instruments");
this.instruments = this.makeInstruments();
cb();
};

IOS.prototype.startInstruments = function (cb) {
logger.debug("Starting instruments");
this.instruments.start(function (err) {
if (err) {
if (!_.isEmpty(this.logs)) {
Expand Down Expand Up @@ -875,6 +881,22 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, cb);
}.bind(this);

var checkDeviceAvailable = function (cb) {
logger.debug("Checking whether instruments supports our device string");
this.instruments.getAvailableDevices(function (err, availDevices) {
var dString = this.getDeviceString();
if (err) return cb(err);
if (!_.contains(availDevices, dString)) {
var msg = "Could not find a device to launch. You requested '" +
dString + "', but the available devices were: " +
JSON.stringify(availDevices);
logger.error(msg);
return cb(new Error(msg));
}
cb();
}.bind(this));
}.bind(this);

var startSim = function (cb) {
logger.debug("Launching device: " + this.getDeviceString());
var iosSimArgs = ["-SimulateDevice", this.getDeviceString()];
Expand Down Expand Up @@ -905,6 +927,7 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
} else {
async.series([
this.endSimulator.bind(this),
checkDeviceAvailable,
cleanup,
], function (err) {
cb(err);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -79,7 +79,7 @@
"date-utils": "~1.2.14",
"bytes": "~0.2.1",
"appium-atoms": "~0.0.5",
"appium-instruments": "~0.1.19",
"appium-instruments": "~0.1.20",
"appium-uiauto": "~0.0.15",
"mv": "~2.0.0",
"js2xmlparser2": "~0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion submodules/appium-instruments
14 changes: 14 additions & 0 deletions test/functional/ios/testapp/device-specs.js
@@ -1,6 +1,9 @@
/*globals should:true */
"use strict";

var setup = require("../../common/setup-base"),
_ = require('underscore'),
initSession = require('../../../helpers/session').initSession,
desired = require('./desired');

describe('testapp - device -', function () {
Expand All @@ -25,4 +28,15 @@ describe('testapp - device -', function () {
});
});

describe('deviceName', function () {
var newDesired = _.extend(_.clone(desired), {deviceName: "iFailure 3.5-inch"});
var session = initSession(newDesired, {'no-retry': true});

it('should fail gracefully with an invalid deviceName', function (done) {
session.setUp()
.should.be.rejectedWith(/environment you requested was unavailable/)
.nodeify(done);
});
});

});

0 comments on commit 39949dc

Please sign in to comment.