呂學洲*_*呂學洲 7 testing flutter widget-test-flutter
就我而言,当我使用 时ExpansionPanelList,我需要检查面板内的小部件是否可见。
如果不可见,tester.tap(find.text('More Info'))将抛出异常:
Warning: A call to tap() with finder "exactly one widget with text "More Info" (ignoring offstage widgets): Text("More Info", dependencies: [MediaQuery, DefaultTextStyle])" derived an Offset (Offset(400.0, 641.8)) that would not hit test on the specified widget. Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events. Indeed, Offset(400.0, 641.8) is outside the bounds of the root of the render tree, Size(800.0, 600.0). The finder corresponds to this RenderBox: RenderParagraph#1b6b1 relayoutBoundary=up27 The hit test result at that offset is: HitTestResult(HitTestEntry#b18dd(RenderView#408c3), HitTestEntry#a2393()) #0 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:953:25) #1 WidgetController.getCenter (package:flutter_test/src/controller.dart:836:12) #2 WidgetController.tap (package:flutter_test/src/controller.dart:271:18) #3 main. (file:///Users/tommy/Repos/surveyapp/survey/test/widget_test.dart:99:18)
Run Code Online (Sandbox Code Playgroud)
如何检查此小部件在测试中是否可见?
Dan*_*tad 19
使用hitTestable(),它会生成一个查找器,仅当查找器描述的小部件在屏幕上真正可见时才匹配。例如:
expect(find.text('More Info').hitTestable(), findsOneWidget);
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您可能需要等待ExpansionPanelList展开或列表滚动到视图中。您可能需要先使用pumpSettle()或ensureVisible()。
| 归档时间: |
|
| 查看次数: |
6747 次 |
| 最近记录: |