This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
integration_test.dart
66 lines (60 loc) · 1.68 KB
/
integration_test.dart
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
59
60
61
62
63
64
65
66
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: avoid_print
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';
const String _examplePackage = 'io.flutter.plugins.cameraexample';
Future<void> main() async {
if (!(Platform.isLinux || Platform.isMacOS)) {
print('This test must be run on a POSIX host. Skipping...');
exit(0);
}
final bool adbExists =
Process.runSync('which', <String>['adb']).exitCode == 0;
if (!adbExists) {
print(r'This test needs ADB to exist on the $PATH. Skipping...');
exit(0);
}
print('Granting camera permissions...');
Process.runSync('adb', <String>[
'shell',
'pm',
'grant',
_examplePackage,
'android.permission.CAMERA'
]);
Process.runSync('adb', <String>[
'shell',
'pm',
'grant',
_examplePackage,
'android.permission.RECORD_AUDIO'
]);
print('Starting test.');
final FlutterDriver driver = await FlutterDriver.connect();
final String data = await driver.requestData(
null,
timeout: const Duration(minutes: 1),
);
await driver.close();
print('Test finished. Revoking camera permissions...');
Process.runSync('adb', <String>[
'shell',
'pm',
'revoke',
_examplePackage,
'android.permission.CAMERA'
]);
Process.runSync('adb', <String>[
'shell',
'pm',
'revoke',
_examplePackage,
'android.permission.RECORD_AUDIO'
]);
final Map<String, dynamic> result = jsonDecode(data) as Map<String, dynamic>;
exit(result['result'] == 'true' ? 0 : 1);
}