Skip to Content
Author's profile photo Fu-qiang Lv

How to update Selendroid framework to support Cordova 3.6.x or above

Selendroid is a test automation framework which drives off the UI of Android native and hybrid applications (apps) and the mobile web. Tests are written using the Selenium 2 client API – that’s it!

Selendroid: Selenium for Android  

When try to automation Cordova app(cordova 3.6.x or above) with Selendroid, it failed with error ClassCastException. The root cause of this issue is the cordova has changed some code for webview. It will convert the WebviewClient to CordovaWebViewClient, so when Selendroid try to set the WebViewClient to Webview, it will throw exception and crashed.

The code in CordovaWebView:

    public void setWebViewClient(WebViewClient client) {
        this.viewClient = (CordovaWebViewClient)client;
    public void setWebChromeClient(WebChromeClient client) {
        this.chromeClient = (CordovaChromeClient)client;

I found a workaround for this issue. I tried to build the selendroid-server to use CordovaChromeClient and override onJsAlert instead of SelendroidWebChromeClient.

First, create a new class and extends CordovaChromeClient. In this class override onJsAlert with SelendroidWebChromeClient’s onJsAlert method.

for example:

public class SelfWebChromeClient extends CordovaChromeClient{
     public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
             //code copied from SelendroidWebDriver

Then check the view type, if it is Cordova web view, create a new SelfWebChromeClient:

if (view instanceof CordovaWebView) {
     chromeClient = new SelfWebChromeClient();
} else {
     chromeClient = new SelendroidWebChromeClient();

Before build the Selendroid library, you need to add the Cordova library to maven local repository, then add the cordova library to the project as a runtime dependency.

How to add jar to maven local repository: Maven – Guide to installing 3rd party JARs

mvn install:install-file -Dfile=path-to-your-artifact-jar \

       -DgroupId=your.groupId \

       -DartifactId=your-artifactId \

       -Dversion=version \


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.