How to use this.suspendChromedriverProxy method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

context.js

Source:context.js Github

copy

Full Screen

...61 if (this.opts.recreateChromeDriverSessions) {62 logger.debug("recreateChromeDriverSessions set to true; killing existing chromedrivers");63 this.stopChromedriverProxies();64 } else {65 this.suspendChromedriverProxy();66 }67 } else {68 throw new Error(`Didn't know how to handle switching to context '${name}'`);69 }70};71/* ---------------------------------72 * On-object context-related helpers73 * --------------------------------- */74// The reason this is a function and not just a constant is that both android-75// driver and selendroid-driver use this logic, and each one returns76// a different default context name77helpers.defaultContextName = function () {78 return NATIVE_WIN;79};80helpers.defaultWebviewName = function () {81 return WEBVIEW_BASE + this.opts.appPackage;82};83helpers.isWebContext = function () {84 return this.curContext !== null && this.curContext !== NATIVE_WIN;85};86// Turn on proxying to an existing Chromedriver session or a new one87helpers.startChromedriverProxy = async function (context) {88 logger.debug(`Connecting to chrome-backed webview context '${context}'`);89 let cd;90 if (this.sessionChromedrivers[context]) {91 // in the case where we've already set up a chromedriver for a context,92 // we want to reconnect to it, not create a whole new one93 logger.debug(`Found existing Chromedriver for context '${context}'. Using it.`);94 cd = this.sessionChromedrivers[context];95 await setupExistingChromedriver(cd);96 } else {97 let opts = _.cloneDeep(this.opts);98 opts.chromeUseRunningApp = true;99 if (opts.extractChromeAndroidPackageFromContextName) {100 let androidPackage = context.match(`${WEBVIEW_BASE}(.+)`);101 if (androidPackage && androidPackage.length > 0) {102 opts.chromeAndroidPackage = androidPackage[1];103 }104 }105 cd = await setupNewChromedriver(opts, this.adb.curDeviceId,106 this.adb);107 // bind our stop/exit handler, passing in context so we know which108 // one stopped unexpectedly109 cd.on(Chromedriver.EVENT_CHANGED, (msg) => {110 if (msg.state === Chromedriver.STATE_STOPPED) {111 this.onChromedriverStop(context);112 }113 });114 // save the chromedriver object under the context115 this.sessionChromedrivers[context] = cd;116 }117 // hook up the local variables so we can proxy this biz118 this.chromedriver = cd;119 this.proxyReqRes = this.chromedriver.proxyReq.bind(this.chromedriver);120 this.jwpProxyActive = true;121};122// Stop proxying to any Chromedriver123helpers.suspendChromedriverProxy = function () {124 this.chromedriver = null;125 this.proxyReqRes = null;126 this.jwpProxyActive = false;127};128// Handle an out-of-band Chromedriver stop event129helpers.onChromedriverStop = async function (context) {130 logger.warn(`Chromedriver for context ${context} stopped unexpectedly`);131 if (context === this.curContext) {132 // we exited unexpectedly while automating the current context and so want133 // to shut down the session and respond with an error134 let err = new Error("Chromedriver quit unexpectedly during session");135 await this.startUnexpectedShutdown(err);136 } else {137 // if a Chromedriver in the non-active context barfs, we don't really138 // care, we'll just make a new one next time we need the context.139 logger.warn("Chromedriver quit unexpectedly, but it wasn't the active " +140 "context, ignoring");141 delete this.sessionChromedrivers[context];142 }143};144// Intentionally stop all the chromedrivers currently active, and ignore145// their exit events146helpers.stopChromedriverProxies = async function () {147 this.suspendChromedriverProxy(); // make sure we turn off the proxy flag148 for (let context of _.keys(this.sessionChromedrivers)) {149 let cd = this.sessionChromedrivers[context];150 logger.debug(`Stopping chromedriver for context ${context}`);151 // stop listening for the stopped state event152 cd.removeAllListeners(Chromedriver.EVENT_CHANGED);153 try {154 await cd.stop();155 } catch (err) {156 logger.warn(`Error stopping Chromedriver: ${err.message}`);157 }158 delete this.sessionChromedrivers[context];159 }160};161helpers.isChromedriverContext = function (viewName) {...

Full Screen

Full Screen

android-context-controller.js

Source:android-context-controller.js Github

copy

Full Screen

...63 // current ChromeDriver doesn't handle more than a single web view64 if (this.isChromedriverContext(name)) {65 this.startChromedriverProxy(name, next);66 } else if (this.isChromedriverContext(this.curContext)) {67 this.suspendChromedriverProxy(next);68 } else if (this.isProxy) { // e.g. WebView context handled in Selendroid69 this.proxyTo('wd/hub/session/' + this.proxySessionId + '/context', 'POST', {name: name}, next);70 }71 }.bind(this));72};73androidContextController.isWebContext = function () {74 return this.curContext !== null && this.curContext !== 'NATIVE_APP';75};76androidContextController.getWindowHandle = function (cb) {77 cb(new NotYetImplementedError(), null);78};79androidContextController.getWindowHandles = function (cb) {80 cb(new NotYetImplementedError(), null);81};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6chaiAsPromised.transferPromiseness = wd.transferPromiseness;7var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const AppiumAndroidDriver = require('appium-android-driver');2AppiumAndroidDriver.prototype.suspendChromedriverProxy = function () {3 if (this.chromedriver) {4 this.chromedriver.suspend();5 }6};7AppiumAndroidDriver.prototype.resumeChromedriverProxy = function () {8 if (this.chromedriver) {9 this.chromedriver.resume();10 }11};12const appiumAndroidDriver = new AppiumAndroidDriver();13appiumAndroidDriver.suspendChromedriverProxy();14appiumAndroidDriver.resumeChromedriverProxy();15const AppiumAndroidDriver = require('appium-android-driver');16AppiumAndroidDriver.prototype.suspendChromedriverProxy = function () {17 if (this.chromedriver) {18 this.chromedriver.suspend();19 }20};21AppiumAndroidDriver.prototype.resumeChromedriverProxy = function () {22 if (this.chromedriver) {23 this.chromedriver.resume();24 }25};26const appiumAndroidDriver = new AppiumAndroidDriver();27appiumAndroidDriver.suspendChromedriverProxy();28appiumAndroidDriver.resumeChromedriverProxy();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var expect = chai.expect;6var assert = chai.assert;7var should = chai.should();8var desired = {9};10var driver = wd.promiseChainRemote('localhost', 4723);11driver.init(desired).then(function () {12}).then(function () {13 return driver.sleep(5000);14}).then(function () {15 return driver.suspendChromedriverProxy();16}).then(function () {17 return driver.sleep(5000);18}).then(function () {19 return driver.resumeChromedriverProxy();20}).then(function () {21 return driver.sleep(5000);22}).then(function () {23 return driver.quit();24}).done();25[debug] [MJSONWP] Calling AppiumDriver.suspendChromedriverProxy() with args: ["ebd8c0a0-5a1c-4f3b-8d3f-6d0c7f9f6d0c"]26 at AndroidDriver.suspendChromedriverProxy$ (C:\Users\pavan\AppData\Roaming\npm\node_modules\appium\lib\devices\android\android.js:692:11)27 at tryCatch (C:\Users\pavan\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)28 at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\pavan\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var should = chai.should();6var assert = chai.assert;7var expect = chai.expect;8var driver = wd.promiseChainRemote('localhost', 4723);9var desired = {10};11driver.init(desired).then(function() {12}).then(function() {13 return driver.sleep(10000);14}).then(function() {15 return driver.suspendChromedriverProxy(10000);16}).then(function() {17}).then(function() {18 return driver.sleep(10000);19}).then(function() {20 return driver.quit();21}).done();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful