iOS app with multiple web views only has one web view context and one window handle in that context
See original GitHub issueThe problem
There doesn’t appear to be a working way to switch contexts or window handles from one iOS web view to another, as there seems to only ever be one web view context (with a name that starts with “WEBVIEW_”) and one window handle in that context. Furthermore, attempting to switch window handles in that one context – which admittedly doesn’t make too much sense given there’s only one window handle to begin with, and it seems to already be set to that one by default – hangs Appium Server and the connection eventually times out.
Environment
- Appium version (or git revision) that exhibits the issue: 1.10.0 (via Appium.app)
- Last Appium version that did not exhibit the issue (if applicable): N/A
- Desktop OS/version used to run Appium: macOS Mojave 10.14.2
- Node.js version (unless using Appium.app|exe): I’m using Appium.app
- Mobile platform/version under test: iOS 12.1
- Real device or emulator/simulator: Emulator (iPhone XR)
- Appium CLI or Appium.app|exe: Appium.app 1.10.0
Details
I’ve got a pretty simple app that has two tabs that contain one view each, where each view per tab contains a single web view (WKWebView) that navigate to different URLs when the app is started. No matter what I do, it seems the only web view context available and its one window handle is always set to the first web view, with seemingly no mention in the logs of the latter web view in the other tab; this behavior holds even when I switch tabs, where the web view from the first tab is the only one with a corresponding context and window handle returned.
Perhaps related: attempting to “switch” to this one window handle times out, i.e. the connection hangs for a long while and nothing happens, but I see in the Appium logs that the request was relayed.
Link to Appium logs
https://gist.github.com/jamespizzurro/785e9ee58fd09c70c3cdf6cce08a4afa
Code To Reproduce Issue [ Good To Have ]
This isn’t a complete working example, just a Java code snippet, but hopefully it’s self-explanatory what I’m trying to do:
// assumption: this.driver is set to a properly-configured instance of IOSDriver
Set<String> contextNames = this.driver.getContextHandles();
// ^ returns only one context
for (String contextName : contextNames) {
if (!contextName.startsWith("WEBVIEW_")) {
continue;
}
this.driver.context(contextName);
Set<String> windowNames = this.mobileDriver.getWindowHandles();
// ^ returns only one window handle
for (String windowName : windowNames) {
this.mobileDriver.switchTo().window(windowName);
// ^ Appium hangs during execution of the line above; this is reflected in the logs I've provided
// TODO: do stuff with the content of the web view here
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:22 (5 by maintainers)
Top GitHub Comments
Sounds good. In 1.17.0 there is also a capability,
webviewConnectTimeout
, to specify a length of time (in ms) to poll on the server side. It will wait up to that long for a webview to be present. Otherwise the endpoint checks with the WebInspector and returns whatever is returned, so it Safari isn’t reporting it yet, it won’t be returned.If an issue with webviews comes up, feel free to also mention me in the issue. I check issues but that will flag it to me faster generally speaking.
Awesome! Glad to hear it helps.