使用后门测试Android的Calabash。找不到方法

时间:2016-10-25 16:37:39

标签: android calabash

当我运行我的Calabash测试时,我在android中有一个我试图调用的后门方法。

后门方法在calabash-android文档中建议的Application子类中。

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

但是我收到以下错误:

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是当前的活动。

如何让Calabash在Application子类中执行该方法而不是尝试访问当前的Activity?

另一个问题的答案建议在这里调用这些命令是命令和输出。

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

此方法也是如此:

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;
}

来自葫芦的电话如下:

backdoor('setTestToken:', token)

1 个答案:

答案 0 :(得分:0)

iOS会像这样调用后门:

backdoor('setTestToken:', token)

Android会像这样调用后门:

backdoor('setTestToken', token)

删除冒号解决了Android的问题。

iOS需要冒号。