Appium - 在上下文中找到现有的chromedriver;使用它

问题描述:

我正在尝试自动化混合应用程序,我在其中不断切换Web和本机视图。Appium - 在上下文中找到现有的chromedriver;使用它

我使用的功能

public void switchToWebContext() throws InterruptedException { 
    Set<String> contextNames = appiumDriver.getContextHandles(); 
    for (String context : contextNames) { 
     System.out.println("Context is" + context); 
     if (context.contains("WEBVIEW")) { 
      getAppiumWebDriver().context(context); 
      displayLog("Mobile Web View switched"); 
     } 
    } 
} 

public void switchToNativeContext() { 
    Set<String> contextNames = getAppiumWebDriver().getContextHandles(); 
    for (String context : contextNames) { 
     if (context.contains("NATIVE")) { 
      displayLog("Native View found"); 
      getAppiumWebDriver().context(context); 
     } 
    } 

} 

我在这里的问题是,在第一次的导航需要流量正常,但在第二轮我得到这个错误

Found existing chromedriver for context 

我等待后几分钟我得到的错误是

[debug] [JSONWP Proxy] Proxying [GET /url] to [GET http://127.0.0.1:8000/wd/hub/session/ad84071a45fc33c30541cc85681dab7b/url] with no body 
[debug] [AndroidDriver] ChromeDriver is not associated with a window. Re-initializing the session. 
[Chromedriver] Restarting chromedriver 
[debug] [Chromedriver] Changed state to 'restarting' 
[debug] [JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8000/wd/hub/session/ad84071a45fc33c30541cc85681dab7b] with no body 

有人可以帮我解决这个问题吗?有没有什么办法中,我可以使用现有的上下文或存储它以某种方式以备将来使用

我会哄Appium 1.6.5在Windows 10

你不需要WEB_VEIW和本地之间切换。最新的uiAutomator内置了对这两种视图的支持。只需从PlayStore更新设备的“Android System WebView”并更新您的Android SDK即可。你的代码应该在VIEW之间切换而不用切换。