Take screenshot on devicelab failure (#122249)
Take screenshot on devicelab failure
This commit is contained in:
parent
a599c08c32
commit
e2e313ecf6
@ -252,10 +252,14 @@ Future<void> main() async {
|
||||
section('gradlew on build script with error');
|
||||
await project.introduceError();
|
||||
ProcessResult result = await inDirectory(project.rootPath, () {
|
||||
return executeFlutter('build', options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
]);
|
||||
return executeFlutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
],
|
||||
canFail: true,
|
||||
);
|
||||
});
|
||||
|
||||
if (result.exitCode == 0) {
|
||||
@ -278,10 +282,14 @@ Future<void> main() async {
|
||||
section('flutter build apk on build script with error');
|
||||
await project.introduceError();
|
||||
result = await inDirectory(project.rootPath, () {
|
||||
return executeFlutter('build', options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
]);
|
||||
return executeFlutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
],
|
||||
canFail: true,
|
||||
);
|
||||
});
|
||||
if (result.exitCode == 0) {
|
||||
throw failure(
|
||||
@ -304,10 +312,14 @@ Future<void> main() async {
|
||||
section('gradlew assembleDebug forwards stderr');
|
||||
await project.introducePubspecError();
|
||||
final ProcessResult result = await inDirectory(project.rootPath, () {
|
||||
return executeFlutter('build', options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
]);
|
||||
return executeFlutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'apk',
|
||||
'--release',
|
||||
],
|
||||
canFail: true,
|
||||
);
|
||||
});
|
||||
if (result.exitCode == 0) {
|
||||
throw failure(
|
||||
|
@ -471,10 +471,15 @@ Future<int> flutter(String command, {
|
||||
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
|
||||
Map<String, String>? environment,
|
||||
String? workingDirectory,
|
||||
}) {
|
||||
}) async {
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
final int exitCode = await exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment, workingDirectory: workingDirectory);
|
||||
|
||||
if (exitCode != 0 && !canFail) {
|
||||
await _flutterScreenshot(workingDirectory: workingDirectory);
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
/// Starts a Flutter subprocess.
|
||||
@ -506,13 +511,20 @@ Future<Process> startFlutter(String command, {
|
||||
String? workingDirectory,
|
||||
}) async {
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return startProcess(
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
args,
|
||||
environment: environment,
|
||||
isBot: isBot,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
unawaited(process.exitCode.then<void>((int exitCode) async {
|
||||
if (exitCode != 0) {
|
||||
await _flutterScreenshot(workingDirectory: workingDirectory);
|
||||
}
|
||||
}));
|
||||
return process;
|
||||
}
|
||||
|
||||
/// Runs a `flutter` command and returns the standard output as a string.
|
||||
@ -530,12 +542,53 @@ Future<String> evalFlutter(String command, {
|
||||
|
||||
Future<ProcessResult> executeFlutter(String command, {
|
||||
List<String> options = const <String>[],
|
||||
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
|
||||
}) async {
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return _processManager.run(
|
||||
final ProcessResult processResult = await _processManager.run(
|
||||
<String>[path.join(flutterDirectory.path, 'bin', 'flutter'), ...args],
|
||||
workingDirectory: cwd,
|
||||
);
|
||||
|
||||
if (processResult.exitCode != 0 && !canFail) {
|
||||
await _flutterScreenshot();
|
||||
}
|
||||
return processResult;
|
||||
}
|
||||
|
||||
Future<void> _flutterScreenshot({ String? workingDirectory }) async {
|
||||
try {
|
||||
final Directory? dumpDirectory = hostAgent.dumpDirectory;
|
||||
if (dumpDirectory == null) {
|
||||
return;
|
||||
}
|
||||
// On command failure try uploading screenshot of failing command.
|
||||
final String screenshotPath = path.join(
|
||||
dumpDirectory.path,
|
||||
'device-screenshot-${DateTime.now().toLocal().toIso8601String()}.png',
|
||||
);
|
||||
|
||||
final String deviceId = (await devices.workingDevice).deviceId;
|
||||
print('Taking screenshot of working device $deviceId at $screenshotPath');
|
||||
final List<String> args = _flutterCommandArgs(
|
||||
'screenshot',
|
||||
<String>[
|
||||
'--out',
|
||||
screenshotPath,
|
||||
'-d', deviceId,
|
||||
],
|
||||
);
|
||||
final ProcessResult screenshot = await _processManager.run(
|
||||
<String>[path.join(flutterDirectory.path, 'bin', 'flutter'), ...args],
|
||||
workingDirectory: workingDirectory ?? cwd,
|
||||
);
|
||||
|
||||
if (screenshot.exitCode != 0) {
|
||||
print('Failed to take screenshot. Continuing.');
|
||||
}
|
||||
} catch (exception) {
|
||||
print('Failed to take screenshot. Continuing.\n$exception');
|
||||
}
|
||||
}
|
||||
|
||||
String get dartBin =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user