Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在颤振测试中找到一个浮动动作按钮_Flutter_Flutter Test - Fatal编程技术网

Flutter 在颤振测试中找到一个浮动动作按钮

Flutter 在颤振测试中找到一个浮动动作按钮,flutter,flutter-test,Flutter,Flutter Test,我在我的flatter应用程序中运行了一些小部件测试,遇到了这个问题 因此,测试中调用的页面仅由构建卡片列表的ListView.builder创建,之后是一个“添加更多卡片”浮动按钮(按钮位于ListView.builder内) 根据《真的没有秘密》的说法,你只需找到它,然后像其他按钮小部件一样点击它 await tester.tap(find.byType(FloatingActionButton)); 但是当测试达到这条线时,我得到了一个“糟糕的状态:没有这样的元素” 下面是测试代码: t

我在我的flatter应用程序中运行了一些小部件测试,遇到了这个问题

因此,测试中调用的页面仅由构建卡片列表的ListView.builder创建,之后是一个“添加更多卡片”浮动按钮(按钮位于ListView.builder内)

根据《真的没有秘密》的说法,你只需找到它,然后像其他按钮小部件一样点击它

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);