From 3b0b6b351f665f47820caff2c9fa9a4ffd383a70 Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Mon, 30 Sep 2013 12:33:49 +0100 Subject: [PATCH] Added solution which allows you to run tests against safari without 20-30 seconds time out using appium. --- app/appium.js | 11 ++++++++--- app/ios.js | 5 ++++- instruments/instruments.js | 18 ++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/appium.js b/app/appium.js index cdbc5e52f..14dddbb90 100644 --- a/app/appium.js +++ b/app/appium.js @@ -628,9 +628,14 @@ Appium.prototype.stop = function(cb) { } logger.info('Shutting down appium session...'); - this.device.stop(function(code) { - this.onDeviceDie(code, cb); - }.bind(this)); + if (typeof this.device.isSafariLauncherApp !== "undefined" && this.device.isSafariLauncherApp === true) { + this.device.stopRemote(); + this.onDeviceDie(0, cb); + } else { + this.device.stop(function(code) { + this.onDeviceDie(code, cb); + }.bind(this)); + } }; diff --git a/app/ios.js b/app/ios.js index 56119f2ee..4821b1b33 100644 --- a/app/ios.js +++ b/app/ios.js @@ -70,6 +70,8 @@ var IOS = function(args) { this.onPageChangeCb = null; this.useRobot = args.robotPort > 0; this.robotUrl = this.useRobot ? "http://" + args.robotAddress + ":" + args.robotPort + "" : null; + this.safariLauncherAppName = "/safarilauncher.app"; + this.isSafariLauncherApp = (typeof args.app !== "undefined") && (args.app.toLowerCase().indexOf(this.safariLauncherAppName, args.app.length - this.safariLauncherAppName.length) !== -1); this.capabilities = { version: '6.0' , webStorageEnabled: false @@ -177,6 +179,7 @@ IOS.prototype.start = function(cb, onDie) { this.instruments = instruments( this.app || this.bundleId , this.udid + , this.isSafariLauncherApp , path.resolve(__dirname, 'uiauto/bootstrap.js') , this.automationTraceTemplatePath , sock @@ -572,7 +575,7 @@ IOS.prototype.cleanupAppState = function(cb) { IOS.prototype.listWebFrames = function(cb, exitCb) { var isDone = false; - if (!this.bundleId) { + if (!this.bundleId && !this.isSafariLauncherApp) { logger.error("Can't enter web frame without a bundle ID"); return cb(new Error("Tried to enter web frame without a bundle ID")); } diff --git a/instruments/instruments.js b/instruments/instruments.js index 6b77c3ba5..24c221fe4 100644 --- a/instruments/instruments.js +++ b/instruments/instruments.js @@ -13,9 +13,10 @@ var spawn = require('child_process').spawn , mkdirp = require('mkdirp') , codes = require('../app/uiauto/lib/status.js').codes; -var Instruments = function(app, udid, bootstrap, template, sock, withoutDelay, xcodeVersion, webSocket, cb, exitCb) { +var Instruments = function(app, udid, isSafariLauncherApp, bootstrap, template, sock, withoutDelay, xcodeVersion, webSocket, cb, exitCb) { this.app = app; this.udid = udid; + this.isSafariLauncherApp = isSafariLauncherApp; this.bootstrap = bootstrap; this.template = template; this.withoutDelay = withoutDelay; @@ -69,7 +70,13 @@ Instruments.prototype.startSocketServer = function(sock) { this.exitHandler(1); }; - var socketConnectTimeout = setTimeout(onSocketNeverConnect.bind(this), 90000); + // for safari launcher app we simply let the socket timeout and catch it. + var socketConnectTimeout = null; + if (this.isSafariLauncherApp) { + socketConnectTimeout = setTimeout(onSocketNeverConnect.bind(this), 8000); + } else { + socketConnectTimeout = setTimeout(onSocketNeverConnect.bind(this), 90000); + } this.socketServer = net.createServer({allowHalfOpen: true}, function(conn) { if (!this.hasConnected) { @@ -160,6 +167,9 @@ Instruments.prototype.launch = function() { self.proc.on('exit', function(code) { self.debug("Instruments exited with code " + code); + if (self.isSafariLauncherApp){ + self.readyHandler(); + } if (self.curCommand && self.curCommand.cb) { self.curCommand.cb({ status: code, @@ -355,7 +365,7 @@ Instruments.prototype.debug = function(msg) { /* NODE EXPORTS */ -module.exports = function(server, app, udid, bootstrap, template, sock, withoutDelay, webSocket, cb, exitCb) { - return new Instruments(server, app, udid, bootstrap, template, sock, withoutDelay, webSocket, cb, exitCb); +module.exports = function(server, app, isSafariLauncherApp, udid, bootstrap, template, sock, withoutDelay, webSocket, cb, exitCb) { + return new Instruments(server, app, isSafariLauncherApp, udid, bootstrap, template, sock, withoutDelay, webSocket, cb, exitCb); };