inkling/Subliminal

New selectors

KrauseFx opened this issue · 5 comments

Is there a reason why these selectors are not built in?

+ (instancetype)elementWithAccessibilityValue:(NSString *)value;
+ (instancetype)elementWithAccessibilityHint:(NSString *)hint;

Basically I implemented them like this:

return [self elementMatching:^BOOL(NSObject *obj) {
        return [obj.accessibilityValue isEqualToString:value];
    }
    withDescription:[@"Value: " stringByAppendingString:value]];

Am I missing something?

I guess I shouldn't be using the value or the hint to find elements.. is that the reason?

Subliminal just gives convenience wrappers for the most common selectors, which from my understanding of Apple's docs here (and also from looking at the attributes of standard UIKit controls) are labels, values, and traits.

SLElement's constructors are also structured/ordered to encourage developers to set/use labels, given Apple's recommendations.

But you can certainly use other criteria--and sometimes you need to do so, where labels aren't unique--and for these cases Subliminal provides -elementMatching:. You could match hints using something very similar to the code snippet you have above. You don't need to do that for value, though--you can just call +elementWithAccessibilityLabel:value:traits: with a nil label and SLUIAccessibilityTraitsAny for traits.

Thanks for the hint with the label.
It's your choice if you want those additional convenience methods in the library. I use them in a category right now.

I think you're right, every element should be accessible using the label.

I'm setting the hint to the english version of the label always. So I can run the tests in different languages well and still provide a valid and helpful accessibilityLabel for people who need it.
That's why I'm using this method.

Do you set the hint to the english version of the label even in production? That might be a bit confusing for your users. I think it might be a bit more appropriate to use the accessibilityIdentifier for such "debug" information--that's not shown to users. And then you could use +[SLElement elementWithAccessibilityIdentifier:].

I don't feel a need to add those convenience constructors to SLElement, so I'm going to close this, but please feel free to add additional comments.

No, those values are only set in Debug mode. I need the real language for the screenshots but english only for finding and accessing the elements.

👍