Flutter driver commands for controlling the Input widget (#4913)
* Driver commands for controlling the Input widget This commit introduces two new driver commands for controlling the material Input widget. * setInputText(SerializableFinder finder, String text) * submitInputText(SerializableFinder finder) Since it is not possible to directly modify the Input widget text, these driver commands invokes the handler functions of the Input widget: onChanged and onSubmitted, respectively. The `submitInputText` command returns the submitted String as a result. * Make input command handler methods private Addressing comments from @yjbanov.
This commit is contained in:
@@ -12,6 +12,7 @@ import 'error.dart';
|
||||
import 'find.dart';
|
||||
import 'gesture.dart';
|
||||
import 'health.dart';
|
||||
import 'input.dart';
|
||||
import 'message.dart';
|
||||
import 'timeline.dart';
|
||||
|
||||
@@ -214,6 +215,24 @@ class FlutterDriver {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Sets the text value of the `Input` widget located by [finder].
|
||||
///
|
||||
/// This command invokes the `onChanged` handler of the `Input` widget with
|
||||
/// the provided [text].
|
||||
Future<Null> setInputText(SerializableFinder finder, String text) async {
|
||||
await _sendCommand(new SetInputText(finder, text));
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Submits the current text value of the `Input` widget located by [finder].
|
||||
///
|
||||
/// This command invokes the `onSubmitted` handler of the `Input` widget and
|
||||
/// the returns the submitted text value.
|
||||
Future<String> submitInputText(SerializableFinder finder) async {
|
||||
Map<String, dynamic> json = await _sendCommand(new SubmitInputText(finder));
|
||||
return json['text'];
|
||||
}
|
||||
|
||||
/// Waits until [finder] locates the target.
|
||||
Future<Null> waitFor(SerializableFinder finder, {Duration timeout: _kDefaultTimeout}) async {
|
||||
await _sendCommand(new WaitFor(finder, timeout: timeout));
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'error.dart';
|
||||
import 'find.dart';
|
||||
import 'gesture.dart';
|
||||
import 'health.dart';
|
||||
import 'input.dart';
|
||||
import 'message.dart';
|
||||
|
||||
const String _extensionMethodName = 'driver';
|
||||
@@ -64,6 +65,8 @@ class FlutterDriverExtension {
|
||||
'get_text': getText,
|
||||
'scroll': scroll,
|
||||
'scrollIntoView': scrollIntoView,
|
||||
'setInputText': _setInputText,
|
||||
'submitInputText': _submitInputText,
|
||||
'waitFor': waitFor,
|
||||
});
|
||||
|
||||
@@ -73,6 +76,8 @@ class FlutterDriverExtension {
|
||||
'get_text': GetText.deserialize,
|
||||
'scroll': Scroll.deserialize,
|
||||
'scrollIntoView': ScrollIntoView.deserialize,
|
||||
'setInputText': SetInputText.deserialize,
|
||||
'submitInputText': SubmitInputText.deserialize,
|
||||
'waitFor': WaitFor.deserialize,
|
||||
});
|
||||
|
||||
@@ -215,6 +220,20 @@ class FlutterDriverExtension {
|
||||
return new ScrollResult();
|
||||
}
|
||||
|
||||
Future<SetInputTextResult> _setInputText(SetInputText command) async {
|
||||
Finder target = await _waitForElement(_createFinder(command.finder));
|
||||
Input input = target.evaluate().single.widget;
|
||||
input.onChanged(new InputValue(text: command.text));
|
||||
return new SetInputTextResult();
|
||||
}
|
||||
|
||||
Future<SubmitInputTextResult> _submitInputText(SubmitInputText command) async {
|
||||
Finder target = await _waitForElement(_createFinder(command.finder));
|
||||
Input input = target.evaluate().single.widget;
|
||||
input.onSubmitted(input.value);
|
||||
return new SubmitInputTextResult(input.value.text);
|
||||
}
|
||||
|
||||
Future<GetTextResult> getText(GetText command) async {
|
||||
Finder target = await _waitForElement(_createFinder(command.finder));
|
||||
// TODO(yjbanov): support more ways to read text
|
||||
|
||||
62
packages/flutter_driver/lib/src/input.dart
Normal file
62
packages/flutter_driver/lib/src/input.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'message.dart';
|
||||
import 'find.dart';
|
||||
|
||||
class SetInputText extends CommandWithTarget {
|
||||
@override
|
||||
final String kind = 'setInputText';
|
||||
|
||||
SetInputText(SerializableFinder finder, this.text) : super(finder);
|
||||
|
||||
final String text;
|
||||
|
||||
static SetInputText deserialize(Map<String, dynamic> json) {
|
||||
String text = json['text'];
|
||||
return new SetInputText(SerializableFinder.deserialize(json), text);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> serialize() {
|
||||
Map<String, String> json = super.serialize();
|
||||
json['text'] = text;
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
class SetInputTextResult extends Result {
|
||||
static SetInputTextResult fromJson(Map<String, dynamic> json) {
|
||||
return new SetInputTextResult();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{};
|
||||
}
|
||||
|
||||
class SubmitInputText extends CommandWithTarget {
|
||||
@override
|
||||
final String kind = 'submitInputText';
|
||||
|
||||
SubmitInputText(SerializableFinder finder) : super(finder);
|
||||
|
||||
static SubmitInputText deserialize(Map<String, dynamic> json) {
|
||||
return new SubmitInputText(SerializableFinder.deserialize(json));
|
||||
}
|
||||
}
|
||||
|
||||
class SubmitInputTextResult extends Result {
|
||||
SubmitInputTextResult(this.text);
|
||||
|
||||
final String text;
|
||||
|
||||
static SubmitInputTextResult fromJson(Map<String, dynamic> json) {
|
||||
return new SubmitInputTextResult(json['text']);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'text': text
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user