如何使用calabash iOS从源代码中获取价值

时间:2013-09-25 05:32:22

标签: ios calabash

我正在使用葫芦黄瓜来测试我的IOS应用程序。问题是进行验证和其他一些操作。我需要从源代码中获取价值。可能吗?如果是这样,怎么样?请帮我。我已经阅读了不同的文件,但我没有得到正确的答案。提前谢谢。

2 个答案:

答案 0 :(得分:1)

您可以使用calabash-ios query语言调用UIView及其子类上的选择器。

如果你对calabash-ios有任何经验,你可能在没有意识到的情况下使用了这个功能。

# calls the 'text' selector on the labels that match the query
query("label marked:'product description'", :text)

要查看是否启用了按钮,您可以执行以下操作:

# NB the property is 'enabled', but the selector is 'isEnabled
query("button marked:'ask for help'", :isEnabled")

这在calabash-ios wiki上有描述:

https://github.com/calabash/calabash-ios/wiki/03.5-Calabash-iOS-Ruby-API https://github.com/calabash/calabash-ios/wiki/05-Query-syntax

答案 1 :(得分:1)

如果你想设置自定义属性,那么一种方法是子类化UI元素(例如UIButton,然后你可以创建一个属性,然后你可以这样访问:

ExampleButton.h:

@interface ExampleButton : UIButton
{
  BOOL doingSomething;
}

@property (nonatomic) BOOL isDoingSomething;

ExampleButton.m

#import "ExampleButton.h"

@implementation ExampleButton

... //code possibly here

- (BOOL)isDoingSomething
{
  return doingSomething;
}

... //more code possibley here

然后你会有其他代码设置做什么。

顺便说一句,我刚刚开始在iOS和Calabash测试中,所以我的目标C生锈了,但我认为你也没有doingSomething Bool而只有@synthesize isDoingSomething然后,您可以直接在该属性上进行设置(self.isDoingSomething = true;等)。

在calabash中,您的查询将如下所示:

query("view:'ExampleButton' isDoingSomething:1") 

query("view:'ExampleButton' isDoingSomething:0")

分别查看属性是真还是假。

这可能不是唯一的方法(它可能不是最简单的方法,但它有效)。