Arun Kenjila
Arun Kenjila

Reputation: 169

Tap() in widget test showing warning in flutter

await widgetTester.tap(find.byType(ElevatedButton));

shows warning : Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.

Upvotes: 11

Views: 7848

Answers (3)

Nguyễn Anh Tuấn
Nguyễn Anh Tuấn

Reputation: 1350

I just replace await tester.pump(); by await tester.pumpAndSettle(); before tap

It works for me.

Upvotes: 3

jbryanh
jbryanh

Reputation: 2023

I suggest creating a safeTapBy function logic. This just ensures that the button is visible (keyboard showing, off screen etc). Here is an example using find.byKey:

Future safeTapByKey(WidgetTester tester, String key) async {
  await tester.ensureVisible(find.byKey(Key(key)));
  await tester.pumpAndSettle();
  await tester.tap(find.byKey(Key(key)));
}

Upvotes: 2

Alireza
Alireza

Reputation: 263

Try this:

await widgetTester.ensureVisible(find.byType(ElevatedButton));
await widgetTester.pumpAndSettle();
await widgetTester.tap(find.byType(ElevatedButton));

Upvotes: 26

Related Questions