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

chore: Short circuit if the app under test crashes while checking for alerts #1510

Merged
merged 2 commits into from
Feb 28, 2023
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
15 changes: 13 additions & 2 deletions lib/commands/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ATOM_WAIT_TIMEOUT_MS = 2 * 60000;
const ATOM_INITIAL_WAIT_MS = 1000;

const ON_OBSTRUCTING_ALERT_EVENT = 'alert';
const ON_APP_CRASH_EVENT = 'app_crash';

const VISIBLE = 'visible';
const INVISIBLE = 'invisible';
Expand Down Expand Up @@ -573,7 +574,7 @@ extensions.waitForAtom = async function waitForAtom (promise) {
const originalError = (err instanceof B.AggregateError) ? err[0] : err;
this.log.debug(`Error received while executing atom: ${originalError.message}`);
if (originalError instanceof B.TimeoutError) {
throw new Error(`Did not get any response for atom execution after ` +
throw new errors.TimeoutError(`Did not get any response for atom execution after ` +
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
}
throw originalError;
Expand All @@ -597,6 +598,7 @@ extensions.waitForAtom = async function waitForAtom (promise) {
this._waitingAtoms.count++;

let onAlertCallback;
let onAppCrashCallback;
try {
// only restart the monitor if it is not running already
if (this._waitingAtoms.alertMonitor.isResolved()) {
Expand All @@ -606,15 +608,21 @@ extensions.waitForAtom = async function waitForAtom (promise) {
if (await this.checkForAlert()) {
this._waitingAtoms.alertNotifier.emit(ON_OBSTRUCTING_ALERT_EVENT);
}
} catch (ign) {}
} catch (err) {
if (isErrorType(err, errors.InvalidElementStateError)) {
this._waitingAtoms.alertNotifier.emit(ON_APP_CRASH_EVENT, err);
}
}
await B.delay(ATOM_INITIAL_WAIT_MS / 2);
}
})());
}

return await new B((resolve, reject) => {
onAlertCallback = () => reject(new errors.UnexpectedAlertOpenError());
onAppCrashCallback = reject;
this._waitingAtoms.alertNotifier.once(ON_OBSTRUCTING_ALERT_EVENT, onAlertCallback);
this._waitingAtoms.alertNotifier.once(ON_APP_CRASH_EVENT, onAppCrashCallback);
handlePromiseError(timedAtomPromise)
// eslint-disable-next-line promise/prefer-await-to-then
.then(resolve)
Expand All @@ -624,6 +632,9 @@ extensions.waitForAtom = async function waitForAtom (promise) {
if (onAlertCallback) {
this._waitingAtoms.alertNotifier.removeListener(ON_OBSTRUCTING_ALERT_EVENT, onAlertCallback);
}
if (onAppCrashCallback) {
this._waitingAtoms.alertNotifier.removeListener(ON_APP_CRASH_EVENT, onAppCrashCallback);
}
this._waitingAtoms.count--;
}
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"appium": "^2.0.0-beta.40"
},
"devDependencies": {
"@appium/docutils": "^0.2.2",
"@appium/docutils": "^0.x",
"@appium/eslint-config-appium": "^6.0.0",
"@appium/test-support": "^3.0.0",
"@babel/cli": "^7.18.10",
Expand All @@ -141,7 +141,7 @@
"@babel/register": "^7.18.9",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"axios": "^1.x",
"axios": "^1.3.4",
"babel-plugin-source-map-support": "^2.2.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
Expand Down