# Handling webview context switch in parallel

**URL:** <https://discuss.appium.io/t/handling-webview-context-switch-in-parallel/11484>\
**Category:** Support\
**Created:** [July 31, 2016, 8:01am UTC](https://discuss.appium.io/t/handling-webview-context-switch-in-parallel/11484 "2016-07-31T08:01:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harigovind](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@harigovind](https://discuss.appium.io/u/harigovind)\
**Post date:** [July 31, 2016, 8:01am UTC](https://discuss.appium.io/t/handling-webview-context-switch-in-parallel/11484/1 "2016-07-31T08:01:11Z")

</div>

Hello Masters,

I am trying to run a hybrid app test in parallel involves webview. Problem i am facing whenever i call switchcontext to webview , ChromeDriver is killing existing chromedriver sessions . This will cause other test to fail if they are using chromedriver . All help / hints appreciated 🙂

[Chromedriver] Set chromedriver binary as: \AppData\Roaming\npm\node\_modules\appium\node\_modules\appium-android-driver\node\_modules\appium-chromedriver\chromedriver\win\chromedriver.exe  
[Chromedriver] Killing any old chromedrivers, running: FOR /F “usebackq tokens=5” %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F “usebackq” %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))  
[MJSONWP] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: read ECONNRESET  
at doJwpProxy$ (lib/mjsonwp/mjsonwp.js:329:11)  
at tryCatch (\AppData\Roaming\npm\node\_modules\appium\node\_modules\babel-runtime\regenerator\runtime.js:67:40)  
at GeneratorFunctionPrototype.invoke [as \_invoke] (\AppData\Roaming\npm\node\_modules\appium\node\_modules\babel-runtime\regenerator\runtime.js:315:22)  
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (\AppData\Roaming\npm\node\_modules\appium\node\_modules\babel-runtime\regenerator\runtime.js:100:21)  
at GeneratorFunctionPrototype.invoke (\AppData\Roaming\npm\node\_modules\appium\node\_modules\babel-runtime\regenerator\runtime.js:136:37)  
[HTTP] \<-- POST /wd/hub/session/d6be2aab-dfbb-43ea-9677-63cc662d4310/element/0.012612742371857166-3/value 500 2328 ms - 281  
[Chromedriver] Chromedriver exited unexpectedly with code 1, signal null  
[debug] [Chromedriver] Changed state to ‘stopped’

---

<div class="post-metadata">

**Author:** ![harigovind](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@harigovind](https://discuss.appium.io/u/harigovind)\
**Post date:** [July 31, 2016, 8:05am UTC](https://discuss.appium.io/t/handling-webview-context-switch-in-parallel/11484/2 "2016-07-31T08:05:51Z")

</div>

it’s always starting chromedriver on 9515 port, I wonder if there a way to start in user defined port every time ?

---

<div class="post-metadata">

**Author:** ![harigovind](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@harigovind](https://discuss.appium.io/u/harigovind)\
**Post date:** [August 1, 2016, 11:58am UTC](https://discuss.appium.io/t/handling-webview-context-switch-in-parallel/11484/3 "2016-08-01T11:58:05Z")

</div>

Solved … Posting it for others if useful

instead of using Switching using driver.context() , used chromedriver explicitly

File chromeDriverLib = new File("…/path/to/chromedriver.exe");  
String chromeDriverPath = chromeDriverLib.getAbsolutePath();  
System.setProperty(“webdriver.chrome.driver”, chromeDriverPath);

```
		ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(chromeDriverLib)
				.usingAnyFreePort().build();
		service.start();

		Proxy proxy = new Proxy();
		proxy.setHttpProxy(driver.getRemoteAddress().toString());
		ChromeOptions chromeOptions = new ChromeOptions();
		chromeOptions.setExperimentalOption("androidPackage", "app.package.name");
		chromeOptions.setExperimentalOption("androidDeviceSerial", deviceID);
		chromeOptions.setExperimentalOption("androidUseRunningApp", true);

		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability(CapabilityType.PROXY, proxy);
		capabilities.setCapability("chromeOptions", chromeOptions);
		WebDriver chromeDriver = new RemoteWebDriver(service.getUrl(), capabilities);

                    <do webview test steps>
                  service.stop();
                   <continue Native test steps>

```

This has solved my problems and it’s stable as well .
