How to check element properties in iOS gui automation?

江枫思渺然 提交于 2019-11-30 10:05:48

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");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!