Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling when real device logger does not exist #125

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 " +
Expand Down
24 changes: 15 additions & 9 deletions lib/ios-deploy.js
Original file line number Diff line number Diff line change
@@ -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;
export default IOSDeploy;
29 changes: 25 additions & 4 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -149,7 +152,7 @@ class WebDriverAgent {
return xcodebuild;
}

createSimLogsSubProcess () {
async createSimLogsSubProcess () {
let args = [
'-f',
'-n', '0',
Expand All @@ -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;
Expand Down