我在配置参数时新增了 automationName=uiautomator2,因为我们的这个 app 是 H5 和 toast 都有, 但是我新增这个参数后,switch to context("WEBVIEW") 就报错,我用的 Robotframework 导入的 AppiumLibrary 库。
这个是 RF 控制台的报错。

20170711 11:31:12.193 :  INFO : [u'NATIVE_APP', u'WEBVIEW_com.suixingpay.cashier']
20170711 11:31:17.995 :  INFO : NATIVE_APP
20170711 11:31:17.998 :  FAIL : 
NoSuchContextException: Message: No such context found.

下面是 appium 的报错

[AndroidDriver] Found webviews: ["WEBVIEW_com.suixingpay.cashier"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[HTTP] <-- GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/contexts 200 571 ms - 119 
[HTTP] --> GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/contexts {}
[MJSONWP] Calling AppiumDriver.getContexts() with args: ["ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[AndroidDriver] Getting a list of available webviews
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","cat","/proc/net/unix"]
[AndroidDriver] WEBVIEW_11279 mapped to pid 11279
[AndroidDriver] Getting process name for webview
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","ps"]
[AndroidDriver] Parsed pid: 11279 pkg: com.suixingpay.cashier!
[AndroidDriver] from: u0_a176,11279,236,1135300,114844,ffffffff,00000000,S,com.suixingpay.cashier
[AndroidDriver] returning process name: com.suixingpay.cashier
[AndroidDriver] Found webviews: ["WEBVIEW_com.suixingpay.cashier"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[HTTP] <-- GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/contexts 200 524 ms - 119 
[HTTP] --> POST /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context {"sessionId":"ea0d3be5-983f-4896-90cb-31acf1c13d23","name":"WEBVIEW"}
[MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW","ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[AndroidDriver] Getting a list of available webviews
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","cat","/proc/net/unix"]
[AndroidDriver] WEBVIEW_11279 mapped to pid 11279
[AndroidDriver] Getting process name for webview
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","ps"]
[AndroidDriver] Parsed pid: 11279 pkg: com.suixingpay.cashier!
[AndroidDriver] from: u0_a176,11279,236,1135300,114844,ffffffff,00000000,S,com.suixingpay.cashier
[AndroidDriver] returning process name: com.suixingpay.cashier
[AndroidDriver] Found webviews: ["WEBVIEW_com.suixingpay.cashier"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[HTTP] <-- POST /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context 500 549 ms - 109 
[HTTP] --> GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context {}
[MJSONWP] Calling AppiumDriver.getCurrentContext() with args: ["ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[MJSONWP] Responding to client with driver.getCurrentContext() result: "NATIVE_APP"
[HTTP] <-- GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context 200 1 ms - 84 
[HTTP] --> GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context {}
[MJSONWP] Calling AppiumDriver.getCurrentContext() with args: ["ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[MJSONWP] Responding to client with driver.getCurrentContext() result: "NATIVE_APP"
[HTTP] <-- GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context 200 2 ms - 84 
[HTTP] --> POST /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context {"sessionId":"ea0d3be5-983f-4896-90cb-31acf1c13d23","name":"NATIVE_APP"}
[MJSONWP] Calling AppiumDriver.setContext() with args: ["NATIVE_APP","ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[AndroidDriver] Getting a list of available webviews
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","cat","/proc/net/unix"]
[AndroidDriver] WEBVIEW_11279 mapped to pid 11279
[AndroidDriver] Getting process name for webview
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","ps"]
[AndroidDriver] Parsed pid: 11279 pkg: com.suixingpay.cashier!
[AndroidDriver] from: u0_a176,11279,236,1135300,114844,ffffffff,00000000,S,com.suixingpay.cashier
[AndroidDriver] returning process name: com.suixingpay.cashier
[AndroidDriver] Found webviews: ["WEBVIEW_com.suixingpay.cashier"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.suixingpay.cashier"]
[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/context 200 511 ms - 76 
[HTTP] --> GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/screenshot {}
[MJSONWP] Calling AppiumDriver.getScreenshot() with args: ["ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[ADB] Device API level: 19
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","/system/bin/rm","/data/local/tmp/screenshot.png;","/system/bin/screencap","-p","/data/local/tmp/screenshot.png"]
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","pull","/data/local/tmp/screenshot.png","C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\appium117611-9812-1qr7vv2.1h2v6rms4i.png"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","dumpsys","input"]
[MJSONWP] Responding to client with driver.getScreenshot() result: "iVBORw0KGgoAAAANSUhEUgAABDgAAAeACAYAAAArYecKAACAAElEQVR4AezBB2DW9Z348ffn8/09I8mTJzshm723gAiiiCi46qrz1FbvWu15pa3dtvbau161d23/PXu2Xocdrta6Jw4UURFBQPYmjISQCdnJs37/PnihCQYMSDDB7+sliWPPdLEsy7Isy7Isy7Isy+rDHPElYlmWZVmWZVmWZVmW1Zc5Yhwsy7Isy7Isy7Isy7L6Mgc1WJZlWZZlWZZlWZZl9WUOarAsy7Isy7Isy7Isy+rLHBHBsizLsizLsizLsiyrL3MQxbIsy7Isy7Isy7Isqy9zUMWyLMuyLMuyLMuyLKsvc0QVy7Isy7Isy7Isy7KsvsxBFMuyLMuyLMuyLMuyrL7MQQ2WZVmWZVmWZVmWZVl9mSOiWJZlWZZlWZZlWZZl9WUOqliWZVmWZX1SGVUGF/QjLyOVYFICfp+XSCRCQ3Mrlfvq2b6nkvrmFizLsizL6t0cVLEsy7Isy/qkGZibzafPnMzUUYMZUtCPfumpeBxDR5X769m+p5LV23bz1JvLWbx2Cy4ulmVZlmX1Po6IwbIsy7Is65MiNyOVeZefw5Uzp5AeDHAk2alBslODTB05mOvOmcaba7fwnw8/z/LNJeBi9UJZaUHmXXYO508dR2FWOh7H0JVwJMruqlpeeGcVdz/+CpW1dfRWWWlB5l12DudPHUdhVjoex9CVcCTK7qpaXnhnFXc//gqVtXVYlmV9kkjqRbe6WJZlWZZlfQJ8atp4/u3GSynOyeBYtYbC/Pyxl7n78ZdpaQtj9R6Th/fnoe/cQmZKgKNRU9/ENT/8Fcs27qC3mTy8Pw995xYyUwIcjZr6Jq754a9YtnEHlmVZnxSSevEXXSzLsizLsk5y8y49m+9cewFej8NH5QJPvLGCb/7mUarrGzlZ+DwOEwYXMbwol8F52QzMzaR/TgbpwQCJfi8Bv4+4xtY2mltD1DY0sWNvNdvLq9m6p5KNu8pZuXUXbeEI...
[HTTP] <-- GET /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23/screenshot 200 4714 ms - 57566 
[HTTP] --> DELETE /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23 {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["ea0d3be5-983f-4896-90cb-31acf1c13d23"]
[BaseDriver] Event 'quitSessionRequested' logged at 1499743878004 (11:31:18 GMT+0800 (中国标准时间))
[UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Deleting UiAutomator2 server session
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/ae3ad193-6fa2-4628-9919-75f90bb02253] with no body
[JSONWP Proxy] Got response with status 200: "{\"value\":\"Session deleted\",\"status\":0,\"sessionId\":\"ae3ad193-6fa2-4628-9919-75f90bb02253\"}"
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","shell","am","force-stop","com.suixingpay.cashier"]
[Logcat] Stopping logcat capture
[ADB] Removing forwarded port socket connection: 8200 
[ADB] Running 'E:\adt\adt-bundle\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Q8HUPJDIZDKZLNT4","forward","--remove","tcp:8200"]
[Appium] Removing session ea0d3be5-983f-4896-90cb-31acf1c13d23 from our master session list
[BaseDriver] Event 'quitSessionFinished' logged at 1499743879279 (11:31:19 GMT+0800 (中国标准时间))
[MJSONWP] Received response: null
[MJSONWP] But deleting session, so not returning
[MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/ea0d3be5-983f-4896-90cb-31acf1c13d23 200 1276 ms - 76 

我个人感觉是使用 automationName=uiautomator2 这个参数后,切换成了 uiautomator2 去识别控件了,但是无法识别 webview 所以会报这个错?
所以请教下各位我这样理解是否正确?有没有解决的办法?感谢各位


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