mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
![]() ## Add `bySemanticsIdentifier` finder for finding by identifier ### Description This pull request introduces a new finder, `CommonFinders.bySemanticsIdentifier`, to the Flutter testing framework. This finder allows developers to locate `Semantics` widgets based on their `identifier` property, enhancing the precision and flexibility of widget tests. ### Motivation Establish a consistent and reliable method for locating elements in integration and end-to-end (e2e) tests. Unlike `label` or `key`, which may carry functional significance within the application, the `identifier` is purely declarative and does not impact functionality. Utilizing the `identifier` for finding semantics widgets ensures that tests can target specific elements without interfering with the app's behavior, thereby enhancing test reliability, maintainability, and reusability across testing frameworks. ### Changes - **semantics.dart** - Updated documentation to mention that `identifier` can be matched using `CommonFinders.bySemanticsIdentifier`. - **finders.dart** - Added the `bySemanticsIdentifier` method to `CommonFinders`. - Supports both exact string matches and regular expression patterns. - Includes error handling to ensure semantics are enabled during tests. - **finders_test.dart** - Added tests to verify that `bySemanticsIdentifier` correctly finds widgets by exact identifier and regex patterns. - Ensures that the finder behaves as expected when semantics are not enabled. ### Usage Developers can use the new finder in their tests as follows: ```dart // Exact match expect(find.bySemanticsIdentifier('Back'), findsOneWidget); // Regular expression match expect(find.bySemanticsIdentifier(RegExp(r'^item-')), findsNWidgets(2)); ``` |
||
---|---|---|
.. | ||
bindings_environment | ||
custom_exception_reporter | ||
semantics_checker | ||
test_config | ||
utils | ||
accessibility_test.dart | ||
accessibility_window_test.dart | ||
all_elements_test.dart | ||
analysis_options.yaml | ||
bindings_async_gap_test.dart | ||
bindings_reset_test.dart | ||
bindings_restoration_test.dart | ||
bindings_test_failure.dart | ||
bindings_test.dart | ||
controller_test.dart | ||
coordinate_translation_test.dart | ||
demangle_test.dart | ||
display_test.dart | ||
event_simulation_test.dart | ||
finders_test.dart | ||
frame_timing_summarizer_test.dart | ||
goldens_test.dart | ||
integration_bindings_test.dart | ||
live_binding_test.dart | ||
live_widget_controller_test.dart | ||
matchers_test.dart | ||
mock_canvas_test.dart | ||
multi_view_accessibility_test.dart | ||
multi_view_controller_test.dart | ||
multi_view_testing.dart | ||
platform_dispatcher_test.dart | ||
reference_image_test.dart | ||
restoration_test.dart | ||
semantics_finder_test.dart | ||
stack_manipulation_test.dart | ||
test_async_utils_test.dart | ||
test_default_binary_messenger_test.dart | ||
test_text_input_test.dart | ||
view_test.dart | ||
widget_tester_leaks_test.dart | ||
widget_tester_live_device_test.dart | ||
widget_tester_test.dart | ||
window_test.dart |