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

feat(android): add support for multiple-views actions. #4180

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

asafkorem
Copy link
Contributor

@asafkorem asafkorem commented Sep 6, 2023

This PR enhances Detox's ability to work with actions on multiple matching views on Android. The aim is to provide greater flexibility for actions, allowing them to handle both single and multiple view scenarios declaratively.

Motivation

As of now, Detox struggles with scenarios where getAttributes() is required to operate on several matched elements on Android, even though this is supported on iOS. This PR lays the groundwork to rectify this discrepancy, paving the way for full implementation in a subsequent PR.

See: #3196

Problem

  • The existing perform method in the EspressoDetox class relies on ViewInteraction, which doesn't naturally cater to multiple matching views.

Solution

  • To sidestep the challenge posed by viewInteraction = onView(matcher), we transitioned the perform method in EspressoDetox to directly use Matcher<View> instead of ViewInteraction.

  • This adjustment enable us to iterate on the the matching views by using the by-index functionality of Matcher.

  • Furthermore, a new marker interface, MultipleViewsAction, has been introduced. Actions having this mark can handle and act upon all views that match.


Usage Examples

public class SomeMultiViewAction implements ViewAction, MultipleViewsAction {
    @Override
    public void perform(UiController uiController, View view) {
        // Your implementation goes here...
    }
}

perform(someMatcher, new SomeMultiViewAction());

@asafkorem asafkorem self-assigned this Sep 6, 2023
@asafkorem
Copy link
Contributor Author

asafkorem commented Sep 6, 2023

This change is still on its draft version. But we can still start the review (design-level) @d4vidi

@asafkorem asafkorem force-pushed the feat/add-multiple-views-support branch 2 times, most recently from 9cd7447 to 8b1ed09 Compare September 6, 2023 10:03
@asafkorem asafkorem force-pushed the feat/add-multiple-views-support branch from 73fd7c0 to f8d8823 Compare September 11, 2023 05:26
@asafkorem asafkorem marked this pull request as ready for review September 11, 2023 07:18
@asafkorem asafkorem merged commit d77cbe0 into master Sep 12, 2023
@asafkorem asafkorem deleted the feat/add-multiple-views-support branch September 28, 2023 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants