Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Action pressOn not working consistently #386

Open
k-ane opened this issue Jan 7, 2024 · 0 comments
Open

fix: Action pressOn not working consistently #386

k-ane opened this issue Jan 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@k-ane
Copy link

k-ane commented Jan 7, 2024

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:

  • Wrap the final pumpAndSettle with a try catch
  • Add a one second timeout to the pumpAndSettle

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;
  }
@k-ane k-ane added the bug Something isn't working label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant