Skip to content

Commit

Permalink
Get chrome session back when resetting app
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Feb 1, 2018
1 parent 1601620 commit ccf3ade
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ commands.reset = async function () {
// reset context since we don't know what kind on context we will end up after app launch.
this.curContext = NATIVE_WIN;

return await this.startAUT();
return await this.isChromeSession ? this.startChromeSession() : this.startAUT();
};

commands.startAUT = async function () {
Expand Down
15 changes: 8 additions & 7 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseDriver, DeviceSettings } from 'appium-base-driver';
import Chromedriver from 'appium-chromedriver';
import desiredConstraints from './desired-caps';
import commands from './commands/index';
import { setupNewChromedriver } from './commands/context';
import * as contextCommands from './commands/context';
import helpers from './android-helpers';
import { CHROMIUM_WIN } from './webview-helpers';
import log from './logger';
Expand Down Expand Up @@ -261,10 +261,6 @@ class AndroidDriver extends BaseDriver {
if (this.isChromeSession) {
// start a chromedriver session and proxy to it
await this.startChromeSession();
if (this.shouldDismissChromeWelcome()) {
// dismiss Chrome welcome dialog
await this.dismissChromeWelcome();
}
} else {
if (this.opts.autoLaunch) {
// start app
Expand Down Expand Up @@ -365,8 +361,8 @@ class AndroidDriver extends BaseDriver {
if (!_.includes(knownPackages, this.opts.appPackage)) {
opts.chromeAndroidActivity = this.opts.appActivity;
}
this.chromedriver = await setupNewChromedriver(opts, this.adb.curDeviceId,
this.adb);
this.chromedriver = await contextCommands.setupNewChromedriver(opts, this.adb.curDeviceId,
this.adb);
this.chromedriver.on(Chromedriver.EVENT_CHANGED, (msg) => {
if (msg.state === Chromedriver.STATE_STOPPED) {
this.onChromedriverStop(CHROMIUM_WIN);
Expand All @@ -380,6 +376,11 @@ class AndroidDriver extends BaseDriver {
this.sessionChromedrivers[CHROMIUM_WIN] = this.chromedriver;
this.proxyReqRes = this.chromedriver.proxyReq.bind(this.chromedriver);
this.jwpProxyActive = true;

if (this.shouldDismissChromeWelcome()) {
// dismiss Chrome welcome dialog
await this.dismissChromeWelcome();
}
}

async checkAppPresent () {
Expand Down
25 changes: 22 additions & 3 deletions test/unit/driver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import chaiAsPromised from 'chai-as-promised';
import log from '../../lib/logger';
import sinon from 'sinon';
import helpers from '../../lib/android-helpers';
import * as contextCommands from '../../lib/commands/context';
import { withMocks } from 'appium-test-support';
import AndroidDriver from '../..';
import ADB from 'appium-adb';
import { errors } from 'appium-base-driver';
import { fs } from 'appium-support';
import { SharedPrefsBuilder } from 'shared-preferences-builder';

import _ from 'lodash';

let driver;
let sandbox = sinon.sandbox.create();
Expand Down Expand Up @@ -375,12 +376,30 @@ describe('driver', function () {
await driver.startAndroidSession();
driver.dismissChromeWelcome.calledOnce.should.be.false;
});
});
describe('startChromeSession', function () {
beforeEach(async function () {
driver = new AndroidDriver();
driver.adb = new ADB();
driver.bootstrap = new helpers.bootstrap(driver.adb);
driver.settings = { update () { } };
driver.caps = {};

sandbox.stub(contextCommands, 'setupNewChromedriver').returns({
on: _.noop,
proxyReq: _.noop,
});
sandbox.stub(driver, 'dismissChromeWelcome');
});
afterEach(function () {
sandbox.restore();
});
it('should call dismissChromeWelcome', async function () {
driver.opts.browserName = 'Chrome';
driver.opts.chromeOptions = {
"args" : ["--no-first-run"]
"args": ["--no-first-run"]
};
await driver.startAndroidSession();
await driver.startChromeSession();
driver.dismissChromeWelcome.calledOnce.should.be.true;
});
});
Expand Down

0 comments on commit ccf3ade

Please sign in to comment.