Skip to content

Better API for triggering SemanticsActions in tests #112413

Description

@goderbauer

The API to trigger semantics actions from tests right now is not very discoverable:

tester.binding.pipelineOwner.semanticsOwner!.performAction(detectorId, SemanticsAction.scrollLeft);

Instead of requiring developers to figure that out, we should provide an easier way. Similarly to WidgetTester.tap [1] and WidgetTester.tapAt [2] we should provide a simple API on WidgetTester itself to trigger semantics actions in tests based on finders. With such an API, people could be writing something like the following in their tests:

  await tester.performSemanticsAction(find.text('click me'), SemanticsAction.tap);

[1] https://master-api.flutter.dev/flutter/flutter_test/WidgetController/tap.html
[2] https://master-api.flutter.dev/flutter/flutter_test/WidgetController/tapAt.html

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    a: multi windowIssues related to multi window support
    on Sep 26, 2022
  2. goderbauer commented on Sep 26, 2022

    @goderbauer
    MemberAuthor

    Implementing this would also be helpful for the multi window project: the pipelineOwner attribute on the binding is going away as part of that project, so all tests, which are currently relying on tester.binding.pipelineOwner.semanticsOwner to perform semantics actions need to be migrated anyways. Would be good to migrate them straight to a more sensible API on widget tester instead of migrating them to what's replacing the pipelineOwner attribute.

    (Under the hood, the API on WidgetTester can still be based on pipelineOwner for now. Once the multi window stuff is ready, we would then have a single place to migrate that over to the new API instead of doing it for every single test that triggers semantics actions.)

  3. goderbauer commented on Sep 26, 2022

    @goderbauer
    MemberAuthor

    /cc @pdblasi-google Would you be up for looking into this?

  4. pdblasi-google commented on Sep 26, 2022

    @pdblasi-google
    Contributor

    @goderbauer

    Yeah, I'd be happy to look into this. This actually gave me an idea for improving the API for #107866 as well. What would you think about adding a semantics/semanticsTester property to WidgetTester that could include various semantics related APIs?

    It'd be implemented with a SemanticsTester class, which could help organize out those specific needs. I've been trying to make a Finder in #107866 for a simulated semantics traversal, but the API isn't quite right. It'd fit better in either WidgetTester or a dedicated SemanticsTester, so I could create an initial SemanticsTester as part of #107866 and add in new functionality for this ticket when I get to it.

  5. goderbauer commented on Sep 27, 2022

    @goderbauer
    MemberAuthor

    What API are you envisioning for that semantics/semanticsTester property? Could it live right on WidgetTester as a first-class citizen like most of the other testing related API?

  6. pdblasi-google commented on Sep 27, 2022

    @pdblasi-google
    Contributor

    I was thinking that the semantics property would be implemented with a separate class, but be exposed through WidgetTester. The end result would look something like this while writing tests:

    tester.semantics.tap(find.byKey(key));
    

    To make things nicer, I had thought to split out the separate SemanticActions into different methods, but a tester.semantics.performAction could be an alternative or simply included as well.

    Personally, I think having this separated out through a property and separate class makes things more readable, discoverable, and prevents us from having to prefix every method with semantics* to differentiate it from the current WidgetTester methods. It also makes it easier for us to expand on our semantics testing API more consistently, lowering the overall maintenance burden.

  7. goderbauer commented on Sep 27, 2022

    @goderbauer
    MemberAuthor

    I like that idea!

  8. pdblasi-google commented on Sep 27, 2022

    @pdblasi-google
    Contributor

    Awesome! I'll start on that idea with #107866 and expand on it here for semantics interactions!

  9. added
    P1High-priority issues at the top of the work list
    on Sep 27, 2022
  10. 3 remaining items

  11. flutter-triage-bot commented on Jul 9, 2023

    @flutter-triage-bot

    This issue is assigned but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  12. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Jul 30, 2023
  13. flutter-triage-bot commented on Sep 1, 2023

    @flutter-triage-bot

    This issue was assigned to @pdblasi-google but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

  14. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Sep 1, 2023
  15. moved this from In Progress to Done in Multi Windowon Oct 18, 2023
  16. added a commit that references this issue on Oct 18, 2023
    52a1a31
  17. github-actions commented on Nov 1, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: multi windowIssues related to multi window supporta: tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions