appium测试微信小程序切换context偶现chrome not reachable

  • 环境:macos
  • 移动端型号:VIVO X30
  • 移动端系统:android 10
  • 问题复述:appium测试微信小程序切换context时,频繁出现chrome not reachable, 频率1/2左右。
  • 开发语言:java

代码如下

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "10");
        capabilities.setCapability("appPackage", "com.tencent.mm");
        capabilities.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");
        capabilities.setCapability("automationName", "appium");
        capabilities.setCapability("deviceName", "0000020df6b06a4e");
        capabilities.setCapability("fastReset", false);
        capabilities.setCapability("fullReset", false);
        capabilities.setCapability("noReset", true);//启动app时不要清除app里的原有的数据
        capabilities.setCapability("recreateChromeDriverSessions", true);//支持X5内核应用自动化配置
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand0");
        String chromeDriverPath = "/Users/wbc/IdeaProjects/pagan-rpa/driver/86/chromedriver";
        File chromedriver = new File(chromeDriverPath);
        log.info(chromedriver.getAbsolutePath());
        capabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, chromedriver
            .getAbsolutePath());
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setBrowserName("");//初始化会默认将chrome浏览器打开,需要将Browser置为空
        capabilities.setCapability("unicodeKeyboard", true);//使用unicode输入法
        capabilities.setCapability("resetKeyboard", true);//重置输入法到初始状态
        capabilities.setCapability("sessionOverride", true);// 每次启动时覆盖session,否则第二次后运行会报错不能新建session
        capabilities.setBrowserName("");
        capabilities.setCapability("newCommandTimeout", "6000");
        //第三步:设置adb proxy
        //通过自己的adb代理修复chromedriver的bug并解决@xweb_devtools_remote的问题
        capabilities.setCapability("adbPort", "5038");
        //打印更多chromedriver的log方便定位问题
        //capabilities.setCapability("showChromedriverLog", true);
        //capabilities.setCapability("autoWebview", true);
        try {
            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElementByXPath("//*[@text='发现']").click();
        driver.findElementByXPath("//*[@text='小程序']").click();
        driver.findElementByXPath("//*[contains(@text, 'XXX')]").click();
        pause(5);
        Set<String> contextHandles = driver.getContextHandles();
        for (String contextHandle : contextHandles) {
            log.info(contextHandle);
        }
        pause(1);
        //切换到webview的content
        driver.context("WEBVIEW_com.tencent.mm:appbrand0");
        Set<String> windowHandles = driver.getWindowHandles();
        Map<String, String> windowHandleMap = new HashMap<>();
        for (String handle : windowHandles) {
            driver.switchTo().window(handle);
            log.info("切换窗口到" + handle);
            String pageSource = driver.getPageSource();
            if (pageSource.contains("帮助")) {
                driver.findElementByXPath("//*[@class='binding']/wx-view[1]").click();
                pause(5);
            }
        }

错误信息如下

io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: chrome not reachable
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'wbcdeMacBook-Pro.local', ip: 'fe80:0:0:0:23:ed42:9cab:48af%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_181'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbPort: 5038, appActivity: com.tencent.mm.ui.LauncherUI, appPackage: com.tencent.mm, automationName: appium, browserName: , chromedriverExecutable: /Users/wbc/IdeaProje..., databaseEnabled: false, desired: {adbPort: 5038, appActivity: com.tencent.mm.ui.LauncherUI, appPackage: com.tencent.mm, automationName: appium, browserName: , chromedriverExecutable: /Users/wbc/IdeaProje..., deviceName: 0000020df6b06a4e, fastReset: false, fullReset: false, goog:chromeOptions: {androidProcess: com.tencent.mm:appbrand0, args: [], extensions: []}, newCommandTimeout: 6000, noReset: true, platformName: android, platformVersion: 10, recreateChromeDriverSessions: true, resetKeyboard: true, sessionOverride: true, unicodeKeyboard: true}, deviceApiLevel: 29, deviceManufacturer: vivo, deviceModel: V1938CT, deviceName: 0000020df6b06a4e, deviceScreenDensity: 480, deviceScreenSize: 1080x2400, deviceUDID: 0000020df6b06a4e, fastReset: false, fullReset: false, goog:chromeOptions: {androidProcess: com.tencent.mm:appbrand0, args: [], extensions: []}, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 6000, noReset: true, pixelRatio: 3, platform: LINUX, platformName: Android, platformVersion: 10, recreateChromeDriverSessions: true, resetKeyboard: true, sessionOverride: true, statBarHeight: 108, takesScreenshot: true, unicodeKeyboard: true, viewportRect: {height: 2202, left: 0, top: 108, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 407b01c5-5c88-44f7-90eb-57f862037703
	at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:201)
	at test.WeixinDemo.switchContext(WeixinDemo.java:104)
	at test.WeixinDemo.testAppium(WeixinDemo.java:82)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: chrome not reachable
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'wbcdeMacBook-Pro.local', ip: 'fe80:0:0:0:23:ed42:9cab:48af%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_181'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbPort: 5038, appActivity: com.tencent.mm.ui.LauncherUI, appPackage: com.tencent.mm, automationName: appium, browserName: , chromedriverExecutable: /Users/wbc/IdeaProje..., databaseEnabled: false, desired: {adbPort: 5038, appActivity: com.tencent.mm.ui.LauncherUI, appPackage: com.tencent.mm, automationName: appium, browserName: , chromedriverExecutable: /Users/wbc/IdeaProje..., deviceName: 0000020df6b06a4e, fastReset: false, fullReset: false, goog:chromeOptions: {androidProcess: com.tencent.mm:appbrand0, args: [], extensions: []}, newCommandTimeout: 6000, noReset: true, platformName: android, platformVersion: 10, recreateChromeDriverSessions: true, resetKeyboard: true, sessionOverride: true, unicodeKeyboard: true}, deviceApiLevel: 29, deviceManufacturer: vivo, deviceModel: V1938CT, deviceName: 0000020df6b06a4e, deviceScreenDensity: 480, deviceScreenSize: 1080x2400, deviceUDID: 0000020df6b06a4e, fastReset: false, fullReset: false, goog:chromeOptions: {androidProcess: com.tencent.mm:appbrand0, args: [], extensions: []}, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 6000, noReset: true, pixelRatio: 3, platform: LINUX, platformName: Android, platformVersion: 10, recreateChromeDriverSessions: true, resetKeyboard: true, sessionOverride: true, statBarHeight: 108, takesScreenshot: true, unicodeKeyboard: true, viewportRect: {height: 2202, left: 0, top: 108, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 407b01c5-5c88-44f7-90eb-57f862037703
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
	at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:198)
	... 26 more

appium日志如下

[HTTP] --> POST /wd/hub/session/407b01c5-5c88-44f7-90eb-57f862037703/context
[HTTP] {"name":"WEBVIEW_com.tencent.mm:appbrand0"}
[W3C (407b01c5)] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.tencent.mm:appbrand0","407b01c5-5c88-44f7-90eb-57f862037703"]
[AndroidDriver] Getting a list of available webviews
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e shell cat /proc/net/unix'
[AndroidDriver] Parsed 2 active devtools sockets: ["@xweb_devtools_remote_8348","@xweb_devtools_remote_9589"]
[AndroidDriver] Collecting CDP data of 2 webviews
[AndroidDriver] Forwarding remote port xweb_devtools_remote_8348 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[AndroidDriver] Forwarding remote port xweb_devtools_remote_9589 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e forward tcp:10900 localabstract:xweb_devtools_remote_8348'
[ADB] Removing forwarded port socket connection: 10900 
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e forward --remove tcp:10900'
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e forward tcp:10900 localabstract:xweb_devtools_remote_9589'
[ADB] Removing forwarded port socket connection: 10900 
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e forward --remove tcp:10900'
[AndroidDriver] CDP data collection completed
[AndroidDriver] WEBVIEW_8348 mapped to pid 8348
[AndroidDriver] Getting process name for webview 'WEBVIEW_8348'
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm:appbrand0'
[AndroidDriver] WEBVIEW_9589 mapped to pid 9589
[AndroidDriver] Getting process name for webview 'WEBVIEW_9589'
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm:appbrand2'
[AndroidDriver] Found 2 webviews: ["WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm:appbrand2"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm:appbrand2"]
[AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:appbrand0'
[AndroidDriver] A port was not given, using random free port: 8000
[AndroidDriver] Passing web view details to the Chromedriver constructor: {
[AndroidDriver]   "info": {
[AndroidDriver]     "Android-Package": "com.tencent.mm",
[AndroidDriver]     "Browser": "Chrome/86.0.4240.99",
[AndroidDriver]     "Protocol-Version": "1.3",
[AndroidDriver]     "User-Agent": "Mozilla/5.0 (Linux; Android 10; V1938CT Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 XWEB/3209 MMWEBSDK/20220204 Mobile Safari/537.36",
[AndroidDriver]     "V8-Version": "8.6.395.13",
[AndroidDriver]     "WebKit-Version": "537.36 (@002668237e13d38aabd6d11c2d216dd22b736ff2)",
[AndroidDriver]     "webSocketDebuggerUrl": "ws://127.0.0.1:10900/devtools/browser"
[AndroidDriver]   },
[AndroidDriver]   "process": {
[AndroidDriver]     "name": "com.tencent.mm:appbrand0",
[AndroidDriver]     "id": "8348"
[AndroidDriver]   }
[AndroidDriver] }
[AndroidDriver] Merging 'goog:chromeOptions' into 'chromeOptions'. This may cause unexpected behavior
[AndroidDriver] Precalculated Chromedriver capabilities: {
[AndroidDriver]   "androidPackage": "com.tencent.mm",
[AndroidDriver]   "androidUseRunningApp": true,
[AndroidDriver]   "androidProcess": "com.tencent.mm:appbrand0",
[AndroidDriver]   "androidDeviceSerial": "0000020df6b06a4e"
[AndroidDriver] }
[AndroidDriver] The following Chromedriver capabilities cannot be overridden by the provided chromeOptions:
[AndroidDriver]   androidProcess ("com.tencent.mm:appbrand0")
[AndroidDriver] Before starting chromedriver, androidPackage is 'com.tencent.mm'
[Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: /Users/wbc/IdeaProjects/pagan-rpa/driver/86/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Users/wbc/IdeaProjects/pagan-rpa/driver/86/chromedriver.*--port=8000"
[Chromedriver] No old chromedrivers seem to exist
[Chromedriver] Cleaning this device's adb forwarded port socket connections: 0000020df6b06a4e
[ADB] List forwarding ports
[ADB] Running '/Users/wbc/Library/Android/sdk/platform-tools/adb -P 5038 -s 0000020df6b06a4e forward --list'
[Chromedriver] Spawning chromedriver with: /Users/wbc/IdeaProjects/pagan-rpa/driver/86/chromedriver --url-base=wd/hub --port=8000 --adb-port=5038 --verbose
[Chromedriver] Chromedriver version: '86.0.4240.22'
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8000
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[WD Proxy] Got response with status 200: {"value":{"build":{"version":"86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})"},"message":"ChromeDriver ready for new sessions.","os":{"arch":"x86_64","name":"Mac OS X","version":"10.13.6"},"ready":true}}
[Chromedriver] Starting W3C Chromedriver session with capabilities: {
[Chromedriver]   "capabilities": {
[Chromedriver]     "alwaysMatch": {
[Chromedriver]       "goog:chromeOptions": {
[Chromedriver]         "androidPackage": "com.tencent.mm",
[Chromedriver]         "androidUseRunningApp": true,
[Chromedriver]         "androidProcess": "com.tencent.mm:appbrand0",
[Chromedriver]         "androidDeviceSerial": "0000020df6b06a4e",
[Chromedriver]         "args": [],
[Chromedriver]         "extensions": []
[Chromedriver]       },
[Chromedriver]       "goog:loggingPrefs": {
[Chromedriver]         "browser": "ALL"
[Chromedriver]       }
[Chromedriver]     }
[Chromedriver]   }
[Chromedriver] }
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"capabilities":{"alwaysMatch":{"goog:chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:appbrand0","androidDeviceSerial":"0000020df6b06a4e","args":[],"extensions":[]},"goog:loggingPrefs":{"browser":"ALL"}}}}
[WD Proxy] Got response with status 500: {"value":{"error":"chrome not reachable","message":"chrome not reachable","stacktrace":"0   chromedriver                        0x0000000104fc0c29 chromedriver + 2464809\n1   chromedriver                        0x00000001055fb6f3 chromedriver + 8996595\n2   chromedriver                        0x0000000104e05bc6 chromedriver + 650182\n3   chromedriver                        0x0000000104df59df chromedriver + 584159\n4   chromedriver                        0x0000000104d7f9a9 chromedriver + 100777\n5   chromedriver                        0x0000000104d79aa0 chromedriver + 76448\n6   chromedriver                        0x0000000104dab326 chromedriver + 279334\n7   chromedriver                        0x0000000104da83f3 chromedriver + 267251\n8   chromedriver                        0x0000000104d82230 chromedriver + 111152\n9   chromedriver                        0x0000000104d831a7 chromedriver + 115111\n10  chromedriver                        0x0000000104f93830 chromedriver + 2279472\n11  chromedriver             ...
[W3C] Matched W3C error code 'chrome not reachable' to UnknownError
[Chromedriver] UnknownError: An unknown server-side error occurred while processing the command. Original error: chrome not reachable
[Chromedriver]     at errorFromW3CJsonCode (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:785:23)
[Chromedriver]     at ProxyRequestError.getActualError (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
[Chromedriver]     at JWProxy.command (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
[Chromedriver]     at processTicksAndRejections (internal/process/task_queues.js:85:5)
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[Chromedriver] Changed state to 'stopped'
[Chromedriver] An unknown server-side error occurred while processing the command. Original error: chrome not reachable
[W3C (407b01c5)] Encountered internal error running command: Error: An unknown server-side error occurred while processing the command. Original error: chrome not reachable
[W3C (407b01c5)]     at Object.errorAndThrow (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:94:35)
[W3C (407b01c5)]     at Chromedriver.start (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:541:11)
[W3C (407b01c5)]     at AndroidUiautomator2Driver.setupNewChromedriver (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:472:3)
[W3C (407b01c5)]     at AndroidUiautomator2Driver.startChromedriverProxy (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:221:10)
[W3C (407b01c5)]     at AndroidUiautomator2Driver.switchContext (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:128:5)
[W3C (407b01c5)]     at AndroidUiautomator2Driver.setContext (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:54:3)
[HTTP] <-- POST /wd/hub/session/407b01c5-5c88-44f7-90eb-57f862037703/context 500 61426 ms - 793

我课上讲到这块了吧 用学院提供的上mock工具处理下

是abd.py吗 这个已经加上了,的确能访问到,但是偶现的 [chrome not reachable]

我用的mock脚本是这个

"""
mitmdump -p 5038 --rawtcp --mode reverse:http://localhost:5037/ -s adb.py
"""
from mitmproxy.utils import strutils
from mitmproxy import ctx
from mitmproxy import tcp

def tcp_message(flow: tcp.TCPFlow):
    message = flow.messages[-1]
    old_content = message.content
    #message.content = old_content.replace(b"foo", b"bar")
    message.content = old_content.replace(b"@webview_devtools_remote_", b"@.*.*.*._devtools_remote_")

    ctx.log.info(
        "[tcp_message{}] from {} to {}:\n{}".format(
            " (modified)" if message.content != old_content else "",
            "client" if message.from_client else "server",
            "server" if message.from_client else "client",
            strutils.bytes_to_escaped_str(message.content))
    )

这个是老版的,试试这个

谢谢大佬,这个脚本用了以后调通了,但是过了一天以后,继续调试切换context出现了一个新问题,上下文列表能打印出来,切换报错,Failed to get sockets matching: @weblayer_devtools_remote_.*7518

io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @weblayer_devtools_remote_.*7518
  (make sure the app has its WebView/WebLayer configured for debugging)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'wbcdeMacBook-Pro.local', ip: 'fe80:0:0:0:14e9:501c:523f:d0c9%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_181'

你好,请问这个问题解决了吗?

同问,后面解决了吗

关闭