foreignSurface method
Reads system alerts first: that read never waits on the app, so an alert that blocks the app ("Allow Paste") is still seen; the app's own tree is read only when there is none.
Implementation
@override
Future<String?> foreignSurface() async {
try {
final system = await tree(null).timeout(readLimit);
final alerts = system['alerts'];
final app = bundleId() ?? await frontmost?.call().timeout(readLimit);
if ((alerts is List && alerts.isNotEmpty) || app == null) return _take(system, app);
return _take(await tree(app).timeout(readLimit), app);
} on Object catch (e) {
lastReadProblem = 'the XCTest runner could not be read: $e';
lastSurfaceName = null;
_surface = const [];
_appState = null;
return null;
}
}