Android: Appium does not detect all webviews shown by chrome remote debugger
See original GitHub issueThe problem
Appium’s driver.contexts does not list all webviews shown by chrome remote debugger. Also in some cases if chrome is not running in the background then it doesn’t list all webviews. When i manually start chrome and then run the test using Appium it shows the webview
Environment
- Appium version (or git revision) that exhibits the issue: 1.10.0 and before
- Last Appium version that did not exhibit the issue (if applicable): NA
- Desktop OS/version used to run Appium: Mac OSX 10.14
- Node.js version (unless using Appium.app|exe): All
- Mobile platform/version under test: Android 9, 8
- Real device or emulator/simulator: Read device
- Appium CLI or Appium.app|exe:
Details
Appium seems to detect available webviews by looking at the output of /proc/net/unix
angler:/ $ cat /proc/net/unix| grep -i webview
0000000000000000: 00000002 00000000 00010000 0001 01 5144717 @webview_devtools_remote_6142
0000000000000000: 00000003 00000000 00000000 0001 03 5142394 @webview_devtools_remote_6142
Seems like chromedriver has an API to list webviews and it shows all webviews as separate windows. Can we use this logic to fetch the list of webviews entirely through chromedriver as follows?
STEP 1: Launch chromedriver (say on port 8000) and create a new session
POST http://localhost:8000/wd/hub/session
RESPONSE: {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8)"},"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:55964"},...
STEP 2: Get a list of webviews using the debuggerAddress
from the previous response
GET http://localhost:55964/json
RESPONSE: ```
[
{
"description": "{\"attached\":true,\"empty\":false,\"height\":1584,\"screenX\":0,\"screenY\":210,\"visible\":true,\"width\":1080}",
"devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/C2AA84076605682A9FEC208E94BBF38D",
"id": "C2AA84076605682A9FEC208E94BBF38D",
"title": "20190114",
"type": "page",
"url": "https://mobileapp.app.com/todaysdeals",
"webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/C2AA84076605682A9FEC208E94BBF38D"
},
{
"description": "{\"attached\":false,\"empty\":true,\"screenX\":0,\"screenY\":0,\"visible\":true}",
"devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/CC6BB9E0833650D16039C08D47E76AF8",
"faviconUrl": "https://googleads.g.doubleclick.net/favicon.ico",
"id": "CC6BB9E0833650D16039C08D47E76AF8",
"title": "https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader-canary-canary.html",
"type": "page",
"url": "https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader-canary-canary.html",
"webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/CC6BB9E0833650D16039C08D47E76AF8"
},
{
"description": "{\"attached\":false,\"empty\":false,\"height\":181,\"screenX\":0,\"screenY\":0,\"visible\":true,\"width\":1080}",
"devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/10C4C9131158C5FEF9E15C3732544FDA",
"faviconUrl": "https://pubads.g.doubleclick.net/favicon.ico",
"id": "10C4C9131158C5FEF9E15C3732544FDA",
"title": "about:blank",
"type": "page",
"url": "about:blank",
"webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/10C4C9131158C5FEF9E15C3732544FDA"
}
]
STEP 3: Switch to window using window ID C2AA84076605682A9FEC208E94BBF38D
from previous response
> curl -X POST "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/window" --data '{"name": "CDwindow-C2AA84076605682A9FEC208E94BBF38D"}'
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":null}
STEP 4: Check if it switched
> curl "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/window"
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":"CDwindow-C2AA84076605682A9FEC208E94BBF38D"}
STEP 5: Locate element
> curl -X POST "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/element" --data '{"using":"id","value":"id_scfFooter"}'
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":{"ELEMENT":"0.9314698275473243-1"}}
This approach means we only have to create one chromedriver instance even if there are multiple webviews. So this could also fix the issue https://github.com/appium/appium/issues/11820
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@mykola-mokhnach I am not too familiar with Appium codebase. Lemme look into it and get back. I can surely help with testing though.
Currently the logic of web views extraction is aligned with the one used in Chrome. The list of web view pages/windows could be retrieved using the recently added
mobile: getContexts
API.