diff --git a/lib/driver.js b/lib/driver.js index 94d09918e..74fd27724 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -184,8 +184,8 @@ class XCUITestDriver extends BaseDriver { await this.startSim(); } - await this.installApp(); - + await this.installApp(); + await this.startWda(sessionId, realDevice); if (this.isSafari()) { @@ -536,7 +536,7 @@ class XCUITestDriver extends BaseDriver { async installToSimulator () { if (this.opts.fullReset && this.opts.bundleId) { await removeApp(this.opts.device.udid, this.opts.bundleId); - } + } await installApp(this.opts.device.udid, this.opts.app); } @@ -572,9 +572,7 @@ class XCUITestDriver extends BaseDriver { try { //This iDevice object could be ideviceinstaller (node-idevice) for future once we have ideviceinstaller working for ios 10 let iDevice = new IOSDeploy(this.opts.udid); - if (!await fs.hasAccess(iDevice.cmd)) { - throw new Error(`ios-deploy is not installed or not installed globally. Please install : npm install -g ios-deploy`); - } + await iDevice.checkStatus(); return iDevice; } catch (e) { let msg = "Could not initialize ios-deploy make sure it is " + diff --git a/lib/ios-deploy.js b/lib/ios-deploy.js index dd16e1a7f..73f47f866 100644 --- a/lib/ios-deploy.js +++ b/lib/ios-deploy.js @@ -1,48 +1,54 @@ import { exec } from 'teen_process'; +import { fs } from 'appium-support'; import logger from './logger'; const IOSDEPLOY_PATH = `ios-deploy`; class IOSDeploy { - + constructor (udid) { this.udid = udid; this.cmd = IOSDEPLOY_PATH;// this.cmd is in accordance with iDevice } + async checkStatus () { + // make sure we actually have the program + await fs.which(this.cmd); + } + async remove (bundleid) { let remove = [`--uninstall_only`, `--id`, this.udid, `--bundle_id`, bundleid]; try { let {stdout} = await exec(this.cmd, remove, { maxBuffer: 524288}); logger.debug(`app uninstall stdout : ${stdout}`); } catch (err) { - logger.debug(`Error : ${err.message}`); + logger.debug(`Error : ${err.message}`); throw new Error(`coulld not remove app ${err.message}`); } } async install (app) { - let install = [`--id`, this.udid, `--uninstall`, `--bundle`, app]; + let install = [`--id`, this.udid, `--uninstall`, `--bundle`, app]; try { let {stdout} = await exec(this.cmd, install, { maxBuffer: 524288}); logger.debug(`app install stdout : ${stdout}`); } catch (err) { - logger.debug(`Error : ${err.message}`); + logger.debug(`Error : ${err.message}`); throw new Error(`could not install app ${err.message}`); - } + } } async isInstalled (bundleid) { let isInstalled = [`--exists`, `--id`, this.udid, `--bundle_id`, bundleid]; try { let {stdout} = await exec(this.cmd, isInstalled, { maxBuffer: 524288}); - logger.debug(`app isInstalled stdout : ${stdout}`); + logger.debug(`Stdout from app isInstalled check: ${stdout}`); return (stdout && (stdout.indexOf("true") > -1)); } catch (err) { - logger.debug(`Error : ${err.message}`); + logger.debug(`Error checking install status: ${err.message}`); return false; - } + } } } -export default IOSDeploy; \ No newline at end of file +export default IOSDeploy; diff --git a/lib/webdriveragent.js b/lib/webdriveragent.js index ac4b41395..69047688c 100644 --- a/lib/webdriveragent.js +++ b/lib/webdriveragent.js @@ -61,8 +61,11 @@ class WebDriverAgent { await this.checkForDependencies(); // start the logging process - this.deviceLogs = this.realDevice ? this.createRealDeviceLogsSubProcess() - : this.deviceLogs = this.createSimLogsSubProcess(); + if (this.realDevice) { + this.deviceLogs = await this.createRealDeviceLogsSubProcess(); + } else { + this.deviceLogs = await this.createSimLogsSubProcess(); + } this.xcodebuild = await this.createXcodeBuildSubProcess(); @@ -149,7 +152,7 @@ class WebDriverAgent { return xcodebuild; } - createSimLogsSubProcess () { + async createSimLogsSubProcess () { let args = [ '-f', '-n', '0', @@ -166,7 +169,25 @@ class WebDriverAgent { return new SubProcess(`iproxy`, [localport, deviceport, this.device.udid]); } - createRealDeviceLogsSubProcess () { + async createRealDeviceLogsSubProcess () { + async function checkForLogger (logger) { + // the logger can be the name of a program on the PATH + // or a path to the program + try { + await fs.which(logger); + } catch (err) { + // not on the PATH, so see if it is an accessible path itself + return await fs.exists(logger); + } + + // no error thrown, so all is well + return true; + } + if (!await checkForLogger(this.realDeviceLogger)) { + // we have no logger + throw new Error(`Unable to find real device logging program '${this.realDeviceLogger}'`); + } + let logs = new SubProcess(`${this.realDeviceLogger}`, ['-u', this.device.udid]); this.setupLogging(logs, 'Device'); return logs;