Appium 关于 webview 问题。请求帮助

ben · 2014年02月10日 · 最后由 一天边 回复于 2015年08月24日 · 1642 次阅读

背景: 小弟要测试一个 hybrid 类型的 app。apk 进来跳转到 webview,现在能够显示 webview 的内容,却不能进行测试操作。
手机是 Android 4.2.2,电脑是 windows。 代码如下:

DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability("device","Android");
     capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
 capabilities.setCapability(CapabilityType.VERSION, "4.2");
     capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
    capabilities.setCapability("app-package", "com.paic.mobileoa");
    capabilities.setCapability("app-activity", ".LoadingActivity");
     remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

 }
 @After
 public void tearDown() throws Exception {
     driver.quit();
 }
 @Test
 public void addContact(){
     try{
         Thread.sleep(20000);
     }catch(Exception e){
         e.printStackTrace();
     }
 remoteWebDriver.switchTo().window("WEBVIEW");
     remoteWebDriver.findElement(By.name("待处理文件")).click();
     remoteWebDriver.executeScript("mobile: leaveWebView");

报错信息:
报错说:
debug: Request received with params: {"name":"WEBVIEW"}
Responding to client that a method is not implemented 为什么啊??
同样的,我在手机上跑 sample 里面那个 AndroidContactsTest.java 就没有问题。

debug: Appium request initiated at /wd/hub/session/bd62b7a5-c2dd-4545-9f56-594957055823
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"platform":"WINDOWS","browserN
ame":"","version":"4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled"
:true,"databaseEnabled":false,"app-package":"com.paic.mobileoa","device":"Android","app-acti
vity":".LoadingActivity"},"sessionId":"bd62b7a5-c2dd-4545-9f56-594957055823"}
GET /wd/hub/session/bd62b7a5-c2dd-4545-9f56-594957055823 200 9ms - 388b
debug: Appium request initiated at /wd/hub/session/bd62b7a5-c2dd-4545-9f56-594957055823/wind
ow
debug: Request received with params: {"name":"WEBVIEW"}
info: Responding to client that a method is not implemented
POST /wd/hub/session/bd62b7a5-c2dd-4545-9f56-594957055823/window 501 15ms - 180b
共收到 25 条回复 时间 点赞
ben #1 · 2014年02月10日 Author

capabilities.setCapability("device","Android") 换成 capabilities.setCapability("device","Selendroid");
也是问题》

debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platform":"WINDOWS","browserNa
me":"","app-package":"com.paic.mobileoa","device":"selendroid","app-activity":".LoadingActiv
ity"}}
info: Got configuration error, not starting session
info: Cleaning up appium session
error: Failed to start an Appium session, err was: No app set; either start appium with --ap
p or pass in an 'app' value in desired capabilities
info: Responding to client with error: {"status":33,"value":{"message":"A new session could
not be created.","origValue":"No app set; either start appium with --app or pass in an 'app'
 value in desired capabilities"},"sessionId":null}
POST /wd/hub/session 500 8ms - 223b
ben #2 · 2014年02月10日 Author

#1 楼 @benlooking 改成 capabilities.setCapability("device","Selendroid");后根据
http://stackoverflow.com/questions/16619143/android-maven-could-not-find-tool-aapt 所说
修改 windows 版本的 mklink aapt.exe ..\build-tools\android-4.2.2\aapt.exe mklink /D lib ..\build-tools\android-4.2.2\lib mklink aidl.exe ..\build-tools\android-4.2.2\aidl.exe 也继续报错
Failed to start an Appium session, err was: Error: Could not find aapt in tools

@benlooking 看 log 很清楚嘛,你没设置 apk 的文件路径呀。。。

ben #4 · 2014年02月10日 Author

#3 楼 @luis 这是因为改成 capabilities.setCapability("device","Selendroid") 后的问题。后面加上了路径,报 err was: Error: Could not find aapt in tools。
之前第一次 Ok 了就把路径注释了的

ben #6 · 2014年02月10日 Author

#5 楼 @luis 恩。我看过这个帖子了,方法我也根据http://stackoverflow.com/questions/16619143/android-maven-could-not-find-tool-aapt所说改了还是有问题。晚上回去在研究研究

@benlooking 试试下载其他版本的 android SDK

ben #8 · 2014年02月11日 Author

#7 楼 @luis
Hi,我昨天试了下,用 Selendroid。加了 aapt.exe 等三个文件可以运行。可以却出现如下问题:
1..之前用"device","Android"时,第一次运行完后注释 app 的路径。之后会去手机里面找。但是在 selendroid 模式下会报 app 路径找不到的错。改回 Android,就可以。

error: Failed to start an Appium session, err was: No app set; either start appium with --ap
p or pass in an 'app' value in desired capabilities
info: Responding to client with error: {"status":33,"value":{"message":"A new session could
not be created.","origValue":"No app set; either start appium with --app or pass in an 'app'
 value in desired capabilities"},"sessionId":null}
POST /wd/hub/session 500 7ms - 223b

2.如果给 Selendroid 加上路径后运行报

debug: Request received with params: {"name":"WEBVIEW"}
debug: Proxying command to localhost:8080
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/6800894c-8
423-4018-b5b1-fa0a042e973c/window","method":"POST","json":{"name":"WEBVIEW"}}
debug: Proxied response received with status 500: undefined
POST /wd/hub/session/6800894c-8423-4018-b5b1-fa0a042e973c/window 500 5204ms

请问一下,appium 测试 webview 只能用 Selendroid 模式么。
谢谢~

#8 楼 @benlooking 不是啊 selendroid 是为了兼容 4.1 一下的吧?

ben #11 · 2014年02月11日 Author

#9 楼 @lihuazhang
我在https://groups.google.com/forum/#! topic/appium-discuss/vUIqIPdjxvc看到
Jonathan Lipps 说
If you want to use webviews, you need to use selendroid mode.所以想确认下。
大神求帮助啊,我的 webview 一直跑不起来。

#10 楼 @benlooking 哦 是嘛。。。。 那我不知道了诶。。。我回头帮你看看。

ben #12 · 2014年02月11日 Author

#11 楼 @lihuazhang 恩,谢谢。现在用 selendroid 不能注释路径。Android 又找不到元素。

@benlooking 要测试 hybrid app 必须使用 selendorid 模式,这种模式下 app 必须指定。

ben #14 · 2014年02月11日 Author

#13 楼 @luis 那每次都要重新安装 app 么?程序里有动态吗验证的那就不行了哦?

@benlooking appium 会有 check,动态验证码可以通过制定不同 activity 来跳过,或者开发阶段开个后门吧。。。

ben #17 · 2014年02月11日 Author

#15 楼 @luis
自动 check 么?就是没有后门开。。诶。。。
老大,有 selendroid 下能跑通的 demo 么。我这边无论怎样都不行,我拿过来研究研究

@benlooking 你现在只是动态验证码不知道如何处理还是什么?更新下你的问题。。。

ben #18 · 2014年02月12日 Author

#17 楼 @luis 老大,现在用 selendorid 模式测 webview,被测 app 有(动态验证码以及手机短信验证码),现在问题有
1。这种模式下页面元素获取不到(之前用过淘宝的 athrun 可以获取)

debug: Request received with params: {"using":"name","value":"提交"}
debug: Proxying command to localhost:8080
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/211af7fa-f
783-4437-93ed-0afa092ba21c/element","method":"POST","json":{"using":"name","value":"提交"}}
info: Responding to client with error: {"status":7,"value":{"message":"An element could not
be located on the page using the given search parameters.","origValue":"Element was not foun
d."},"sessionId":"211af7fa-f783-4437-93ed-0afa092ba21c"}
POST /wd/hub/session/211af7fa-f783-4437-93ed-0afa092ba21c/element 500 5105ms - 229b
debug: Appium request initiated at /wd/hub/session/211af7fa-f783-4437-93ed-0afa092ba21c

2。不知道怎么跳过动态码的验证。

@benlooking 元素定位不到很可能是对应的元素 locator 写的不对,建议把 html 源码放上,也建议用 xpaTh 定位不要用 name....至于验证码最简单的就是开后门,还有就是用代码识别验证码但难度很大,还有就是能否跳过验证码那一页面直接从下一页面的 activity 开始

ben #20 · 2014年02月17日 Author

#19 楼 @luis
在这个模式下奇怪的报错。。。。

File classpathRoot = new File(System.getProperty("user.dir"));
     File appDir = new File(classpathRoot, "../../../apps/meoa");
     File app = new File(appDir, "OldMeoa_debug.apk");
      DesiredCapabilities capabilities = new DesiredCapabilities();
     //capabilities.setCapability("device","Android");
      capabilities.setCapability("device","Selendroid");
      capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
      capabilities.setCapability(CapabilityType.VERSION, "4.0");
      capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
      capabilities.setCapability("app", app.getAbsolutePath());
      capabilities.setCapability("app-package", "com.paic.mobileoa");
      capabilities.setCapability("app-activity", ".LoadingActivity");
      URL url = new URL("http://127.0.0.1:4723/wd/hub");
     remoteWebDriver = new RemoteWebDriver(url, capabilities);
error: Failed to start an Appium session, err was: Error: Waited 20 secs for selendroid serv
er and it never showed up
info: Responding to client with error: {"status":33,"value":{"message":"A new session could
not be created. (Original error: Waited 20 secs for selendroid server and it never showed up
)","origValue":"Waited 20 secs for selendroid server and it never showed up"},"sessionId":nu
ll}
POST /wd/hub/session 500 39197ms - 268b

#19 楼 @luis 请问一个问题 selendroid 下 xpath 定位不到元素,一直很困扰我
代码:
puts @driver.find_element(:class,'android.widget.HorizontalScrollView')
puts @driver.find_element(:xpath,'//ImageButton')

@chuyaoyao 建议贴上元素 inspect 结构图

代码中的这段地址我一直不行,http://127.0.0.1:4723/wd/hub

代码中的这段地址我一直不行,http://127.0.0.1:4723/wd/hub,访问不了,执行到这里就执行不下去了,是怎么回事呢?求解哇!~~~~

我下载的这个 ContactManager.apk 手机上安装了也不能用呢 💀

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册