How to check element properties in iOS gui automation?

后端 未结 1 877
挽巷
挽巷 2021-01-01 03:16

All UI Automation examples I\'ve seen uses standard components whose state can be inspected with the JavaScript API using the value() method. This is a bit limi

相关标签:
1条回答
  • 2021-01-01 03:37

    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 讨论(0)
提交回复
热议问题