Skip to content

Commit c559443

Browse files
jmagmanmingwandroid
authored andcommitted
Take screenshots of wirelessly paired iOS devices (flutter#60623)
1 parent aac1e6a commit c559443

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

packages/flutter_tools/lib/src/ios/devices.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ class IOSDevice extends Device {
509509
void clearLogs() { }
510510

511511
@override
512-
bool get supportsScreenshot => _iMobileDevice.isInstalled && interfaceType == IOSDeviceInterface.usb;
512+
bool get supportsScreenshot => _iMobileDevice.isInstalled;
513513

514514
@override
515515
Future<void> takeScreenshot(File outputFile) async {
516-
await _iMobileDevice.takeScreenshot(outputFile, id);
516+
await _iMobileDevice.takeScreenshot(outputFile, id, interfaceType);
517517
}
518518

519519
@override

packages/flutter_tools/lib/src/ios/mac.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import '../macos/xcode.dart';
2424
import '../project.dart';
2525
import '../reporting/reporting.dart';
2626
import 'code_signing.dart';
27+
import 'devices.dart';
2728
import 'migrations/ios_migrator.dart';
2829
import 'migrations/project_base_configuration_migration.dart';
2930
import 'migrations/remove_framework_link_and_embedding_migration.dart';
@@ -66,13 +67,19 @@ class IMobileDevice {
6667
}
6768

6869
/// Captures a screenshot to the specified outputFile.
69-
Future<void> takeScreenshot(File outputFile, String deviceID) {
70+
Future<void> takeScreenshot(
71+
File outputFile,
72+
String deviceID,
73+
IOSDeviceInterface interfaceType,
74+
) {
7075
return _processUtils.run(
7176
<String>[
7277
_idevicescreenshotPath,
7378
outputFile.path,
7479
'--udid',
7580
deviceID,
81+
if (interfaceType == IOSDeviceInterface.network)
82+
'--network',
7683
],
7784
throwOnError: true,
7885
environment: Map<String, String>.fromEntries(

packages/flutter_tools/test/general.shard/ios/mac_test.dart

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/base/platform.dart';
1414
import 'package:flutter_tools/src/base/process.dart';
1515
import 'package:flutter_tools/src/cache.dart';
1616
import 'package:flutter_tools/src/globals.dart' as globals;
17+
import 'package:flutter_tools/src/ios/devices.dart';
1718
import 'package:flutter_tools/src/ios/mac.dart';
1819
import 'package:flutter_tools/src/ios/xcodeproj.dart';
1920
import 'package:flutter_tools/src/project.dart';
@@ -85,10 +86,14 @@ void main() {
8586
logger: logger,
8687
);
8788

88-
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile, '1234'), throwsA(anything));
89+
expect(() async => await iMobileDevice.takeScreenshot(
90+
mockOutputFile,
91+
'1234',
92+
IOSDeviceInterface.usb,
93+
), throwsA(anything));
8994
});
9095

91-
testWithoutContext('idevicescreenshot captures and returns screenshot', () async {
96+
testWithoutContext('idevicescreenshot captures and returns USB screenshot', () async {
9297
when(mockOutputFile.path).thenReturn(outputPath);
9398
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
9499
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
@@ -100,12 +105,39 @@ void main() {
100105
logger: logger,
101106
);
102107

103-
await iMobileDevice.takeScreenshot(mockOutputFile, '1234');
108+
await iMobileDevice.takeScreenshot(
109+
mockOutputFile,
110+
'1234',
111+
IOSDeviceInterface.usb,
112+
);
104113
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath, '--udid', '1234'],
105114
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
106115
workingDirectory: null,
107116
));
108117
});
118+
119+
testWithoutContext('idevicescreenshot captures and returns network screenshot', () async {
120+
when(mockOutputFile.path).thenReturn(outputPath);
121+
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
122+
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
123+
124+
final IMobileDevice iMobileDevice = IMobileDevice(
125+
artifacts: mockArtifacts,
126+
cache: mockCache,
127+
processManager: mockProcessManager,
128+
logger: logger,
129+
);
130+
131+
await iMobileDevice.takeScreenshot(
132+
mockOutputFile,
133+
'1234',
134+
IOSDeviceInterface.network,
135+
);
136+
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath, '--udid', '1234', '--network'],
137+
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
138+
workingDirectory: null,
139+
));
140+
});
109141
});
110142
});
111143

0 commit comments

Comments
 (0)