From 39949dc835b2c1ee78662b8f84262c8a88b832a9 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Mon, 31 Mar 2014 12:15:34 -0700 Subject: [PATCH] check we can launch a device based on user's caps and throw a nice error if not (fix #2114) --- lib/devices/ios/ios.js | 25 ++++++++++++++++++++- package.json | 2 +- submodules/appium-instruments | 2 +- test/functional/ios/testapp/device-specs.js | 14 ++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/devices/ios/ios.js b/lib/devices/ios/ios.js index c18268c28c1..76d4b795cf3 100644 --- a/lib/devices/ios/ios.js +++ b/lib/devices/ios/ios.js @@ -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), @@ -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)) { @@ -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()]; @@ -905,6 +927,7 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) { } else { async.series([ this.endSimulator.bind(this), + checkDeviceAvailable, cleanup, ], function (err) { cb(err); diff --git a/package.json b/package.json index 8135fe1ee94..a318e0d1310 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/submodules/appium-instruments b/submodules/appium-instruments index 65230d0297e..ddc5ae2af4d 160000 --- a/submodules/appium-instruments +++ b/submodules/appium-instruments @@ -1 +1 @@ -Subproject commit 65230d0297e72af970498dc25f7a9e9f7bffdc47 +Subproject commit ddc5ae2af4d8603b2845fd0b22dab68687db3968 diff --git a/test/functional/ios/testapp/device-specs.js b/test/functional/ios/testapp/device-specs.js index 0982fe1672d..4252bc4c7a8 100644 --- a/test/functional/ios/testapp/device-specs.js +++ b/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 () { @@ -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); + }); + }); + });