Skip to content

Commit

Permalink
Add the troubleshooting link to the exception messages (#345)
Browse files Browse the repository at this point in the history
* Add the troubleshooting link to the exception messages

* Use a constant
  • Loading branch information
Mykola Mokhnach committed Aug 27, 2018
1 parent 3bf0ebd commit 624cb95
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/tools/apk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import os from 'os';

let apkUtilsMethods = {};

const ACTIVITIES_TROUBLESHOOTING_LINK =
'https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md';

/**
* Check whether the particular package is present on the device under test.
*
Expand Down Expand Up @@ -40,9 +43,15 @@ apkUtilsMethods.startUri = async function (uri, pkg) {
if (!uri || !pkg) {
throw new Error("URI and package arguments are required");
}

const args = [
"am", "start",
"-W",
"-a", "android.intent.action.VIEW",
"-d", uri.replace(/&/g, '\\&'),
pkg,
];
try {
let args = ["am", "start", "-W", "-a", "android.intent.action.VIEW", "-d",
uri.replace(/&/g, '\\&'), pkg];
const res = await this.shell(args);
if (res.toLowerCase().includes('unable to resolve intent')) {
throw new Error(res);
Expand Down Expand Up @@ -122,7 +131,9 @@ apkUtilsMethods.startApp = async function (startAppOptions = {}) {
}
return stdout;
} catch (e) {
throw new Error(`Cannot start the '${startAppOptions.pkg}' application. Original error: ${e.message}`);
throw new Error(`Cannot start the '${startAppOptions.pkg}' application. ` +
`Visit ${ACTIVITIES_TROUBLESHOOTING_LINK} for troubleshooting. ` +
`Original error: ${e.message}`);
}
};

Expand Down Expand Up @@ -237,7 +248,8 @@ apkUtilsMethods.waitForActivityOrNot = async function (pkg, activity, waitForSto
}
log.debug('Incorrect package and activity. Retrying.');
/* jshint ignore:start */
throw new Error(`${possibleActivityNames.map((name) => `'${name}'`).join(' or ')} never ${waitForStop ? 'stopped' : 'started'}`);
throw new Error(`${possibleActivityNames.map((name) => `'${name}'`).join(' or ')} never ${waitForStop ? 'stopped' : 'started'}. ` +
`Visit ${ACTIVITIES_TROUBLESHOOTING_LINK} for troubleshooting`);
/* jshint ignore:end */
});
};
Expand Down

0 comments on commit 624cb95

Please sign in to comment.