Appium native 切换 webview 失败,求大神协助

sky-ma · 2020年04月07日 · 最后由 mackle 回复于 2020年11月20日 · 3160 次阅读

appium.log 报错信息:
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 shell ps'[debug] [35m[AndroidDriver][39m Parsed pid: '8161' pkg: 'tv.danmaku.bili' from
[debug] [35m[AndroidDriver][39m USER PID PPID VSZ RSS WCHAN ADDR S NAME
[debug] [35m[AndroidDriver][39m u0_a921 8161 731 2495168 237272 0 0 S tv.danmaku.bili
[debug] [35m[AndroidDriver][39m Returning process name: 'tv.danmaku.bili'
[debug] [35m[AndroidDriver][39m Parsed pid: '8839' pkg: 'tv.danmaku.bili:web' from
[debug] [35m[AndroidDriver][39m USER PID PPID VSZ RSS WCHAN ADDR S NAME
[debug] [35m[AndroidDriver][39m u0_a921 8839 731 2448644 257836 0 0 S tv.danmaku.bili:web
[debug] [35m[AndroidDriver][39m Returning process name: 'tv.danmaku.bili:web'
[debug] [35m[AndroidDriver][39m Found webviews: ["WEBVIEW_tv.danmaku.bili","WEBVIEW_stetho_tv.danmaku.bili","WEBVIEW_tv.danmaku.bili:web","WEBVIEW_stetho_tv.danmaku.bili:web"]
[debug] [35m[AndroidDriver][39m Available contexts: ["NATIVE_APP","WEBVIEW_tv.danmaku.bili","WEBVIEW_stetho_tv.danmaku.bili","WEBVIEW_tv.danmaku.bili:web","WEBVIEW_stetho_tv.danmaku.bili:web"]
[debug] [35m[AndroidDriver][39m Connecting to chrome-backed webview context 'WEBVIEW_tv.danmaku.bili:web'
[debug] [35m[AndroidDriver][39m A port was not given, using random free port: 8000
[debug] [35m[AndroidDriver][39m Automated Chromedriver download is disabled. Use 'chromedriver_autodownload' server feature to enable it
[debug] [35m[AndroidDriver][39m Before starting chromedriver, androidPackage is 'tv.danmaku.bili'
[debug] [35m[Chromedriver][39m Changed state to 'starting'
[info] [35m[Chromedriver][39m Set chromedriver binary as: D:\chromedriver\2.44\chromedriver.exe
[debug] [35m[Chromedriver][39m Killing any old chromedrivers, running: wmic process where "commandline like '%chromedriver.exe%--port=8000%'" delete[debug] [35m[Chromedriver][39m Successfully cleaned up old chromedrivers
[debug] [35m[Chromedriver][39m Cleaning any old adb forwarded port socket connections
[debug] [35m[ADB][39m List forwarding ports
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 forward --list'
[debug] [35m[ADB][39m Removing forwarded port socket connection: 50257
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 forward --remove tcp:50257'[debug] [35m[ADB][39m Removing forwarded port socket connection: 50303
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 forward --remove tcp:50303'[debug] [35m[Chromedriver][39m Chromedriver version: '2.44.609538'
[debug] [35m[Chromedriver][39m Chromedriver v. 2.44.609538 does not fully support W3C protocol. Defaulting to MJSONWP
[debug] [35m[WD Proxy][39m Matched '/status' to command name 'getStatus'
[debug] [35m[WD Proxy][39m Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"10.0.18362"}}}
[info] [35m[Chromedriver][39m Starting MJSONWP Chromedriver session with capabilities: {
[info] [35m[Chromedriver][39m "desiredCapabilities": {
[info] [35m[Chromedriver][39m "chromeOptions": {
[info] [35m[Chromedriver][39m "androidPackage": "tv.danmaku.bili",
[info] [35m[Chromedriver][39m "androidUseRunningApp": true,
[info] [35m[Chromedriver][39m "androidDeviceSerial": "B2T0216822004895"
[info] [35m[Chromedriver][39m },
[info] [35m[Chromedriver][39m "loggingPrefs": {
[info] [35m[Chromedriver][39m "browser": "ALL"
[info] [35m[Chromedriver][39m }
[info] [35m[Chromedriver][39m }
[info] [35m[Chromedriver][39m }
[debug] [35m[WD Proxy][39m Matched '/session' to command name 'createSession'
[debug] [35m[WD Proxy][39m Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"tv.danmaku.bili","androidUseRunningApp":true,"androidDeviceSerial":"B2T0216822004895"},"loggingPrefs":{"browser":"ALL"}}}[debug] [35m[Chromedriver][39m Webview version: 'Chrome/69.0.3497.100'[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"3b64ac6dd291a6a0491e45e3f8963014","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)"}}
[info] [35m[WD Proxy][39m Determined the downstream protocol as 'MJSONWP'
[info] [35m[WD Proxy][39m The response has an unknown format
[debug] [35m[MJSONWP][39m Matched JSONWP error code 13 to UnknownError
[warn] [35m[Chromedriver][39m Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: unable to discover open pages
[warn] [35m[Chromedriver][39m (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)[debug] [35m[WD Proxy][39m Matched '/session' to command name 'createSession'
[debug] [35m[WD Proxy][39m Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"tv.danmaku.bili","androidUseRunningApp":true,"androidDeviceSerial":"B2T0216822004895"},"loggingPrefs":{"browser":"ALL"}}}[debug] [35m[Chromedriver][39m Webview version: 'Chrome/69.0.3497.100'[info] [35m[HTTP][39m [37m<-- POST /wd/hub/session/392974e8-2e74-48c8-a3d2-97672addda8a/context [39m[32m-[39m [90m- ms - -[39m
[info] [35m[HTTP][39m [90m[39m[info] [35m[HTTP][39m [37m-->[39m [37mDELETE[39m [37m/wd/hub/session/392974e8-2e74-48c8-a3d2-97672addda8a[39m
[info] [35m[HTTP][39m [90m{}[39m
[debug] [35m[W3C (392974e8)][39m Calling AppiumDriver.deleteSession() with args: ["392974e8-2e74-48c8-a3d2-97672addda8a"]
[debug] [35m[BaseDriver][39m Event 'quitSessionRequested' logged at 1586244841316 (15:34:01 GMT+0800 (中国标准时间))
[info] [35m[Appium][39m Removing session 392974e8-2e74-48c8-a3d2-97672addda8a from our master session list
[debug] [35m[UiAutomator2][39m Deleting UiAutomator2 session
[debug] [35m[UiAutomator2][39m Deleting UiAutomator2 server session
[debug] [35m[WD Proxy][39m Matched '/' to command name 'deleteSession'
[debug] [35m[WD Proxy][39m Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/9f9f4b8a-53aa-495a-a41e-2d5118f97369] with no body[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"9f9f4b8a-53aa-495a-a41e-2d5118f97369","value":null}
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 shell am force-stop tv.danmaku.bili'[debug] [35m[Logcat][39m Stopping logcat capture
[debug] [35m[ADB][39m Removing forwarded port socket connection: 8200
[debug] [35m[ADB][39m Running 'D:\Program\andriod\sdk\platform-tools\adb.exe -P 5037 -s B2T0216822004895 forward --remove tcp:8200'[debug] [35m[BaseDriver][39m Event 'quitSessionFinished' logged at 1586244841862 (15:34:01 GMT+0800 (中国标准时间))
[debug] [35m[W3C (392974e8)][39m Received response: null
[debug] [35m[W3C (392974e8)][39m But deleting session, so not returning
[debug] [35m[W3C (392974e8)][39m Responding to client with driver.deleteSession() result: null
[info] [35m[HTTP][39m [37m<-- DELETE /wd/hub/session/392974e8-2e74-48c8-a3d2-97672addda8a [39m[32m200[39m [90m547 ms - 14[39m
[info] [35m[HTTP][39m [90m[39m
[debug] [35m[Instrumentation][39m .[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"b50c8735d77d7432136584f249a3e32d","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)"}}
[info] [35m[WD Proxy][39m Determined the downstream protocol as 'MJSONWP'
[info] [35m[WD Proxy][39m The response has an unknown format
[debug] [35m[MJSONWP][39m Matched JSONWP error code 13 to UnknownError
[warn] [35m[Chromedriver][39m Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: unable to discover open pages
[warn] [35m[Chromedriver][39m (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)[debug] [35m[WD Proxy][39m Matched '/session' to command name 'createSession'
[debug] [35m[WD Proxy][39m Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"tv.danmaku.bili","androidUseRunningApp":true,"androidDeviceSerial":"B2T0216822004895"},"loggingPrefs":{"browser":"ALL"}}}[debug] [35m[Instrumentation][39m Time: 145.291
[debug] [35m[Instrumentation][39m
[debug] [35m[Instrumentation][39m OK (1 test)
[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"7eb1bbf9d5070beea46e5487aa044253","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*9536\n (make sure the app has its WebView configured for debugging)\n (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)"}}
[info] [35m[WD Proxy][39m Determined the downstream protocol as 'MJSONWP'
[info] [35m[WD Proxy][39m The response has an unknown format
[debug] [35m[MJSONWP][39m Matched JSONWP error code 13 to UnknownError
[warn] [35m[Chromedriver][39m Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @webview_devtools_remote_.*9536
[warn] [35m[Chromedriver][39m (make sure the app has its WebView configured for debugging)
[warn] [35m[Chromedriver][39m (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)
[debug] [35m[Instrumentation][39m The process has exited with code 0[debug] [35m[WD Proxy][39m Matched '/session' to command name 'createSession'
[debug] [35m[WD Proxy][39m Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"tv.danmaku.bili","androidUseRunningApp":true,"androidDeviceSerial":"B2T0216822004895"},"loggingPrefs":{"browser":"ALL"}}}[debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"7dd4b9c9edf2f34431f62834af24e0c4","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*9536\n (make sure the app has its WebView configured for debugging)\n (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18362 x86_64)"}}
[info] [35m[WD Proxy][39m Determined the downstream protocol as 'MJSONWP'
[info] [35m[WD Proxy][39m The response has an unknown format

appium 配置:

def start(cls):
    apk_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
    desired_caps = {}
    desired_caps['platformName'] = cls.data["platformName"]  # 设备系统
    desired_caps['platformVersion'] = cls.data["platformVersion"]  # 设备系统版本6.0.1
    desired_caps['deviceName'] = cls.data["deviceName"]  # 设备名称
    desired_caps['udid'] = cls.data["udid"]  # 测试app包名
    #desired_caps['app'] = apk_path + "\\app\\bilibili_5531000.apk"
    desired_caps['appPackage'] = cls.data["appPackage"]  # 测试app包名
    desired_caps['appActivity'] = cls.data["appActivity"]  # 测试appActivity.activity
    desired_caps['browserName'] = ''
    desired_caps['chromedriverExecutable'] = 'D:\\chromedriver\\2.44\\chromedriver.exe'
    desired_caps['autoGrantPermissions'] = True  # 默认授权
    desired_caps['unicodeKeyboard'] = True
    desired_caps['noReset'] = True
    desired_caps['ChromeOptions'] = {'androidProcess': 'WEBVIEW_tv.danmaku.bili:web'}

调用代码:

webview_list = self.driver.contexts
print(webview_list)
# ['NATIVE_APP', 'WEBVIEW_stetho_tv.danmaku.bili', 'WEBVIEW_tv.danmaku.bili:web', 'WEBVIEW_tv.danmaku.bili', 'WEBVIEW_stetho_tv.danmaku.bili:web']
sleep(5)
self.driver.switch_to.context('WEBVIEW_tv.danmaku.bili:web'

pycharm 报错信息:

E urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

共收到 5 条回复 时间 点赞

appium+ 真机:华为 安卓 8.0 系统 ;Webview version: 'Chrome/69.0.3497.100'
报错信息一直是:no page found 或者 urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

安卓上,Webview 需要做如下设置,才可以。

WebView.setWebContentsDebuggingEnabled(true);
a112121788 回复

让开发打的 debug 包,chrome remote debug 可以看到 HTML 页面结构;
我这边有多进程同一个页面,不知道是否有关系
WEBVIEW_tv.danmaku.bili:web 会提示 Chrome version on the device: Chrome/69.0.3497.100 ;
WEBVIEW_tv.danmaku.bili 提示 Webview version: 'Chrome/66.0.3359.126'
chrome debug 打开时,会显示 webview in tv.danmaku.bili(66.0.3359.126) 或者 webview in tv.danmaku.bili(69.0.3497.100)
切换到固定的一个 webview: self.driver.switch_to.context('WEBVIEW_tv.danmaku.bili:web') 目前应该切换成功了,现在报打不开这个页面
unknown error: unable to discover open pages
Chromedriver

sky-ma 回复

我现在跟你报一样的错误:unknown error: unable to discover open pages,Webview 版本也是 66.0.3359.126,请问你解决了吗?

楼主解决了嘛,可真头疼

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册