移动自动化-微信H5切换webview的androidProcess问题

今天做微信H5自动化,切换H5报错。
找到思寒大佬帖子 微信 webview 的自动化技术
对于这里的androidProcess值有一个疑问,看到有跟帖也是有其他的值,不清楚这个值是怎么来的?

image
image

查相关的进程是如下 :flushed:

麻烦老师们指点一二

你发的那个截图下面就有讲这个值是怎么来的

不过我看了一下帖子是16年的了,那时候旧版本的appium有BUG才导致切换context有问题,于是加上了这种方法来临时解决问题,现在的appium应该已经没有那个问题了,建议你还是发具体的报错信息来分析一下

webview的context是:WEBVIEW_com.tencent.mm:tools,目前是取和 context 的最像的:joy:。因为查了进程有许多,对 androidProcess 进程的理解不明确 。
而且,我现在用的appium不加这句还是会报错呢
环境

Python: 3.7
Appium: v 1.17.0

相关代码如下

    def start(cls):
        caps = {}
        caps["platformName"] = "Android"
        caps["deviceName"] = "test"
        caps["appPackage"] = "com.tencent.mm"
        caps["appActivity"] = ".ui.LauncherUI"
        caps["noReset"] = True
        caps["autoGrantPermissions"] = True
        caps["skipServerInstallation"] = True
        caps["skipDeviceInitialization"] = True
        caps["chromedriverExecutable"] = r'D:\chromedriver.exe'
        caps["chromeOptions"] = {
            'androidProcess': 'com.tencent.mm:tools'
        }

        cls.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        cls.driver.implicitly_wait(10)
        return MainPage(cls.driver)

将chromeOptions注释后报错信息如下:

[HTTP]
[HTTP] --> POST /wd/hub/session/1ecf7585-a1c3-4dd2-acf2-3660cce2e77f/element/93a722bc-b4d6-4325-b943-c0e17950f3fe/click
[HTTP] {"id":"93a722bc-b4d6-4325-b943-c0e17950f3fe"}
[debug] [W3C (1ecf7585)] Calling AppiumDriver.click() with args: ["93a722bc-b4d6-4325-b943-c0e17950f3fe","1ecf7585-a1c3-4dd2-acf2-3660cce2e77f"]
[debug] [WD Proxy] Matched '/element/93a722bc-b4d6-4325-b943-c0e17950f3fe/click' to command name 'click'
[debug] [WD Proxy] Proxying [POST /element/93a722bc-b4d6-4325-b943-c0e17950f3fe/click] to [POST http://127.0.0.1:8200/wd/hub/session/343a8f88-0d21-488d-a029-96f8ecddc99a/element/93a722bc-b4d6-4325-b943-c0e17950f3fe/click] with body: {"element":"93a722bc-b4d6-4325-b943-c0e17950f3fe"}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"343a8f88-0d21-488d-a029-96f8ecddc99a","value":null}
[debug] [W3C (1ecf7585)] Responding to client with driver.click() result: null
[HTTP] <-- POST /wd/hub/session/1ecf7585-a1c3-4dd2-acf2-3660cce2e77f/element/93a722bc-b4d6-4325-b943-c0e17950f3fe/click 200 3571 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/1ecf7585-a1c3-4dd2-acf2-3660cce2e77f/context
[HTTP] {"name":"WEBVIEW_com.tencent.mm:tools"}
[debug] [W3C (1ecf7585)] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.tencent.mm:tools","1ecf7585-a1c3-4dd2-acf2-3660cce2e77f"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Running 'D:\androidsdk\platform-tools\adb.exe -P 5037 -s bed1dc08 shell cat /proc/net/unix'
[AndroidDriver] Not checking whether webviews have active pages; use the 'ensureWebviewsHavePages' cap to turn this check on
[debug] [AndroidDriver] WEBVIEW_19056 mapped to pid 19056
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Running 'D:\androidsdk\platform-tools\adb.exe -P 5037 -s bed1dc08 shell ps'
[debug] [AndroidDriver] Parsed pid: '19056' pkg: 'com.tencent.mm:tools' from
[debug] [AndroidDriver]     USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
[debug] [AndroidDriver]     u0_a137      19056   643 9753068 345268 0                   0 S com.tencent.mm:tools
[debug] [AndroidDriver] Returning process name: 'com.tencent.mm:tools'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.tencent.mm:tools","WEBVIEW_xweb"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools","WEBVIEW_xweb"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[debug] [AndroidDriver] A port was not given, using random free port: 8000
[debug] [AndroidDriver] Automated Chromedriver download is disabled. Use 'chromedriver_autodownload' server feature to enable it
[debug] [AndroidDriver] Before starting chromedriver, androidPackage is 'com.tencent.mm'
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: D:\chromedriver.exe
[debug] [Chromedriver] Killing any old chromedrivers, running: wmic process where "commandline like '%chromedriver.exe%--port=8000%'" delete
[debug] [Chromedriver] Successfully cleaned up old chromedrivers
[debug] [Chromedriver] Cleaning any old adb forwarded port socket connections
[debug] [ADB] List forwarding ports
[debug] [ADB] Running 'D:\androidsdk\platform-tools\adb.exe -P 5037 -s bed1dc08 forward --list'
[debug] [ADB] Removing forwarded port socket connection: 52130
[debug] [ADB] Running 'D:\androidsdk\platform-tools\adb.exe -P 5037 -s bed1dc08 forward --remove tcp\:52130'
[Chromedriver] Spawning chromedriver with: D:\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[debug] [Chromedriver] Chromedriver version: '2.40.565498'
[debug] [Chromedriver] Chromedriver v. 2.40.565498 does not fully support W3C protocol. Defaulting to MJSONWP
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"10.0.18362"}}}
[Chromedriver] Starting MJSONWP Chromedriver session with capabilities: {
[Chromedriver]   "desiredCapabilities": {
[Chromedriver]     "chromeOptions": {
[Chromedriver]       "androidPackage": "com.tencent.mm",
[Chromedriver]       "androidUseRunningApp": true,
[Chromedriver]       "androidDeviceSerial": "bed1dc08"
[Chromedriver]     },
[Chromedriver]     "loggingPrefs": {
[Chromedriver]       "browser": "ALL"
[Chromedriver]     }
[Chromedriver]   }
[Chromedriver] }
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"bed1dc08"},"loggingPrefs":{"browser":"ALL"}}}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"34c0dec2308ca95b912d68debe4274db","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632\n  (make sure the app has its WebView configured for debugging)\n
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)"}}
[WD Proxy] Determined the downstream protocol as 'MJSONWP'
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[Chromedriver] 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_.*18632
[Chromedriver]   (make sure the app has its WebView configured for debugging)
[Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64) [debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"bed1dc08"},"loggingPrefs":{"browser":"ALL"}}}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"565becd6f0a78ab4a1367a165aa72b21","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632\n  (make sure the app has its WebView configured for debugging)\n
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)"}}
[WD Proxy] Determined the downstream protocol as 'MJSONWP'
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[Chromedriver] 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_.*18632
[Chromedriver]   (make sure the app has its WebView configured for debugging)
[Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64) [debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"bed1dc08"},"loggingPrefs":{"browser":"ALL"}}}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"53335c2f144e8f2dd01f9ec6758e92b8","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632\n  (make sure the app has its WebView configured for debugging)\n
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)"}}
[WD Proxy] Determined the downstream protocol as 'MJSONWP'
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[Chromedriver] 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_.*18632
[Chromedriver]   (make sure the app has its WebView configured for debugging)
[Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64) [debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"bed1dc08"},"loggingPrefs":{"browser":"ALL"}}}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"b6896855a1cd62edaef8ec6916a4f68e","status":13,"value":{"message":"unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632\n  (make sure the app has its WebView configured for debugging)\n
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)"}}
[WD Proxy] Determined the downstream protocol as 'MJSONWP'
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[Chromedriver] 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_.*18632
[Chromedriver]   (make sure the app has its WebView configured for debugging)
[Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64) [debug] [Chromedriver] UnknownError: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632
[debug] [Chromedriver]   (make sure the app has its WebView configured for debugging)
[debug] [Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
[debug] [Chromedriver]     at errorFromMJSONWPStatusCode (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@5.5.0@appium-base-driver\lib\protocol\errors.js:767:10)
[debug] [Chromedriver]     at ProxyRequestError.getActualError (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@5.5.0@appium-base-driver\lib\protocol\errors.js:661:14)
[debug] [Chromedriver]     at JWProxy.command (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@5.5.0@appium-base-driver\lib\jsonwp-proxy\proxy.js:264:19)
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632
[Chromedriver]   (make sure the app has its WebView configured for debugging)
[Chromedriver]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64) [debug] [W3C (1ecf7585)] Encountered internal error running command: Error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @webview_devtools_remote_.*18632
[debug] [W3C (1ecf7585)]   (make sure the app has its WebView configured for debugging)
[debug] [W3C (1ecf7585)]   (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
[debug] [W3C (1ecf7585)]     at Object.errorAndThrow (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-support@2.43.0@appium-support\lib\logging.js:87:35)
[debug] [W3C (1ecf7585)]     at Chromedriver.start (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-chromedriver@4.21.1@appium-chromedriver\lib\chromedriver.js:589:11)
[debug] [W3C (1ecf7585)]     at AndroidUiautomator2Driver.setupNewChromedriver (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-android-driver@4.27.0@appium-android-driver\lib\commands\context.js:429:3)
[debug] [W3C (1ecf7585)]     at AndroidUiautomator2Driver.startChromedriverProxy (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-android-driver@4.27.0@appium-android-driver\lib\commands\context.js:133:10)
[debug] [W3C (1ecf7585)]     at AndroidUiautomator2Driver.switchContext (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-android-driver@4.27.0@appium-android-driver\lib\commands\context.js:69:5)
[debug] [W3C (1ecf7585)]     at AndroidUiautomator2Driver.setContext (C:\Users\felix\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-android-driver@4.27.0@appium-android-driver\lib\commands\context.js:60:3)
[HTTP] <-- POST /wd/hub/session/1ecf7585-a1c3-4dd2-acf2-3660cce2e77f/context 500 3174 ms - 1315
[HTTP]

这个问题解决了吗?我换了N个版本的chromedriver,还是没有解决,看上去像是adb -P 5037 -s e1cedc89 forward --remove tcp:10902导致的