feat: Bump base driver to version 5
MODIFY
lib/appium.js
lib/appium.js
@@ -371,9 +371,6 @@ class AppiumDriver extends BaseDriver {
});
}
- // this is an async function but we don't await it because it handles
- // an out-of-band promise which is fulfilled if the inner driver
- // unexpectedly shuts down
this.attachUnexpectedShutdownHandler(d, innerSessionId);
log.info(`New ${InnerDriver.name} session created successfully, session ` +
@@ -405,25 +402,33 @@ class AppiumDriver extends BaseDriver {
};
}
- async attachUnexpectedShutdownHandler (driver, innerSessionId) {
+ attachUnexpectedShutdownHandler (driver, innerSessionId) {
+ const removeSessionFromMasterList = (cause = new Error('Unknown error')) => {
+ log.warn(`Closing session, cause was '${cause.message}'`);
+ log.info(`Removing session '${innerSessionId}' from our master session list`);
+ delete this.sessions[innerSessionId];
+ };
+
+ if (_.has(driver.onUnexpectedShutdown, 'then')) {
+ // TODO: Remove this block after all the drivers use base driver above v 5.0.0
// Remove the session on unexpected shutdown, so that we are in a position
// to open another session later on.
- // TODO: this should be removed and replaced by a onShutdown callback.
- try {
- await driver.onUnexpectedShutdown; // this is a cancellable promise
+ driver.onUnexpectedShutdown
+ // eslint-disable-next-line promise/prefer-await-to-then
+ .then(() => {
// if we get here, we've had an unexpected shutdown, so error
throw new Error('Unexpected shutdown');
- } catch (e) {
- if (e instanceof B.CancellationError) {
+ })
+ .catch((e) => {
// if we cancelled the unexpected shutdown promise, that means we
// no longer care about it, and can safely ignore it
- return;
+ if (!(e instanceof B.CancellationError)) {
+ removeSessionFromMasterList(e);
}
- log.warn(`Closing session, cause was '${e.message}'`);
- log.info(`Removing session ${innerSessionId} from our master session list`);
- await sessionsListGuard.acquire(AppiumDriver.name, () => {
- delete this.sessions[innerSessionId];
- });
+ }); // this is a cancellable promise
+ } else {
+ // since base driver v 5.0.0
+ driver.onUnexpectedShutdown(removeSessionFromMasterList);
}
}

MODIFY
package.json
package.json
"dependencies": {
"@babel/runtime": "^7.6.0",
"appium-android-driver": "^4.20.0",
- "appium-base-driver": "^4.1.0",
+ "appium-base-driver": "^5.0.0",
"appium-espresso-driver": "^1.0.0",
"appium-fake-driver": "^0.x",
"appium-flutter-driver": "^0",

MODIFY
test/driver-specs.js
test/driver-specs.js
@@ -256,7 +256,7 @@ describe('AppiumDriver', function () {
it('should remove session if inner driver unexpectedly exits with an error', async function () {
let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing
_.keys(appium.sessions).should.contain(sessionId);
- appium.sessions[sessionId].unexpectedShutdownDeferred.reject(new Error('Oops'));
+ appium.sessions[sessionId].eventEmitter.emit('onUnexpectedShutdown', new Error('Oops'));
// let event loop spin so rejection is handled
await sleep(1);
_.keys(appium.sessions).should.not.contain(sessionId);
@@ -264,19 +264,11 @@ describe('AppiumDriver', function () {
it('should remove session if inner driver unexpectedly exits with no error', async function () {
let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing
_.keys(appium.sessions).should.contain(sessionId);
- appium.sessions[sessionId].unexpectedShutdownDeferred.resolve();
+ appium.sessions[sessionId].eventEmitter.emit('onUnexpectedShutdown');
// let event loop spin so rejection is handled
await sleep(1);
_.keys(appium.sessions).should.not.contain(sessionId);
});
- it('should not remove session if inner driver cancels unexpected exit', async function () {
- let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing
- _.keys(appium.sessions).should.contain(sessionId);
- appium.sessions[sessionId].onUnexpectedShutdown.cancel();
- // let event loop spin so rejection is handled
- await sleep(1);
- _.keys(appium.sessions).should.contain(sessionId);
- });
});
describe('getDriverAndVersionForCaps', function () {
it('should not blow up if user does not provide platformName', function () {

feat: Bump base driver to version 5 (#13635)