question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to switch to WebView context on iOS 12.2

See original GitHub issue

The problem

Since the update to iOS 12.2, I am no longer able to switch into the web-view contexts on iOS Simulators.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.13.0
  • Desktop OS/version used to run Appium: Mac OSX 10.14.4
  • Mobile platform/version under test: iOS 12.2
  • Real device or emulator/simulator: Simulator

Details

By using the same app, same appium version, same version of all the appium dependencies but by using iOS 12.1, the issue disappears and I’m able to correctly switch to web-views. By comparing the appium console log of the two executions (the correct one on iOS 12.1 and the failing one on iOS 12.2), it seems like there is a problem on the contexts returned by the AppiumDriver.getContexts() GET method. In particular, it seems like the webview attributes (title, url) are mapped to the native context PID. As a result, the GET method, as you can see in the attached appium log, returns an array composed of the NATIVE_APP context and a WEBVIEW context which actually maps the native context (please notice that the webview name is WEBVIEW_PID_OF_NATIVE_CONTEXT.2, where .2 indicates the second page of a context. As far as I’ve seen so far, in all successful executions the webview contexts end with a .1 suffix). When trying to switch to the returned WEBVIEW, an exception occurs.

Excerpt of the log of the failing execution:

[HTTP] --> GET /wd/hub/session/1db198fa-6984-4550-b09b-326ceb44357b/contexts
[HTTP] {}
[debug] [W3C (1db198fa)] Calling AppiumDriver.getContexts() with args: ["1db198fa-6984-4550-b09b-326ceb44357b"]
[debug] [XCUITest] Executing command 'getContexts'
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false
[debug] [RemoteDebugger] Selecting application
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger]     Application: 'PID:57976'
[debug] [RemoteDebugger]         id: "PID:57976"
[debug] [RemoteDebugger]         isProxy: false
[debug] [RemoteDebugger]         name: "myApp"
[debug] [RemoteDebugger]         bundleId: "myAppBundleID"
[debug] [RemoteDebugger]         hostId: undefined
[debug] [RemoteDebugger]         isActive: 2
[debug] [RemoteDebugger]         isAutomationEnabled: false
[debug] [RemoteDebugger]         pageArray:
[debug] [RemoteDebugger]           - id: 2
[debug] [RemoteDebugger]             title: "myTitle" <--- such attributes are mapped on the native context (PID:57976)
[debug] [RemoteDebugger]             url: "myUrl"
[debug] [RemoteDebugger]             isKey: true
[debug] [RemoteDebugger]     Application: 'PID:58003'
[debug] [RemoteDebugger]         id: "PID:58003"
[debug] [RemoteDebugger]         isProxy: true
[debug] [RemoteDebugger]         name: "com.apple.WebKit.WebContent"
[debug] [RemoteDebugger]         bundleId: "com.apple.WebKit.WebContent"
[debug] [RemoteDebugger]         hostId: "PID:57976"
[debug] [RemoteDebugger]         isActive: 1
[debug] [RemoteDebugger]         isAutomationEnabled: false
[debug] [RemoteDebugger]         pageArray: []
[debug] [RemoteDebugger] Found app id key 'PID:57976' for bundle 'myAppBundleID'
[debug] [RemoteDebugger] Found separate bundleId 'com.apple.WebKit.WebContent' acting as proxy for 'myAppBundleID', with app id 'PID:58003'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:57976, PID:58003
[debug] [RemoteDebugger] Selecting app PID:57976 (try #1 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger (id: 71)
[debug] [RemoteDebugger] Received response from socket send: '["PID:57976",{"1":{"WIRPageIdentifierKey":1,"WI...'
[debug] [RemoteDebugger] Received page change notice for app 'PID:57976' but the listing has not changed. Ignoring.
[debug] [RemoteDebugger] Finally selecting app PID:57976: [{"id":2,"title":"myTitle","url":"myUrl","isKey":true}]
[debug] [W3C (1db198fa)] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_57976.2"] <-- the webview points to PID 57976, which is the native context. The suffix .2 is weird
[HTTP] <-- GET /wd/hub/session/1db198fa-6984-4550-b09b-326ceb44357b/contexts 200 7 ms - 42
....
....
....
[HTTP] --> POST /wd/hub/session/1db198fa-6984-4550-b09b-326ceb44357b/context
[HTTP] {"name":"WEBVIEW_57976.2"}
[debug] [W3C (1db198fa)] Calling AppiumDriver.setContext() with args: ["WEBVIEW_57976.2","1db198fa-6984-4550-b09b-326ceb44357b"]
[debug] [XCUITest] Executing command 'setContext'
[debug] [iOS] Attempting to set context to 'WEBVIEW_57976.2'
[debug] [RemoteDebugger] Selecting page '2' on app 'PID:57976' and forwarding socket setup
[debug] [RemoteDebugger] Sending '_rpc_forwardSocketSetup:' message to remote debugger (id: 72)
[debug] [RemoteDebugger] Sender key set
[debug] [RemoteDebugger] Sending '_rpc_forwardSocketData:' message to remote debugger (id: 73)
[debug] [W3C (1db198fa)] Encountered internal error running command: Error: Remote debugger error with code '-32000': Target not found.
[debug] [W3C (1db198fa)]     at Object.errorHandler (/usr/local/lib/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger-rpc-client.js:246:18)
[debug] [W3C (1db198fa)]     at RpcMessageHandler.handleDataMessage (/usr/local/lib/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger-message-handler.js:194:9)
[debug] [W3C (1db198fa)]     at RpcMessageHandler.handleMessage (/usr/local/lib/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger-message-handler.js:77:13)
[debug] [W3C (1db198fa)]     at RemoteDebuggerRpcClient.handleMessage [as receive] (/usr/local/lib/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger-rpc-client.js:394:35)
[debug] [W3C (1db198fa)]     at Socket.emit (events.js:196:13)
[debug] [W3C (1db198fa)]     at addChunk (_stream_readable.js:290:12)
[debug] [W3C (1db198fa)]     at readableAddChunk (_stream_readable.js:271:11)
[debug] [W3C (1db198fa)]     at Socket.Readable.push (_stream_readable.js:226:10)
[debug] [W3C (1db198fa)]     at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
[HTTP] <-- POST /wd/hub/session/1db198fa-6984-4550-b09b-326ceb44357b/context 500 8

Result of the getContext method of a successful execution:

[HTTP] --> GET /wd/hub/session/156afb3b-5d7a-42dd-8472-09e6cce7d6a9/contexts
[HTTP] {}
[debug] [W3C (156afb3b)] Calling AppiumDriver.getContexts() with args: ["156afb3b-5d7a-42dd-8472-09e6cce7d6a9"]
[debug] [XCUITest] Executing command 'getContexts'
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false
[debug] [RemoteDebugger] Selecting application
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger]     Application: 'PID:58876'
[debug] [RemoteDebugger]         id: "PID:58876"
[debug] [RemoteDebugger]         isProxy: false
[debug] [RemoteDebugger]         name: "myApp"
[debug] [RemoteDebugger]         bundleId: "myAppBundleId"
[debug] [RemoteDebugger]         hostId: undefined
[debug] [RemoteDebugger]         isActive: 2
[debug] [RemoteDebugger]         isAutomationEnabled: false
[debug] [RemoteDebugger]         pageArray: []
[debug] [RemoteDebugger]     Application: 'PID:58899'
[debug] [RemoteDebugger]         id: "PID:58899"
[debug] [RemoteDebugger]         isProxy: true
[debug] [RemoteDebugger]         name: "com.apple.WebKit.WebContent"
[debug] [RemoteDebugger]         bundleId: "com.apple.WebKit.WebContent"
[debug] [RemoteDebugger]         hostId: "PID:58876"
[debug] [RemoteDebugger]         isActive: 1
[debug] [RemoteDebugger]         isAutomationEnabled: false
[debug] [RemoteDebugger]         pageArray:
[debug] [RemoteDebugger]           - id: 1
[debug] [RemoteDebugger]             title: "myTitle" <-- here the webview attributes are mapped to the Webcontent process
[debug] [RemoteDebugger]             url: "myUrl"
[debug] [RemoteDebugger]             isKey: false
[debug] [RemoteDebugger] Found app id key 'PID:58876' for bundle 'myAppBundleID'
[debug] [RemoteDebugger] Found separate bundleId 'com.apple.WebKit.WebContent' acting as proxy for 'myAppBundleID', with app id 'PID:58899'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:58876, PID:58899
[debug] [RemoteDebugger] Selecting app PID:58876 (try #1 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger (id: 101)
[debug] [RemoteDebugger] Received response from socket send: '["PID:58876",{"1":{"WIRPageIdentifierKey":1,"WI...'
[debug] [RemoteDebugger] Received page change notice for app 'PID:58876' but the listing has not changed. Ignoring.
[debug] [RemoteDebugger] Received altered app id, updating from 'PID:58876' to 'PID:58899'
[debug] [RemoteDebugger] Finally selecting app PID:58899: [{"id":1,"title":"myTitle","url":"myUrl","isKey":false}]
[debug] [W3C (156afb3b)] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_58899.1"] <-- here the returned webview maps the second process, i.e., the WebContent process
[HTTP] <-- GET /wd/hub/session/156afb3b-5d7a-42dd-8472-09e6cce7d6a9/contexts 200

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:71 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
imurchiecommented, Nov 22, 2019

Please try the latest beta of Appium (version 1.16.0-beta.2). There has been a lot of work getting this fixed.

1reaction
imurchiecommented, Jun 12, 2019

@lfalkner What is the new error message? Can you post the logs, as a link to a https://gist.github.com? I’d love to get this working for everyone!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appium v1.17.1 unable to switch WebView context in iOS
1) I was able to perform this code. Set<String> contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.
Read more >
Operation timed out while switching to webview context in ...
Hi, I am trying to switch to web view context to interact with few web elements in the hybrid app. I am using...
Read more >
appium-xcuitest-driver - npm
e.g. If you build WDA for 12.2, the module cannot run on iOS 11.4 because of ... appium:autoWebview, Move directly into Webview context...
Read more >
Appium-xcuitest-driver - npm.io
e.g. If you build WDA for 12.2, the module cannot run on iOS 11.4 because of ... appium:autoWebview, Move directly into Webview context...
Read more >
Navigator.share() - Web APIs - MDN Web Docs
Secure context: This feature is available only in secure contexts (HTTPS), in some or all ... The specified share data cannot be validated....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found