Skip to content

Provide testing extension API that matches widgets and returns matched widget information #29375

Closed

Description

@adazh

The API takes in a matcher (e.g. withText, withValueKey) and returns a serialized widget object, which contains information necessary (e.g. coordinates) for performing an action on the widget or making assertions on the widget properties in Espresso.

Activity

  1. jonahwilliams commented on Mar 15, 2019

    @jonahwilliams
    Contributor

    For testing, you likely want information from the semantics tree, this can tell you things such as where to tap/available actions/labels. Example:

    flutter:      └─SemanticsNode#6
    flutter:        │ Rect.fromLTRB(0.0, 100.0, 414.0, 896.0)
    flutter:        │ flags: scopesRoute, namesRoute
    flutter:        │ label: "categories"
    flutter:        │ textDirection: ltr
    flutter:        │ elevation: 12.0
    flutter:        │
    flutter:        └─SemanticsNode#7
    flutter:          │ Rect.fromLTRB(0.0, 0.0, 414.0, 552.0)
    flutter:          │ flags: hasImplicitScrolling
    flutter:          │ scrollExtentMin: 0.0
    flutter:          │ scrollPosition: 0.0
    flutter:          │ scrollExtentMax: 0.0
    flutter:          │
    flutter:          ├─SemanticsNode#8
    flutter:          │   Rect.fromLTRB(0.0, 0.0, 207.0, 184.0)
    flutter:          │   actions: tap
    flutter:          │   flags: isButton, hasEnabledState, isEnabled
    flutter:          │   label: "Studies"
    flutter:          │   textDirection: ltr
    flutter:          │
    

    The semantics tree doesn't correspond 1-1 with Widgets though. And since a Widget is an arbitrary user defined class, we do not have the capability to reflect on or serialize them.

  2. Hixie commented on Mar 19, 2019

    @Hixie
    Contributor

    @jacob314's inspector API exposes much of this, would it be sufficient?

  3. added this to the milestone on Mar 19, 2019
  4. modified the milestones: , July 2019 on Mar 20, 2019
  5. adazh commented on May 22, 2019

    @adazh
    ContributorAuthor

    As discussed with @goderbauer yesterday, for the first version, the matching API will possibly be something like this:
    WidgetInfo matchWidget(SerializableFinder finder), which finds a widget (RenderObject to be accurate?) that matches exactly with the finder, and returns an object containing its properties (we could even start with a minimum set of properties, e.g. runtimeType, valueKey, text, tooltip).

    • How does the matching work?
      First version: it won't be able to match a composite widget. Rather it does exact matching on a widget.
      For example, a Flutter button could be composed by an icon, a Text widget, and may also have multiple layers of widget containers, decorators. Users cannot express "matching a (composite) button widget for me" with the matching API, but could match the Text widget for example.

    Michael, feel free to correct if I'm wrong.

  6. github-actions commented on Aug 29, 2021

    @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.

  7. locked as resolved and limited conversation to collaborators on Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: tests"flutter test", flutter_test, or one of our testscustomer: espressoframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions