Add integration test for the Platform Services app (#8826)
This commit is contained in:
@@ -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')),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -7,6 +7,8 @@ dependencies:
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_driver:
|
||||
path: ../../packages/flutter_driver
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
11
examples/platform_services/test_driver/button_tap.dart
Normal file
11
examples/platform_services/test_driver/button_tap.dart
Normal 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();
|
||||
}
|
||||
36
examples/platform_services/test_driver/button_tap_test.dart
Normal file
36
examples/platform_services/test_driver/button_tap_test.dart
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user