LiewJunTung / pin_code_text_field

A highly customisable Flutter widget for entering pin code. Suitable for use cases such as login and OTP.
MIT License
376 stars 78 forks source link

Question: How to use in a test #62

Open evanblasband opened 2 years ago

evanblasband commented 2 years ago

I have a questions on how to test this package in my app. Specifically I want to navigate to this page and run through different scenarios (i.e. enter correct pin, enter incorrect pin etc.) and verify the given action is correct. However I am not sure how to enter text into this widget for an input. I am currently doing the following:

      expect(findThisText('Please Enter Pin'), findsOneWidget);
      expect(findThisType(Image), findsOneWidget);
      expect(findThisKey(Key('kPinCodeTextField')), findsOneWidget);

      await tester.enterText(findThisKey(Key('kPinCodeTextField')), '111111');
      await tester.pump(Duration(seconds: 3));

where the key is for the PinCodeTextField widget in my app. Any insight would be much appreciated.

gslender commented 2 years ago

Did you find any solutions? I'm thinking of swapping out this widget for something testable, as essentially it isn't that important / nice, and not being able to test-automate is seen as more important than fancy/styled pin code field

gslender commented 2 years ago

This worked...

    await driver.runUnsynchronized(() async {
      final pinField = find.descendant(
        of: find.byType('PinCodeTextField'),
        matching: find.byType('AnimatedContainer'),
        firstMatchOnly: true,
      );
      await driver.tapElement(pinField);
      await driver.enterText('1234');
    });