Emulate text entry in FlutterDriver (#13373)

* Emulate text entry in FlutterDriver

* document enterText behavior

* remove the unnecessary composint TextRange
This commit is contained in:
Yegor
2017-12-06 17:29:37 -08:00
committed by GitHub
parent 5a1e639a2f
commit e27bcd0f9d
9 changed files with 155 additions and 43 deletions

View File

@@ -23,8 +23,8 @@ final CommonFinders find = const CommonFinders._();
class CommonFinders {
const CommonFinders._();
/// Finds [Text] widgets containing string equal to the `text`
/// argument.
/// Finds [Text] and [EditableText] widgets containing string equal to the
/// `text` argument.
///
/// Example:
///
@@ -410,10 +410,14 @@ class _TextFinder extends MatchFinder {
@override
bool matches(Element candidate) {
if (candidate.widget is! Text)
return false;
final Text textWidget = candidate.widget;
return textWidget.data == text;
if (candidate.widget is Text) {
final Text textWidget = candidate.widget;
return textWidget.data == text;
} else if (candidate.widget is EditableText) {
final EditableText editable = candidate.widget;
return editable.controller.text == text;
}
return false;
}
}

View File

@@ -65,7 +65,11 @@ class TestTextInput {
/// Simulates the user changing the [TextEditingValue] to the given value.
void updateEditingValue(TextEditingValue value) {
expect(_client, isNonZero);
// Not using the `expect` function because in the case of a FlutterDriver
// test this code does not run in a package:test test zone.
if (_client == 0) {
throw new TestFailure('_client must be non-zero');
}
BinaryMessages.handlePlatformMessage(
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(
@@ -82,7 +86,6 @@ class TestTextInput {
void enterText(String text) {
updateEditingValue(new TextEditingValue(
text: text,
composing: new TextRange(start: 0, end: text.length),
));
}