mirror of
https://github.com/flutter/flutter
synced 2024-11-05 18:37:51 +00:00
Add integration test for the Platform Services app (#8826)
This commit is contained in:
parent
142922deb4
commit
d1f73fd0ad
8 changed files with 132 additions and 3 deletions
14
dev/devicelab/bin/tasks/platform_services_test.dart
Normal file
14
dev/devicelab/bin/tasks/platform_services_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// 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 'dart:async';
|
||||
|
||||
import 'package:flutter_devicelab/tasks/perf_tests.dart';
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.android;
|
||||
await task(createPlatformServiceDriverTest());
|
||||
}
|
14
dev/devicelab/bin/tasks/platform_services_test_ios.dart
Normal file
14
dev/devicelab/bin/tasks/platform_services_test_ios.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// 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 'dart:async';
|
||||
|
||||
import 'package:flutter_devicelab/tasks/perf_tests.dart';
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.ios;
|
||||
await task(createPlatformServiceDriverTest());
|
||||
}
|
|
@ -9,6 +9,14 @@ import '../framework/adb.dart';
|
|||
import '../framework/framework.dart';
|
||||
import '../framework/utils.dart';
|
||||
|
||||
|
||||
TaskFunction createPlatformServiceDriverTest() {
|
||||
return new DriverTest(
|
||||
'${flutterDirectory.path}/examples/platform_services',
|
||||
'test_driver/button_tap.dart',
|
||||
);
|
||||
}
|
||||
|
||||
TaskFunction createComplexLayoutScrollPerfTest() {
|
||||
return new PerfTest(
|
||||
'${flutterDirectory.path}/dev/benchmarks/complex_layout',
|
||||
|
@ -152,6 +160,39 @@ class PerfTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class DriverTest {
|
||||
|
||||
DriverTest(this.testDirectory, this.testTarget);
|
||||
|
||||
final String testDirectory;
|
||||
final String testTarget;
|
||||
|
||||
Future<TaskResult> call() {
|
||||
return inDirectory(testDirectory, () async {
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
final String deviceId = device.deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
|
||||
// This causes an Xcode project to be created.
|
||||
await flutter('build', options: <String>['ios', '--profile']);
|
||||
}
|
||||
|
||||
await flutter('drive', options: <String>[
|
||||
'-v',
|
||||
'-t',
|
||||
testTarget,
|
||||
'-d',
|
||||
deviceId,
|
||||
]);
|
||||
|
||||
return new TaskResult.success(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class BuildTest {
|
||||
|
||||
BuildTest(this.testDirectory);
|
||||
|
|
|
@ -83,6 +83,12 @@ tasks:
|
|||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
|
||||
platform_services_test:
|
||||
description: >
|
||||
Runs a driver test on the Platform Services sample app on Android.
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
|
||||
flutter_gallery__start_up:
|
||||
description: >
|
||||
Measures the startup time of the Flutter Gallery app on Android.
|
||||
|
@ -138,9 +144,14 @@ tasks:
|
|||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
|
||||
|
||||
# iOS on-device tests
|
||||
|
||||
platform_services_test_ios:
|
||||
description: >
|
||||
Runs a driver test on the Platform Services sample app on iOS.
|
||||
stage: devicelab_ios
|
||||
required_agent_capabilities: ["has-ios-device"]
|
||||
|
||||
complex_layout_scroll_perf_ios__timeline_summary:
|
||||
description: >
|
||||
Measures the runtime performance of the Complex Layout sample app on
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue