diff --git a/lib/commands/context.js b/lib/commands/context.js index 13d06df22..ed35042be 100644 --- a/lib/commands/context.js +++ b/lib/commands/context.js @@ -37,7 +37,7 @@ commands.getContexts = async function () { }; commands.setContext = async function (name) { - if (name === null) { + if (name === null || name === undefined) { name = this.defaultContextName(); } else if (name === WEBVIEW_WIN) { // handle setContext "WEBVIEW" diff --git a/lib/commands/general.js b/lib/commands/general.js index 7dc8c2f8e..341fe84fc 100644 --- a/lib/commands/general.js +++ b/lib/commands/general.js @@ -3,7 +3,6 @@ import androidHelpers from '../android-helpers'; import { util } from 'appium-support'; import B from 'bluebird'; import log from '../logger'; -import { NATIVE_WIN } from '../webview-helpers'; import moment from 'moment'; import { waitForCondition } from 'asyncbox'; @@ -227,8 +226,7 @@ commands.startActivity = async function (appPackage, appActivity, commands.reset = async function () { await androidHelpers.resetApp(this.adb, Object.assign({}, this.opts, {fastReset: true})); // reset context since we don't know what kind on context we will end up after app launch. - this.curContext = NATIVE_WIN; - + await this.setContext(); return await this.isChromeSession ? this.startChromeSession() : this.startAUT(); }; @@ -258,8 +256,7 @@ commands.setUrl = async function (uri) { commands.closeApp = async function () { await this.adb.forceStop(this.opts.appPackage); // reset context since we don't know what kind on context we will end up after app launch. - this.curContext = NATIVE_WIN; - await this.stopChromedriverProxies(); + await this.setContext(); }; commands.getDisplayDensity = async function () { diff --git a/lib/driver.js b/lib/driver.js index 97217b600..20106cc66 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -51,6 +51,9 @@ class AndroidDriver extends BaseDriver { for (let [cmd, fn] of _.toPairs(commands)) { AndroidDriver.prototype[cmd] = fn; } + + // needs to be after the line which assigns commands to AndroidDriver.prototype, so that `this.defaultContextName` is defined. + this.curContext = this.defaultContextName(); } async createSession (...args) { @@ -99,8 +102,6 @@ class AndroidDriver extends BaseDriver { this.opts.fastReset = !this.opts.fullReset && !this.opts.noReset; this.opts.skipUninstall = this.opts.fastReset || this.opts.noReset; - this.curContext = this.defaultContextName(); - if (this.isChromeSession) { log.info("We're going to run a Chrome-based session"); let {pkg, activity} = helpers.getChromePkg(this.opts.browserName);