How to test a flutter button in test widget?

Viewed 19

i read flutter's doc but i couldn't test button's action , i tried to do it this way, the button is children of PrivacyPolicyCard, and when clicked goes to the next page

testWidgets(
  "TextButton Acept",
  (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: PrivacyPolicyCard(),
    ));
    final buton = find.byKey(Key("bt-acept"), skipOffstage: false);
    await tester.ensureVisible(buton);

    expect(find.bySemanticsLabel("Button Acept"), findsOneWidget);
    await tester.tap(buton);
    await tester.pumpAndSettle(Duration(seconds: 2));
    expect(find.text("Next Page"), findsOneWidget);
    await tester.printToConsole("test passed");
    
  },
);
0 Answers
Related