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

stop chromedriver proxies when reset command is called. fixes #12083 #495

Merged
merged 1 commit into from
Feb 5, 2019
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
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