Hello, I’m trying to handle the opening browser from a native app.
I have a native android app. When I click a link on it, it opens a browser. I’m trying to switch to that browser but couldn’t do it. My code block is:
Set<String> contextNames = ((AppiumDriver) webDriver).getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains("android.browser")) {
((AppiumDriver) webDriver).context(contextName);
}
}
After I debugged some (for further questions)
My app contains a vebview on all pages. Here’s what I get when I check with getContextHandles() on any page:
0 = "NATIVE_APP"
1 = "WEBVIEW_com.dmall.app"
If I switch context to webview and getPageSource(), I see there is an empty view.
html xmlns=“http://www.w3.org/1999/xhtml”>head>/head>body>iframe name=“chromedriver dummy frame” src=“about:blank”>/iframe>/body></html
(I removed some chars because of this forum doesn’t accept html)
I started the test again and after click the link that opens a browser and check getContextHandles(), I see
0 = "NATIVE_APP"
1 = "WEBVIEW_com.dmall.app"
2 = "WEBVIEW_com.android.browser"
Everything looks as it should be, right?
Then I’m doing:
((AppiumDriver) webDriver).context(WEBVIEW_com.android.browser);
when I check the page source, I see the same empty webview
html xmlns=“http://www.w3.org/1999/xhtml”></html
By the way, I can’t switch to other webview after this point, it says:
“An unknown server-side error occurred while processing the command. Original error: We already have a chromedriver instance running (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 134 milliseconds”
I guess this is normal
So, how can I switch to browser, any idea, solution, questions, brain storming, anything can be useful.
My capabilities is here:
DesiredCapabilities capability = DesiredCapabilities.android();
capability.setCapability(MobileCapabilityType.APP, "http://172.20.0.196:8088/android/mfandroid-debug.apk");
capability.setCapability(MobileCapabilityType.DEVICE_NAME, "AndroidEmulator" + RandomStringUtils.randomNumeric(3));
capability.setCapability(MobileCapabilityType.PLATFORM, "Android");
capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");
capability.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 3000);
capability.setCapability("autoAcceptAlerts", "true");
capability.setCapability("sendKeyStrategy", "setValue");
Thanks