app_test.dart
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() async {
FlutterDriver driver;
String bareTestingResult;
setUpAll(() async {
driver = await FlutterDriver.connect();
bareTestingResult =
await driver.requestData('', timeout: const Duration(minutes: 1));
});
tearDownAll(() => driver?.close());
group('example app', () {
test('wakelock is disabled at start', () async {
await driver._expectEnabled(isFalse);
});
test('enable wakelock', () async {
// Use the button in the example app instead of a direct plugin call.
await driver.tap(find.text('enable wakelock'));
await driver._expectEnabled(isTrue);
});
test('disable wakelock', () async {
// Use the button in the example app instead of a direct plugin call.
await driver.tap(find.text('disable wakelock'));
await driver._expectEnabled(isFalse);
});
});
test('wakelock bare platform testing', () async {
expect(bareTestingResult, equals('success'));
});
}
extension on FlutterDriver {
Future<bool> _finds(SerializableFinder finder) async {
try {
await waitFor(finder, timeout: const Duration(milliseconds: 420));
return true;
} catch (_) {
return false;
}
}
Future<void> _expectEnabled(Matcher matcher) async {
// Check the widget in the example app.
final result = await _finds(find.text(
'wakelock is currently ${matcher == isTrue ? 'enabled' : 'disabled'}'));
expect(result, isTrue);
}
}