Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async.eachSeries(Object.keys(this.sessionChromedrivers), function (context, cb) {
logger.debug("Stopping chromedriver for context " + context);
// stop listening for the stopped state event
this.sessionChromedrivers[context].removeAllListeners(Chromedriver.EVENT_CHANGED);
this.sessionChromedrivers[context].stop().nodeify(function (err) {
if (err) logger.warn("Error stopping Chromedriver: " + err.message);
// chromedriver isn't valid anymore, so remove it from context list
delete this.sessionChromedrivers[context];
cb();
}.bind(this));
}.bind(this), function (err) {
// if one of these fails, go back to last proxy state and error out
ChromeAndroid.prototype.stop = function (cb) {
// stop listening for the stopped state event
this.chromedriver.removeAllListeners(Chromedriver.EVENT_CHANGED);
// now we can handle the stop on our own
this.chromedriver.stop().nodeify(function (err) {
if (err) logger.warn("Error stopping Chromedriver: " + err.message);
this.onChromedriverStop(cb);
}.bind(this));
};
const knownPackages = [
'org.chromium.chrome.shell',
'com.android.chrome',
'com.chrome.beta',
'org.chromium.chrome',
'org.chromium.webview_shell',
];
if (_.includes(knownPackages, this.opts.appPackage)) {
opts.chromeBundleId = this.opts.appPackage;
} else {
opts.chromeAndroidActivity = this.opts.appActivity;
}
this.chromedriver = await this.setupNewChromedriver(opts, this.adb.curDeviceId, this.adb);
this.chromedriver.on(Chromedriver.EVENT_CHANGED, (msg) => {
if (msg.state === Chromedriver.STATE_STOPPED) {
this.onChromedriverStop(CHROMIUM_WIN);
}
});
// Now that we have a Chrome session, we ensure that the context is
// appropriately set and that this chromedriver is added to the list
// of session chromedrivers so we can switch back and forth
this.curContext = CHROMIUM_WIN;
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();
helpers.stopChromedriverProxies = async function stopChromedriverProxies () {
this.suspendChromedriverProxy(); // make sure we turn off the proxy flag
for (let context of _.keys(this.sessionChromedrivers)) {
let cd = this.sessionChromedrivers[context];
log.debug(`Stopping chromedriver for context ${context}`);
// stop listening for the stopped state event
cd.removeAllListeners(Chromedriver.EVENT_CHANGED);
try {
await cd.stop();
} catch (err) {
log.warn(`Error stopping Chromedriver: ${err.message}`);
}
delete this.sessionChromedrivers[context];
}
};
// For now the only known arg passed this way is androidDeviceSocket used
// by Operadriver (deriving from Chromedriver) // We don't know how other
// Chromium embedders will call this argument so for now it's name needs to
// be configurable. When Google adds the androidDeviceSocket argument to
// the original Chromedriver then we will be sure about its name for all
// Chromium embedders (as their Webdrivers will derive from Chromedriver)
if (this.args.specialChromedriverSessionArgs) {
_.each(this.args.specialChromedriverSessionArgs, function (val, option) {
logger.debug("This method is being deprecated. Apply chromeOptions " +
"normally to pass along options,see sites.google.com/a/" +
"chromium.org/chromedriver/capabilities for more info");
caps.chromeOptions[option] = val;
});
}
caps = this.decorateChromeOptions(caps);
this.chromedriver.on(Chromedriver.EVENT_CHANGED, function (msg) {
if (msg.state === Chromedriver.STATE_STOPPED) {
// bind our stop/exit handler, passing in context so we know which
// one stopped unexpectedly
this.onChromedriverStop(context);
}
}.bind(this));
this.chromedriver.start(caps).nodeify(function (err) {
if (err) return cb(err);
// save the chromedriver object under the context
this.sessionChromedrivers[context] = this.chromedriver;
cb();
}.bind(this));
};
it('should handle chromedriver event with STATE_STOPPED state', async function () {
await driver.startChromedriverProxy('WEBVIEW_1');
await driver.chromedriver.emit(Chromedriver.EVENT_CHANGED,
{state: Chromedriver.STATE_STOPPED});
driver.onChromedriverStop.calledWithExactly('WEBVIEW_1').should.be.true;
});
it('should ignore events if status is not STATE_STOPPED', async function () {
it('should ignore events if status is not STATE_STOPPED', async function () {
await driver.startChromedriverProxy('WEBVIEW_1');
await driver.chromedriver.emit(Chromedriver.EVENT_CHANGED,
{state: 'unhandled_state'});
driver.onChromedriverStop.notCalled.should.be.true;
});
it('should reconnect if session already exists', async function () {
}
};
if (this.args.enablePerformanceLogging) {
caps.loggingPrefs = {performance: 'ALL'};
}
var knownPackages = ["org.chromium.chrome.shell",
"com.android.chrome",
"com.chrome.beta"];
if (!_.contains(knownPackages, this.args.appPackage)) {
caps.chromeOptions.androidActivity = this.args.appActivity;
}
caps = this.decorateChromeOptions(caps);
this.chromedriver.on(Chromedriver.EVENT_CHANGED, function (msg) {
if (msg.state === Chromedriver.STATE_STOPPED) {
logger.info("Chromedriver stopped unexpectedly on us, shutting down " +
"then calling back up with the on-die callback");
this.onChromedriverStop(this.onDieCb);
}
}.bind(this));
this.chromedriver.start(caps).nodeify(function (err) {
if (err) return cb(err);
cb(null, this.chromedriver.sessionId());
}.bind(this));
};