在resetApp之后切换到webview上下文会出现异常“chrome not reachable”

问题描述 投票:0回答:1

环境

Appium : 1.6.4
OS : Ubuntu 16.04 64bit
Node.js : 7.9.0
Android : 5.1
Device :1501-M02
API :java
Appium CLI

细节

我使用spock作为测试框架,带有代码:

class Test{
      AndroidDriver<RemoteWebElement> driver;
      DesiredCapabilities cap=DesiredCapabilities.android();
       ........
      def setup(){
            //setup driver
              .....
             cap.setCapability(NO_RESET, "true");
         cap.setCapability(FULL_RESET, "false");
          .....
             cap.setCapability(RECREATE_CHROME_DRIVER_SESSIONS, "true");
             .......
             driver.context("WEBVIEW_com.domain.pkg");
      }

      def "test1"(){}

      def "test2"(){}

      def cleanup(){
             driver.resetApp();
      }
}

在eclipse中,如果右键单击test1或test2->运行as-> junit test,两者都按预期运行,但如果右键单击Test(类) - >运行as-> junit test,第一个测试工作,第二个测试会抛出异常:

  org.openqa.selenium.WebDriverException: chrome not reachable
  (Session info: webview=39.0.0.0)
  (Driver info: chromedriver=2.28.455506 

如果用这个替换cleanup():

def cleanup(){driver.quit(); }

一切都按预期工作,但每次测试都会重新初始化很多浪费大量时间的员工,所以

driver.resetApp()

没有按预期工作,这是一个错误还是我做错了什么?

像这样的appium日志:

[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","MB8DW44999999999","shell","am","force-stop","com.vsi.pd.doctor"]
[debug] [MJSONWP] Responding to client with driver.closeApp() result: null
[HTTP] <-- POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/appium/app/close 200 1099 ms - 76 
[HTTP] --> POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/appium/app/launch {}
[debug] [MJSONWP] Calling AppiumDriver.launchApp() with args: ["ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2"]
[AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [ADB] Device API level: 22
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","MB8DW44999999999","shell","am","start","-W","-n","com.vsi.pd.doctor/.MainActivity","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [MJSONWP] Responding to client with driver.launchApp() result: null
[HTTP] <-- POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/appium/app/launch 200 1987 ms - 76 
[HTTP] --> POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/context {"name":"WEBVIEW_com.vsi.pd.doctor"}
[debug] [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.vsi.pd.doctor","ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","MB8DW44999999999","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_17929 mapped to pid 17929
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","MB8DW44999999999","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 17929 pkg: com.vsi.pd.doctor!
[debug] [AndroidDriver] from: u0_a181,17929,274,1666480,109536,ffffffff,00000000,S,com.vsi.pd.doctor
[debug] [AndroidDriver] returning process name: com.vsi.pd.doctor
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.vsi.pd.doctor"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.vsi.pd.doctor"]
[debug] [MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/context 200 117 ms - 76 
[HTTP] --> POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/element {"using":"id","value":"login"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/element] to [POST http://127.0.0.1:8000/wd/hub/session/eb87d1b86ef6331102013b50ee2c0ea4/element] with body: {"using":"id","value":"login"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"eb87d1b86ef6331102013b50ee2c0ea4","status":100,"value":{"message":**"chrome not reachable**\n  (Session info: webview=39.0.0.0)\n  (Driver info: chromedriver=2.28.455506 (18f6627e265f442aeec9b6661a49fe819aeeea1f),platform=Linux 4.4.0-75-generic x86_64)"}}
[JSONWP Proxy] Replacing sessionId eb87d1b86ef6331102013b50ee2c0ea4 with ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2
[HTTP] <-- POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/element 200 13 ms - 269 
[HTTP] --> POST /wd/hub/session/ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2/appium/app/close {}
[debug] [MJSONWP] Calling AppiumDriver.closeApp() with args: ["ebe4a8b1-844c-49f3-9997-9bc1bc0dd8a2"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","MB8DW44999999999","shell","am","force-stop","com.vsi.pd.doctor"]
[debug] [MJSONWP] Responding to client with driver.closeApp() result: null
google-chrome appium
1个回答
0
投票

使用新的UIautomator,您无需将驱动程序切换到webview。它内置了识别webView内部元素的功能。

请更新您的Android SDK一次。

WebView中的元素将在UIAutomator for Android Version 6.0+版本中可见。但是,一旦为Android 6.0+设备自动执行脚本,就可以对6.0以下的Android版本使用相同的脚本。

此外,您还可以使用UIAutomator在Android 6.0+设备上查看webView中的元素。

© www.soinside.com 2019 - 2024. All rights reserved.