forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrome_driver.dart
More file actions
50 lines (41 loc) · 1.63 KB
/
chrome_driver.dart
File metadata and controls
50 lines (41 loc) · 1.63 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
// Copyright 2023 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
// ignore_for_file: avoid_print
import 'dart:io';
import 'io_utils.dart';
class ChromeDriver with IOMixin {
Process? _process;
// TODO(kenz): add error messaging if the chromedriver executable is not
// found. We can also consider using web installers directly in this script:
// https://github.com/flutter/flutter/blob/master/docs/contributing/testing/Running-Flutter-Driver-tests-with-Web.md#web-installers-repo.
Future<void> start({bool debugLogging = false}) async {
try {
const chromedriverExe = 'chromedriver';
const chromedriverArgs = ['--port=4444'];
if (debugLogging) {
print('${DateTime.now()}: starting the chromedriver process');
print('${DateTime.now()}: > $chromedriverExe '
'${chromedriverArgs.join(' ')}');
}
final process = _process = await Process.start(
chromedriverExe,
chromedriverArgs,
);
listenToProcessOutput(process, printTag: 'ChromeDriver');
} catch (e) {
// ignore: avoid-throw-in-catch-block, by design
throw Exception('Error starting chromedriver: $e');
}
}
Future<void> stop({bool debugLogging = false}) async {
final process = _process;
_process = null;
if (process == null) return;
await cancelAllStreamSubscriptions();
if (debugLogging) {
print('${DateTime.now()}: killing the chromedriver process');
}
await killGracefully(process, debugLogging: debugLogging);
}
}