wolfenrain / fluttium

Fluttium, the user flow testing tool for Flutter
https://fluttium.dev
MIT License
361 stars 10 forks source link

fix: Action pressOn not working consistently #386

Open k-ane opened 8 months ago

k-ane commented 8 months ago

I had a scenario where pressing a button triggers a loading state which replaces the page, because the button was no longer in the widget tree, the test was getting stuck even though it pressed successfully.

I was able to fix this by duplicating the pressOn action in a new action, and doing the following:

I'm sure this could be cleaner in the actual fix but here is my adjusted code:

@override
  Future<bool> execute(Tester tester) async {
    final Offset center;
    final node = await tester.find(text);
    if (node == null) {
      return false;
    }
    center = node.center;

    final pointer = _pointerId++;

    tester.emitPointerEvent(PointerDownEvent(pointer: pointer, position: center));

    await tester.pump(duration: kPressTimeout);

    tester.emitPointerEvent(PointerUpEvent(pointer: pointer, position: center));

    // Try catch and timeout added here
    try {
      await tester.pumpAndSettle(timeout: const Duration(milliseconds: 1000));
    } catch (e) {}

    return true;
  }