Support screencaps/recordings from multiple devices

Summary:
We've been using "booted" as a shortcut to select a device in `xcrun` but that will only refer to the *first* booted simulator. If you have multiple ones, that causes screenshots, videos and logs to always be pulled from the first.

Of course, this isn't documented anywhere, because Apple, but you can instead of `booted` pass in the "UDID" and refer to a specific device in all cases.

Reviewed By: nikoant

Differential Revision: D24627077

fbshipit-source-id: 2a52a8a17776746af4b3f6ca821dcce37bb0f7c2
This commit is contained in:
Pascal Hartig
2020-10-30 05:43:10 -07:00
committed by Facebook GitHub Bot
parent aef3672235
commit 9d5ca7de87

View File

@@ -58,7 +58,7 @@ export default class IOSDevice extends BaseDevice {
const tmpFilePath = path.join(tmpDirectory, tmpImageName); const tmpFilePath = path.join(tmpDirectory, tmpImageName);
const command = const command =
this.deviceType === 'emulator' this.deviceType === 'emulator'
? `xcrun simctl io booted screenshot ${tmpFilePath}` ? `xcrun simctl io ${this.serial} screenshot ${tmpFilePath}`
: `idb screenshot --udid ${this.serial} ${tmpFilePath}`; : `idb screenshot --udid ${this.serial} ${tmpFilePath}`;
return promisify(exec)(command) return promisify(exec)(command)
.then(() => promisify(fs.readFile)(tmpFilePath)) .then(() => promisify(fs.readFile)(tmpFilePath))
@@ -68,7 +68,7 @@ export default class IOSDevice extends BaseDevice {
} }
navigateToLocation(location: string) { navigateToLocation(location: string) {
const command = `xcrun simctl openurl booted "${location}"`; const command = `xcrun simctl openurl ${this.serial} "${location}"`;
exec(command); exec(command);
} }
@@ -97,7 +97,7 @@ export default class IOSDevice extends BaseDevice {
'simctl', 'simctl',
...deviceSetPath, ...deviceSetPath,
'spawn', 'spawn',
'booted', this.serial,
'log', 'log',
'stream', 'stream',
'--style', '--style',
@@ -185,7 +185,7 @@ export default class IOSDevice extends BaseDevice {
async startScreenCapture(destination: string) { async startScreenCapture(destination: string) {
this.recordingProcess = exec( this.recordingProcess = exec(
`xcrun simctl io booted recordVideo --codec=h264 --force ${destination}`, `xcrun simctl io ${this.serial} recordVideo --codec=h264 --force ${destination}`,
); );
this.recordingLocation = destination; this.recordingLocation = destination;
} }