Integration test | PumpAndSettle

Viewed 875

I have one screen (Say screen B) which uses animation for a second and then displays UI element. After the animation is over, I need to get a button and press it.

This screen comes after a particular screen (Say screen A). I have successfully written integration tests (using integration_test) and now this screen appears. Now here is the scenario-

  1. A has a button on which I tap and do pumpAndSettle
  2. Due to button press, B screen appears.
  3. Now I need to wait for 1 second, and then current view animated to the left and a new view appears which has a button.
  4. I did pumpAndSettle(Duration(seconds: 1))
  5. Now, after 4th line of code, nothing executes afterwards and test does not end until timeout.

More info:

So there is one screen (Say Home screen of App) on which I am showing "Progress Indicator" until I have data available.

Now there is one screen that is pushed on top (kind of welcome screen) of home screen for a fresh installation of app.

In that screen welcome screen, I have one view which I animated to left after one second and show welcome items with skip button.

So

[1] expect(welcomeScreen, findsOneWidget);

[2] await Future.delayed(Duration(seconds: 1));

[3] await tester.pumpAndSettle();

The above lines of code work fine but if I do,

[2Alt] await tester.pumpAndSettle(Duration(seconds: 1))

This runs indefinitely.

Further

There is a skip button that appears after 1 second (on welcom screen), I click on the skip button which pops the welcome screen and get back to home screen where "progress indicator" is spinning until the data is received.

expect(skipButton, findsOneWidget);
await tester.tap(skipButton);
await tester.pumpAndSettle();

Here pumpAndSettle is taking infinite time (until timeout)

I am not sure what is the reason. What actually pumpAndSettle is doing.. If I do pump only, it works

1 Answers

Try this to pump until what you need appears...

do await tester.pump(); while (
        tester.widgetList(find.byType(WhatYouNeedWidget)).isEmpty);
Related