Handling webview context switch in parallel

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 :slight_smile:

[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’

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

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)

		Proxy proxy = new Proxy();
		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>
                   <continue Native test steps>

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

1 Like