Skip to content

Commit

Permalink
Merge pull request #495 from Jonahss/stop-chromedriver-on-reset
Browse files Browse the repository at this point in the history
stop chromedriver proxies when reset command is called. fixes #12083
  • Loading branch information
Jonahss authored Feb 5, 2019
2 parents d14b01b + 0d75041 commit fb3dfd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 7 additions & 5 deletions lib/commands/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import log from '../logger';
import Chromedriver from 'appium-chromedriver';
import PortFinder from 'portfinder';
import B from 'bluebird';
import { util } from 'appium-support';
import { errors } from 'appium-base-driver';
import { default as webviewHelpers,
NATIVE_WIN, WEBVIEW_BASE, WEBVIEW_WIN, CHROMIUM_WIN } from '../webview-helpers';
Expand Down Expand Up @@ -37,21 +38,22 @@ commands.getContexts = async function () {
};

commands.setContext = async function (name) {
if (name === null) {
if (!util.hasValue(name)) {
name = this.defaultContextName();
} else if (name === WEBVIEW_WIN) {
// handle setContext "WEBVIEW"
name = this.defaultWebviewName();
}
// if we're already in the context we want, do nothing
if (name === this.curContext) {
return;
}

let contexts = await this.getContexts();
// if the context we want doesn't exist, fail
if (!_.includes(contexts, name)) {
throw new errors.NoSuchContextError();
}
// if we're already in the context we want, do nothing
if (name === this.curContext) {
return;
}

await this.switchContext(name);
this.curContext = name;
Expand Down
7 changes: 2 additions & 5 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
};

Expand Down Expand Up @@ -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 () {
Expand Down
5 changes: 3 additions & 2 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb3dfd7

Please sign in to comment.