anandmeher / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

WebView testing in Android 4.4 limited, WebChromeClient not found. #585

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create a WebView based application.
2.Add a custom WebChromeClient that overrides onJsAlert.
3.Insert a webpage with a button that does an alert.
4 Create a robotium test that clicks on the button in the webview.

What is the expected output? What do you see instead?
Expected: An alert.
Actual: No alert.

What version of the product are you using? On what operating system?
Robotium 5.0.1 on OSX.

Please provide any additional information below.

The code in WebUtils, member getCurrentWebChromeClient fails to find the 
current Chrome client, so
originalWebChromeClient is null.
The onJsAlert in RobotiumWebClient then does nothng.

Side note: It would be better if the members that use originalWebChromeClient 
returned false in the case where it is null, that way I would at least see an 
alert, even of my own onJsAlert was not called.  Now it just silently fails, no 
exception or logging.

To find the chrome client on Android 4.4, this modification works:

--- a/robotium-solo/src/main/java/com/robotium/solo/WebUtils.java
+++ b/robotium-solo/src/main/java/com/robotium/solo/WebUtils.java
@@ -170,10 +170,16 @@ class WebUtils {
                        }catch(IllegalArgumentException ignored) {}
                }

-               try{
-                       Object mCallbackProxy = new 
Reflect(currentWebView).field("mCallbackProxy").out(Object.class);
-                       currentWebChromeClient = new 
Reflect(mCallbackProxy).field("mWebChromeClient").out(WebChromeClient.class);
-               }catch(Exception ignored){}
+        try{
+            if (android.os.Build.VERSION.SDK_INT >= 19) {
+                Object mClientAdapter = new 
Reflect(currentWebView).field("mContentsClientAdapter").out(Object.class);
+                currentWebChromeClient = new 
Reflect(mClientAdapter).field("mWebChromeClient").out(WebChromeClient.class);
+            }
+            else {
+                Object mCallbackProxy = new 
Reflect(currentWebView).field("mCallbackProxy").out(Object.class);
+                currentWebChromeClient = new 
Reflect(mCallbackProxy).field("mWebChromeClient").out(WebChromeClient.class);
+            }
+        }catch(Exception ignored){}

                return currentWebChromeClient;
        }

Original issue reported on code.google.com by jhdi...@gmail.com on 6 Mar 2014 at 10:52

GoogleCodeExporter commented 9 years ago
Thanks a lot for reporting this and contributing code. It will be included in 
the next release. 

Original comment by renasr...@gmail.com on 6 Mar 2014 at 7:43

GoogleCodeExporter commented 9 years ago
Thanks again for reporting this. This has been fixed in 5.1. 

Original comment by renasr...@gmail.com on 17 Mar 2014 at 6:09

GoogleCodeExporter commented 9 years ago

Original comment by renasr...@gmail.com on 17 Mar 2014 at 6:09