Open yroza opened 11 months ago
Also reported in the Patrol repository: https://github.com/leancodepl/patrol/issues/1409
Hey @yroza @bartekpacia, can you confirm that this code snippet works for you as well?
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinput/pinput.dart';
void main() {
testWidgets('Can enter value', (WidgetTester tester) async {
String? fieldValue;
int called = 0;
final controller = TextEditingController();
final focusNode = FocusNode();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Pinput(
controller: controller,
onChanged: (value) {
fieldValue = value;
called++;
},
),
),
),
);
focusNode.requestFocus();
await tester.pump();
expect(fieldValue, isNull);
expect(called, 0);
await tester.enterText(find.byType(Pinput), '1111');
await tester.testTextInput.receiveAction(TextInputAction.done);
expect(fieldValue, equals('1111'));
expect(called, 1);
});
}
Thanks @Tkko, this code works in a widget test (when run with flutter test test/pinput_test.dart
).
When I run it in a real app on the device (with flutter run test/pinput_test.dart
), it also works:
I had to modify your test slightly to use setState()
, so the changes made are visible:
@bartekpacia Perfect, I'm not sure how patrol
works but Pinput
uses an EditableText
which is an underlying widget of TextField
and CupertinoTextField
so everything should work in the same way
I'm curious whether you use a single EditableText
for all of the number squares, or a single EditableText
for each one of the number squares?
If you use a single EditableText
for all, how does it work that you have a gap between the number squares?
I use single EditableText
Which is hidden under the boxes.
For any one facing the same issue:
add one duration to pump
method before calling await tester.enterText(find.byType(Pinput), '1111');
example: await tester.pump(Duration(milliseconds: 500));
Describe the bug I implemented patrol(https://patrol.leancode.co/) package for perform the integration testing in my current project. when I write the test cases for test the Pinput widget so I am not able to enter text in Pinput widget.
Screenshots Here is my code for test the pinput widget
Pinput version: [e.g. 1.1.10]
Result of:
flutter doctor --verbose
Result of:
patrol doctor
Smartphone (please complete the following information):
Additional context when I run the patrol develop command then I got this result