screenshot method

  1. @override
Future<ScreenshotResult> screenshot(
  1. String path
)
override

Capture a PNG to path for device-mode perception; also the coordinate reference (ratio = pixel / size).

Implementation

@override
Future<ScreenshotResult> screenshot(String path) async {
  final res = await runBounded(
    'xcrun',
    ['simctl', 'io', udid, 'screenshot', path],
    timeout: const Duration(seconds: 10),
    phase: 'simctl screenshot',
  );
  if (res.exitCode != 0) {
    return ScreenshotResult(
      error: ((res.stderr as String?) ?? '').trim().isEmpty
          ? 'simctl screenshot exited ${res.exitCode}'
          : (res.stderr as String).trim(),
    );
  }
  final size = pngSize(path);
  return ScreenshotResult(path: path, width: size?.$1, height: size?.$2);
}