因为我的代码中有频繁的切换 Native 和 WebView 的操作,一般在切换 Native 的时候,没有任何问题,但是每次都会在切换成 Webview 时卡住,以下是日志:

info: <-- POST /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/element 200 36.275 ms - 88 {"status":0,"value":{"ELEMENT":"28"},"sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: --> POST /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/element/28/click {"id":"28"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"28"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"28"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: <-- POST /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/element/28/click 200 3132.665 ms - 76 {"status":0,"value":true,"sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: --> GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/appium/device/current_activity {}
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\dev_soft\android-sdks\platform-tools\adb.exe -s 4f62d22f shell "dumpsys window windows"
info: [debug] Responding to client with success: {"status":0,"value":".activity.MainActivity","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: <-- GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/appium/device/current_activity 200 132.476 ms - 96 {"status":0,"value":".activity.MainActivity","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: --> GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/context {}
info: [debug] Responding to client with success: {"status":0,"value":"NATIVE_APP","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: <-- GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/context 200 1.207 ms - 84 {"status":0,"value":"NATIVE_APP","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: --> GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/context {}
info: [debug] Responding to client with success: {"status":0,"value":"NATIVE_APP","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
info: <-- GET /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/context 200 1.770 ms - 84 {"status":0,"value":"NATIVE_APP","sessionId":"7c4d5563-abdc-422b-bd79-1a39109a01b5"}
[hupan] 2016-06-23 17:46:06,759 - com.at.appium.base.AppBase INFO   - Current content is NATIVE_APP, Now switch to WEBVIEW_com.hupan.app
info: --> POST /wd/hub/session/7c4d5563-abdc-422b-bd79-1a39109a01b5/context {"name":"WEBVIEW_com.hupan.app"}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: D:\dev_soft\android-sdks\platform-tools\adb.exe -s 4f62d22f shell "cat /proc/net/unix"
info: [debug] WEBVIEW_9375 mapped to pid 9375
info: [debug] Getting process name for webview
info: [debug] executing cmd: D:\dev_soft\android-sdks\platform-tools\adb.exe -s 4f62d22f shell "ps"
info: [debug] WEBVIEW_6631 mapped to pid 6631
info: [debug] Getting process name for webview
info: [debug] executing cmd: D:\dev_soft\android-sdks\platform-tools\adb.exe -s 4f62d22f shell "ps"
info: [debug] WEBVIEW_9309 mapped to pid 9309
info: [debug] Getting process name for webview
info: [debug] executing cmd: D:\dev_soft\android-sdks\platform-tools\adb.exe -s 4f62d22f shell "ps"
info: [debug] Parsed pid: 9375 pkg: com.hupan.app:TcmsService
info: [debug] from: u0_a143,9375,219,558860,44732,ffffffff,400b58b8,S,com.hupan.app:TcmsService
info: [debug] returning process name: com.hupan.app:TcmsService
info: [debug] Parsed pid: 6631 pkg: com.tencent.mobileqq
info: [debug] from: u0_a96,6631,219,643188,102544,ffffffff,400b58b8,S,com.tencent.mobileqq
info: [debug] returning process name: com.tencent.mobileqq
info: [debug] Parsed pid: 9309 pkg: com.hupan.app
info: [debug] from: u0_a143,9309,219,715504,90316,ffffffff,6245c3fa,R,com.hupan.app
info: [debug] returning process name: com.hupan.app
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.hupan.app:TcmsService,WEBVIEW_com.tencent.mobileqq,WEBVIEW_com.hupan.app
info: [debug] ["WEBVIEW_com.hupan.app:TcmsService","WEBVIEW_com.tencent.mobileqq","WEBVIEW_com.hupan.app"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.hupan.app:TcmsService,WEBVIEW_com.tencent.mobileqq,WEBVIEW_com.hupan.app
info: [debug] Connecting to chrome-backed webview
info: [debug] Found existing Chromedriver for context 'WEBVIEW_com.hupan.app'. Using it.
info: JSONWP Proxy: Proxying [GET /url] to [GET http://127.0.0.1:9515/wd/hub/session/c46338b3915a427b9c9167e64f9c44eb/url] with no body
info: [debug] Didn't get a new command in 300 secs, shutting down...
info: Shutting down appium session

每次会开在 info: JSONWP Proxy: Proxying [GET /url] to [GET http://127.0.0.1:9515/wd/hub/session/c46338b3915a427b9c9167e64f9c44eb/url] with no body 这一行,然后一直到超时退出,有没有大神遇到过这种问题:

public void switchContent(AndroidSrc androidSrc){
        if(androidSrc.getWebView().equals(WebViewType.NATIVE)&&driver.getContext().equals(AndroidWebView.HUPAN_WEBVIEW)){
            log.info("Current content is "+driver.getContext()+" , Now switch to "+AndroidWebView.NATIVE_WEBVIEW  );
            driver.context(AndroidWebView.NATIVE_WEBVIEW);
        }else if (androidSrc.getWebView().equals(WebViewType.WEBVIEW)&&driver.getContext().equals(AndroidWebView.NATIVE_WEBVIEW)){
            log.info("Current content is "+driver.getContext()+", Now switch to "+AndroidWebView.HUPAN_WEBVIEW);
            driver.context(AndroidWebView.HUPAN_WEBVIEW);
        }
    }

这是我切换 context 的代码


↙↙↙阅读原文可查看相关链接,并与作者交流