How to do integration test with flutter driver on AutoTextCompleteFiled with GlobalKey value. How we can identify the AutoTextCompleteFiled widget with the Global key and how we can enter text in this widget with flutter driver automation in BDD?
Asked
Active
Viewed 969 times
1 Answers
0
Here's how you can do it I have given example of flutter_typeahead which is also used for autocomplete
This is the test case
group('App', () {
final saveButton = find.byValueKey('save_button');
final cityField = find.byValueKey('city_field');
final city = 'Mumbai';
FlutterDriver driver;
// Connect to the Flutter driver before running any tests.
setUpAll(() async {
driver = await FlutterDriver.connect();
});
// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
driver.close();
});
test('test cities field', () async {
//for tapping city autocomplete field
await driver.tap(cityField);
//for entering city
await driver.enterText(city);
//for selecting suggestion or find.text(city) to search by text
await driver.tap(find.byValueKey(city));
//for tapping save button
await driver.tap(saveButton);
});
});
This is the autocomplete field
Main things to note here is that you need to use key in each item builder widget that will be used later to tap that widget
You can also use find.text(city) for searching by text instead of key
city name used for testing must be present in the cities list used
Column(
children: <Widget>[
Text('What is your favorite city?'),
TypeAheadFormField(
key: Key('city_field'),
textFieldConfiguration: TextFieldConfiguration(
controller: this._typeAheadController,
decoration: InputDecoration(labelText: 'City')),
suggestionsCallback: (pattern) {
return getSuggestions(pattern, citiesList);
},
itemBuilder: (context, suggestion) {
return ListTile(
key: Key(suggestion),
title: Text(suggestion),
);
},
transitionBuilder: (context, suggestionsBox, controller) {
return suggestionsBox;
},
onSuggestionSelected: (suggestion) {
this._typeAheadController.text = suggestion;
},
validator: (value) {
if (value.isEmpty) {
return 'Please select a city';
}
return null;
},
onSaved: (value) => this._selectedCity = value,
),
TextButton(
key: Key('save_button'),
onPressed: () {},
child: Text('Save'),
),
],
)
Cities List
List<String> citiesList = [
'Mumbai',
'Pune',
'Delhi',
'Surat',
'Jaipur',
'Chennai',
'Kolkata',
'Bangalore'
];

mohit yadav
- 166
- 4