Robotium 请教下怎么修改 Robotium 的 RobotiumWebClient 使其支持安卓 app 里的 cordova 的 h5

Timothy · 2017年05月11日 · 最后由 心向东 回复于 2017年05月11日 · 1660 次阅读

公司的安卓 app,里面的 webview 有些是用安卓原生的 webview,有些是用了 cordova 的 webview,但 Robotium 不支持 cordova,会抛类转异常,因为 cordova 重写了 WebChromeClient,它也使用了自己的 webview。

我参照腾讯 TMQ 改造 X5 内核 h5 的方法对 robotium 改造,但在改写 cordova 遇到了困难。因为要让 RobotiumWebClient 继承自 SystemWebChromeClient,需要在 RobotiumWebClient 的构造方法里添加 super(SystemWebViewEngine),而 SystemWebViewEngine 的构造方法只有 SystemWebViewEngine(Context, CordovaPreferences) 或者 SystemWebViewEngine(SystemWebView) 两种。但这两种都不行,因为 new Solo 的时候,new 了 WebUtils,然后 new 了 RobotiumWebClient,而此时还没有 webview,app 会 crash。

请问有没有人能够帮忙解答,谢谢!

共收到 3 条回复 时间 点赞
心向东 回复

我集成了这个包,测试了下,还是不行。。
05-11 16:23:12.711: E/Throw UncaughtException(7768): java.lang.ClassCastException: com.robotium.solo.RobotiumWebClient cannot be cast to org.apache.cordova.engine.SystemWebChromeClient
05-11 16:23:12.711: E/Throw UncaughtException(7768): at org.apache.cordova.engine.SystemWebView.setWebChromeClient(SystemWebView.java:76)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at com.robotium.solo.RobotiumWebClient$1.run(RobotiumWebClient.java:84)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1904)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at android.os.Handler.handleCallback(Handler.java:739)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at android.os.Handler.dispatchMessage(Handler.java:95)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at android.os.Looper.loop(Looper.java:148)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at android.app.ActivityThread.main(ActivityThread.java:5432)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at java.lang.reflect.Method.invoke(Native Method)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735)
05-11 16:23:12.711: E/Throw UncaughtException(7768): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

你自己对照着 codova 的源码 自己调试下吧 codova 版本的 API 变动很大 ,找到你们用的版本自己反射注入吧

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