google / EarlGrey

:tea: iOS UI Automation Test Framework
http://google.github.io/EarlGrey/
Apache License 2.0
5.62k stars 742 forks source link

matcherForEnabledElement is treating nil elements as enabled #479

Open RichardGuion opened 7 years ago

RichardGuion commented 7 years ago

When using grey_enabled in a test I noticed that any text I used did not assert

        EarlGrey.select(elementWithMatcher:
            allOf(withText("bar"),
                  withAncestor(allOf(withClass(MyClass.self), isVisible())))).assert(grey_enabled())

This is a case where "bar" did not exist at all and I was expecting an assertion thrown.

The answer is here: https://github.com/google/EarlGrey/blob/b0ed5e03fb2b5a5ba00843811c9e87baa547bf6b/EarlGrey/Matcher/GREYMatchers.m#L476

The default value of BOOL matched should be NO instead of YES.

khandpur commented 7 years ago

Note that the returned matcher should also contain a isKindOfClass matcher for UIControl class types:

return grey_allOf(grey_kindOfClass([UIControl class]), isEnabledMatcher, grey_not(grey_ancestor(grey_not(isEnabledMatcher))), nil);
khandpur commented 7 years ago

@RichardGuion would you like to take a stab at it?