Flutter 在颤振测试中找到一个浮动动作按钮
我在我的flatter应用程序中运行了一些小部件测试,遇到了这个问题 因此,测试中调用的页面仅由构建卡片列表的ListView.builder创建,之后是一个“添加更多卡片”浮动按钮(按钮位于ListView.builder内) 根据《真的没有秘密》的说法,你只需找到它,然后像其他按钮小部件一样点击它Flutter 在颤振测试中找到一个浮动动作按钮,flutter,flutter-test,Flutter,Flutter Test,我在我的flatter应用程序中运行了一些小部件测试,遇到了这个问题 因此,测试中调用的页面仅由构建卡片列表的ListView.builder创建,之后是一个“添加更多卡片”浮动按钮(按钮位于ListView.builder内) 根据《真的没有秘密》的说法,你只需找到它,然后像其他按钮小部件一样点击它 await tester.tap(find.byType(FloatingActionButton)); 但是当测试达到这条线时,我得到了一个“糟糕的状态:没有这样的元素” 下面是测试代码: t
await tester.tap(find.byType(FloatingActionButton));
但是当测试达到这条线时,我得到了一个“糟糕的状态:没有这样的元素”
下面是测试代码:
testWidgets('Connecting with new machine', (WidgetTester tester) async {
await tester.pumpWidget(makeWigdetTestable(child: MaquinasPage()));
await tester.tap(find.byType(FloatingActionButton));
await tester.pumpAndSettle();
expect(find.text('new machine connected'), findsOneWidget);
});
注意:“makeWidgetTestable”小部件只返回一个MaterialApp,其“home”属性是参数“MaquinasPage()”。我遇到过这样的情况,我想从scaffold中找到一个浮动操作按钮
return Scaffold(
appBar: AppBar(title: Text("Title")),
body: Container(*** my code ***),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => { *** my code ***}
),
);
还有我的测试:
expect(find.widgetWithIcon(FloatingActionButton, Icons.add), findsOneWidget);