Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose EarlGrey's matcherForInteractable #668

Closed

Conversation

kkhaidukov
Copy link
Contributor

Will expose EarlGrey's matcherForInteractable in by for iOS.

@kkhaidukov kkhaidukov requested a review from rotemmiz as a code owner April 11, 2018 11:13
Copy link
Contributor

@rotemmiz rotemmiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kkhaidukov,

Thanks for the contribution! In order for this to be merged please add test to the E2E suite, so we can actually make sure it works, and will not break in the future without us noticing.

@kkhaidukov kkhaidukov force-pushed the expose_matcher_for_interactable branch from 9d43d4f to 2f26f31 Compare April 16, 2018 14:07
@kkhaidukov
Copy link
Contributor Author

@rotemmiz I need help with this failed build here -- https://travis-ci.org/wix/detox/jobs/367176057
locally I'm not having this failure

@rotemmiz
Copy link
Contributor

Travis will be Travis 😒, restarted, green

@kkhaidukov
Copy link
Contributor Author

@rotemmiz the e2e test is added, please have another look

@rotemmiz
Copy link
Contributor

I am trying to understand the usecase for using this API.
I'm trying to understand the test you added here. If you're just trying to test that the view can be interacted upon, why not use expect to be visible ? it may be even more conservative since it has 75% visibility threshold.
BTW, EarlGrey validates on most actions if the view is intractable before performing, tap included, so the test you wrote seems redundant.

@kkhaidukov
Copy link
Contributor Author

@rotemmiz We have an app with tabbed interface, and two (or more) tabs may have elements with the same testIDs, because when the tab is switched, a new screen is pushed onto the stack, overlaying the one beneath it (which is not destroyed and its elements are therefore locatable). In this case, detox cannot distinguish between the two elements when trying to e.g. tap.

Adding the interactable matcher solves this problem -- if I remove .and(by.interactable()) from my test, it will fail because multiple elements are matched.

@rotemmiz
Copy link
Contributor

What prevents you from adding testID to each tab ?

@rotemmiz
Copy link
Contributor

interactable means that this view has 10 at least visible pixels. does this solve your issue ? how ?

BTW, I think this proposition will solve your problem and much more.

@kkhaidukov
Copy link
Contributor Author

kkhaidukov commented Apr 19, 2018

What prevents you from adding testID to each tab ?

would that help? withAncestor still matches only immediate parents, or am I doing something wrong

does this solve your issue ? how ?

it does, it ensures that only the elements belonging to the uppermost screen will be matched

BTW, I think this proposition will solve your problem and much more.

it might, but it doesn't look like it's getting any action

@rotemmiz
Copy link
Contributor

So is everything mounted to the screen (even things which are not in the active tab?)
Do you use react native navigation?

@kkhaidukov
Copy link
Contributor Author

So is everything mounted to the screen (even things which are not in the active tab?)

yes

Do you use react native navigation?

if you mean wix/react-native-navigation, then no, we don't

@rotemmiz
Copy link
Contributor

In sake of your app's performance, try detaching those views from the hierarchy. This will also solve your problem.

@mroswald
Copy link

@rotemmiz You can't detach it in every case (at least in the router implementation @kkhaidukov is referring to). While you transition between the screens they need to be mounted and they need to be kept in case you want to transition back. React Native itself takes care of what needs to be rendered and what not, there shouldn't be an performance impact.

Do you see an issue with a matcher for interactable?

@kkhaidukov
Copy link
Contributor Author

@rotemmiz any other changes needed to get this PR merged?

@stale
Copy link

stale bot commented Jun 21, 2018

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 🏚 stale label Jun 21, 2018
@stale
Copy link

stale bot commented Jun 28, 2018

The issue has been closed for inactivity.

@stale stale bot closed this Jun 28, 2018
@rotemmiz
Copy link
Contributor

Hey, sorry for the delayed response here, but I don't think this PR is a good idea, along with what I wrote previously.
A solution that can solve your problems (and was already kinda implemented on Android), is making sure non-interactable views won't be matched.

A PR of this type makes much more sense IMO.

@rotemmiz
Copy link
Contributor

rotemmiz commented Jul 4, 2018

Detox is being used in React Native Navigation v2, and we had the same issue of multiple views with the same testID on multiple tabs on its Android playground app (the app we test RNNv2 on).
Adding the same functionality on iOS matchers should be added here: https://github.com/wix/detox/blob/master/detox/ios/Detox/GREYMatchers+Detox.m

You'll probably need to add matcherForInteractable to grey_allOf() on all matchers.

@kkhaidukov
Copy link
Contributor Author

Currently I'm trying to switch IdMatcher from calling GreyMatchers.matcherForAccessibilityID to a method that I created in GREYMatchers+Detox.m that looks like this:

+ (id<GREYMatcher>)detoxMatcherForAccessibilityID:(NSString *)accessibilityID {
    if (![ReactNativeSupport isReactNativeApp])
    {
        return  [self matcherForAccessibilityID:accessibilityID];
    }
    else
    {
        Class RCTTextViewClass = NSClassFromString(@"RCTText") ?: NSClassFromString(@"RCTTextView");
        return grey_allOf(grey_sufficientlyVisible(),
                          grey_accessibilityID(accessibilityID),
                          grey_not(grey_descendant(grey_allOf(grey_kindOfClass(RCTTextViewClass),
                                                              grey_accessibilityID(accessibilityID),
                                                              nil))),
                          nil);
    }    
}

But the problem is, the tests get very noticeably slower, when there is an extra grey_ matcher inside of grey_allOf. I've tried with grey_sufficientlyVisible and grey_interactable.
Is it the expected behavior or am I just doing it wrong?
@rotemmiz @LeoNatan

@rotemmiz
Copy link
Contributor

rotemmiz commented Jul 8, 2018

I suggest you either open a PR or a new issue. Visibility of closed issues is very limited. You can reference this issue in the new one.

@wix wix locked and limited conversation to collaborators Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants