flutter/packages/flutter_test/test
Adam 37d5dc45d1
Add bySemanticsIdentifier finder for finding by identifier (#155571)
## 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));
```
2024-10-08 17:27:32 +00:00
..
bindings_environment add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
custom_exception_reporter Enable use_function_type_syntax_for_parameters lint (#77163) 2021-03-04 08:59:17 -08:00
semantics_checker Stand-alone widget tree with multiple render trees to enable multi-view rendering (#125003) 2023-07-17 16:14:08 +00:00
test_config Enable private field promotion for other packages (#134475) 2023-09-12 21:08:19 +00:00
utils Improve testing for leak tracking. (#140553) 2024-01-10 11:04:28 -08:00
accessibility_test.dart Update color assertions (#154752) 2024-09-10 15:32:40 -07:00
accessibility_window_test.dart Remvoe last few references to window singleton (#122644) 2023-03-15 00:34:34 +00:00
all_elements_test.dart reland List queue search optimization (#68214) 2020-10-15 13:46:50 -07:00
analysis_options.yaml Enable more lints (#91642) 2021-10-14 22:03:03 -07:00
bindings_async_gap_test.dart Make FlutterErrorDetails.exception non-nullable as documented (#67364) 2020-10-05 18:07:02 -07:00
bindings_reset_test.dart TestWidgetsFlutterBinding should dispose old RestorationManager on reset. (#133999) 2023-09-07 17:49:33 -07:00
bindings_restoration_test.dart Properly initialize RestorationManager in the TestBinding (#70398) 2020-11-12 13:59:05 -08:00
bindings_test_failure.dart Migrate the tests of flutter_test to null-safety (#67058) 2020-10-01 16:27:02 -07:00
bindings_test.dart Updates AutomatedTestWidgetsFlutterBinding.pump to support microsecond precision (#132401) 2023-08-14 23:24:47 +00:00
controller_test.dart Reland [a11y] Add isEnabled semantics flag to text field (#143601) 2024-02-27 22:49:13 +00:00
coordinate_translation_test.dart Remove LiveTestRenderView (#127882) 2023-06-02 20:41:05 +00:00
demangle_test.dart Migrate the tests of flutter_test to null-safety (#67058) 2020-10-01 16:27:02 -07:00
display_test.dart Adds TestDisplay API for testing Display features (#127525) 2023-05-26 00:04:05 +00:00
event_simulation_test.dart [flutter_test] Use defaultTargetPlatform for key events simulation (#143579) 2024-03-07 16:08:20 +00:00
finders_test.dart Add bySemanticsIdentifier finder for finding by identifier (#155571) 2024-10-08 17:27:32 +00:00
frame_timing_summarizer_test.dart [flutter_test] Fix incorrect missed budget count (#95003) 2021-12-10 18:44:11 -08:00
goldens_test.dart Fix: performance improvement on golden test comparison (#142913) 2024-02-09 22:05:00 +00:00
integration_bindings_test.dart Migrate the tests of flutter_test to null-safety (#67058) 2020-10-01 16:27:02 -07:00
live_binding_test.dart Remvoe last few references to window singleton (#122644) 2023-03-15 00:34:34 +00:00
live_widget_controller_test.dart Assert that runApp is called in the same zone as binding.ensureInitialized (#122836) 2023-03-16 22:33:09 +00:00
matchers_test.dart Adds ColorSwatch matcher (#155272) 2024-09-17 09:08:22 -07:00
mock_canvas_test.dart Move mock canvas to flutter_test (#131631) 2023-08-07 23:43:03 +00:00
multi_view_accessibility_test.dart Relands "Add runWidget to bootstrap a widget tree without a default View" (#142344) 2024-01-26 23:05:53 +00:00
multi_view_controller_test.dart Fix SemanticsFinder for multi-view (#143485) 2024-02-16 22:24:55 +00:00
multi_view_testing.dart Prepare for dynamically sized views - pt. 2 (#139079) 2023-11-27 19:06:00 +00:00
platform_dispatcher_test.dart Factor out RawView, make View listen to engine generated view focus events (#143259) 2024-05-20 17:17:55 +00:00
reference_image_test.dart Remove usage of testWidgetsWithLeakTracking. (#140239) 2023-12-15 14:13:31 -08:00
restoration_test.dart Prepare packages (minus tools,framework) for use_super_parameters (#100510) 2022-03-30 15:31:59 -07:00
semantics_finder_test.dart Fix SemanticsFinder for multi-view (#143485) 2024-02-16 22:24:55 +00:00
stack_manipulation_test.dart Enable only_throw_errors (#91567) 2021-10-11 14:13:03 -07:00
test_async_utils_test.dart Remove uses of deprecated test_api imports (#124732) 2023-04-20 20:55:28 +00:00
test_default_binary_messenger_test.dart [flutter_test] Adds method to mock EventChannels (#124415) 2023-04-10 17:02:48 +00:00
test_text_input_test.dart Add deleteBackwardByDecomposingPreviousCharacter mapping for tests (#132919) 2023-08-21 23:27:19 +00:00
view_test.dart Reapply "Dynamic view sizing" (#140165) (#140918) 2024-01-09 14:10:43 -08:00
widget_tester_leaks_test.dart Upgrade leak_tracker. (#143236) 2024-02-09 14:41:22 -08:00
widget_tester_live_device_test.dart cleanup now-irrelevant ignores for deprecated_member_use (#143403) 2024-02-14 21:08:25 +00:00
widget_tester_test.dart Allow the SceneBuilder, PictureRecord, and Canvas constructor calls from the rendering layer to be hooked (#147271) 2024-04-25 00:19:24 +00:00
window_test.dart cleanup now-irrelevant ignores for deprecated_member_use (#143403) 2024-02-14 21:08:25 +00:00