Add integration test for the Platform Services app (#8826)

This commit is contained in:
Sarah Zakarias
2017-03-20 22:19:03 +01:00
committed by GitHub
parent 142922deb4
commit d1f73fd0ad
8 changed files with 132 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ class PlatformServices extends StatefulWidget {
class _PlatformServicesState extends State<PlatformServices> {
static const PlatformMethodChannel platform = const PlatformMethodChannel('battery');
String _batteryLevel = 'Unknown battery level.';
String _batteryLevel = '';
Future<Null> _getBatteryLevel() async {
String batteryLevel;
@@ -40,7 +40,7 @@ class _PlatformServicesState extends State<PlatformServices> {
child: new Text('Get Battery Level'),
onPressed: _getBatteryLevel,
),
new Text(_batteryLevel),
new Text(_batteryLevel, key: new Key('Battery level label')),
],
),
),

View File

@@ -7,6 +7,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
path: ../../packages/flutter_driver
flutter:
uses-material-design: true

View File

@@ -0,0 +1,11 @@
// Copyright 2017 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 'package:flutter_driver/driver_extension.dart';
import 'package:platform_services/main.dart' as app;
void main() {
enableFlutterDriverExtension();
app.main();
}

View File

@@ -0,0 +1,36 @@
// Copyright 2017 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 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() {
group('button tap test', () {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
if (driver != null)
driver.close();
});
test('tap on the button, verify result', () async {
final SerializableFinder batteryLevelLabel = find.byValueKey('Battery level label');
expect(batteryLevelLabel, isNotNull);
final SerializableFinder button = find.text('Get Battery Level');
await driver.waitFor(button);
await driver.tap(button);
String batteryLevel;
while(batteryLevel == null || batteryLevel.isEmpty) {
batteryLevel = await driver.getText(batteryLevelLabel);
}
expect(batteryLevel, isNotEmpty);
});
});
}