开发者

How to check element properties in iOS gui automation?

All UI Automation examples I've seen uses standard components whose state can be in开发者_StackOverflowspected with the JavaScript API using the value() method. This is a bit limiting. Lets say you want to check the color or alpha value and whatnot.

How can I inspect the properties of a view?

An example: a tap on a certain element should make it "selected". I'd like to perform a tap on it and then verify that isSelected is TRUE.

Update:

I found the withPredicate() method which should do it in theory, except it seems to only trigger on name properties:

element.withPredicate("isSelected == YES")          // always fails
element.withPredicate("name matches 'my element'")  // works


I ended up with this approach which works for my purposes:

Let UIView.accessibilityValue return a JSON string with relevant properties:

- (NSString *)accessibilityValue
{
    return [NSString stringWithFormat:
            @"{'alpha':%f, 'isSelected':%@}", 
            self.alpha, self.isSelected ? @"true" : @"false"];
}

Then use eval() in the test code and check those properties. value() is shorthand for calling accessibilityValue:

var props = eval("(" + element.value() + ")");

if (props.isSelected) {
    UIALogger.logFail("Should not be selected");
}

UIATarget.localTarget().tap({"x":471, "y":337});

var props = eval("(" + element.value() + ")");

if (!props.isSelected) {
    UIALogger.logFail("Should be selected");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜