Search code examples
androidcalabash

Calabash testing Android, using back door. Method not found


When running my Calabash test I have a backdoor method in android that I'm trying to invoke.

The back door method is in the Application subclass as suggested in the calabash-android docs.

https://developer.xamarin.com/guides/testcloud/calabash/working-with/backdoors/

But I get the following error:

Error: {"result"=>"No such method found: setTestToken:([String])", "outcome"=>"ERROR", "details"=>"{receiverClass=com.test.mobile.ui.MainActivity, error=No such method found: setTestToken:([String]), receiverString=com.test.mobile.ui.MainActivity@577ecb1, methodName=setTestToken:}"}

MainActivity is the current activity.

How do I get Calabash to execute the method in the Application subclass rather than trying to access the current Activity?

An answer in another question suggested calling these commands here are the commands and outputs.

query("* index:0"):

"class" => "com.android.internal.policy.PhoneWindow$DecorView",

 query("* index:0", :getContext, :toString)

com.test.mobile.ui.MainActivity@577ecb1

query("* index:0", :getContext, :getApplicationContext, :toString)

com.test.mobile.TestApplication@577ac49

Also the method looks like this:

public String setTestToken(String token) {
    if (DEBUG) {
        DefaultPreferences.getInstance().edit().putTestToken(token).commit();
    Logger.d(TAG, "Test token set: " + token);

    //This is a return for Calabash so that it knows the token has been set.
    return DefaultPreferences.getInstance().getTestToken();
    }
    Logger.d(TAG, "Test token not set");

    //This is a return for Calabash so that it knows the token has not been set.
    return null;
}

The call from calabash looks like this:

backdoor('setTestToken:', token)

Solution

  • iOS calls the backdoor like this:

    backdoor('setTestToken:', token)
    

    Android calls the backdoor like this:

    backdoor('setTestToken', token)
    

    Removing the colon solved the problem for Android.

    iOS requires the colon.