Skip to content

Commit fb3dfd7

Browse files
authored
Merge pull request #495 from Jonahss/stop-chromedriver-on-reset
stop chromedriver proxies when reset command is called. fixes #12083
2 parents d14b01b + 0d75041 commit fb3dfd7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lib/commands/context.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import log from '../logger';
33
import Chromedriver from 'appium-chromedriver';
44
import PortFinder from 'portfinder';
55
import B from 'bluebird';
6+
import { util } from 'appium-support';
67
import { errors } from 'appium-base-driver';
78
import { default as webviewHelpers,
89
NATIVE_WIN, WEBVIEW_BASE, WEBVIEW_WIN, CHROMIUM_WIN } from '../webview-helpers';
@@ -37,21 +38,22 @@ commands.getContexts = async function () {
3738
};
3839

3940
commands.setContext = async function (name) {
40-
if (name === null) {
41+
if (!util.hasValue(name)) {
4142
name = this.defaultContextName();
4243
} else if (name === WEBVIEW_WIN) {
4344
// handle setContext "WEBVIEW"
4445
name = this.defaultWebviewName();
4546
}
47+
// if we're already in the context we want, do nothing
48+
if (name === this.curContext) {
49+
return;
50+
}
51+
4652
let contexts = await this.getContexts();
4753
// if the context we want doesn't exist, fail
4854
if (!_.includes(contexts, name)) {
4955
throw new errors.NoSuchContextError();
5056
}
51-
// if we're already in the context we want, do nothing
52-
if (name === this.curContext) {
53-
return;
54-
}
5557

5658
await this.switchContext(name);
5759
this.curContext = name;

lib/commands/general.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import androidHelpers from '../android-helpers';
33
import { util } from 'appium-support';
44
import B from 'bluebird';
55
import log from '../logger';
6-
import { NATIVE_WIN } from '../webview-helpers';
76
import moment from 'moment';
87
import { waitForCondition } from 'asyncbox';
98

@@ -227,8 +226,7 @@ commands.startActivity = async function (appPackage, appActivity,
227226
commands.reset = async function () {
228227
await androidHelpers.resetApp(this.adb, Object.assign({}, this.opts, {fastReset: true}));
229228
// reset context since we don't know what kind on context we will end up after app launch.
230-
this.curContext = NATIVE_WIN;
231-
229+
await this.setContext();
232230
return await this.isChromeSession ? this.startChromeSession() : this.startAUT();
233231
};
234232

@@ -258,8 +256,7 @@ commands.setUrl = async function (uri) {
258256
commands.closeApp = async function () {
259257
await this.adb.forceStop(this.opts.appPackage);
260258
// reset context since we don't know what kind on context we will end up after app launch.
261-
this.curContext = NATIVE_WIN;
262-
await this.stopChromedriverProxies();
259+
await this.setContext();
263260
};
264261

265262
commands.getDisplayDensity = async function () {

lib/driver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class AndroidDriver extends BaseDriver {
5151
for (let [cmd, fn] of _.toPairs(commands)) {
5252
AndroidDriver.prototype[cmd] = fn;
5353
}
54+
55+
// needs to be after the line which assigns commands to AndroidDriver.prototype, so that `this.defaultContextName` is defined.
56+
this.curContext = this.defaultContextName();
5457
}
5558

5659
async createSession (...args) {
@@ -99,8 +102,6 @@ class AndroidDriver extends BaseDriver {
99102
this.opts.fastReset = !this.opts.fullReset && !this.opts.noReset;
100103
this.opts.skipUninstall = this.opts.fastReset || this.opts.noReset;
101104

102-
this.curContext = this.defaultContextName();
103-
104105
if (this.isChromeSession) {
105106
log.info("We're going to run a Chrome-based session");
106107
let {pkg, activity} = helpers.getChromePkg(this.opts.browserName);

0 commit comments

Comments
 (0)