Move screenshot to iOSBridge

Summary:
In order to support IOS cloud devices, we need to abstract
over the direct uses of idb/xcrun so we can switch them
out based on more than the device type.

Note that there's a bit of a type weirdness in there. I'll
clean this up with the next diff.

Reviewed By: mweststrate

Differential Revision: D30248036

fbshipit-source-id: ec8571429e04abe059850ef334a6645ae4a5e034
This commit is contained in:
Pascal Hartig
2021-08-11 11:02:10 -07:00
committed by Facebook GitHub Bot
parent f515df1c01
commit 52b3edc5ad
3 changed files with 66 additions and 19 deletions

View File

@@ -12,14 +12,10 @@ import child_process, {ChildProcess} from 'child_process';
import BaseDevice from './BaseDevice';
import JSONStream from 'JSONStream';
import {Transform} from 'stream';
import fs from 'fs-extra';
import {v1 as uuid} from 'uuid';
import path from 'path';
import {exec} from 'promisify-child-process';
import {default as promiseTimeout} from '../utils/promiseTimeout';
import {IOSBridge} from '../utils/IOSBridge';
import split2 from 'split2';
import {getAppTempPath} from '../utils/pathUtils';
type IOSLogLevel = 'Default' | 'Info' | 'Debug' | 'Error' | 'Fault';
@@ -67,19 +63,8 @@ export default class IOSDevice extends BaseDevice {
if (!this.connected.get()) {
return Buffer.from([]);
}
const tmpImageName = uuid() + '.png';
const tmpDirectory = getAppTempPath();
const tmpFilePath = path.join(tmpDirectory, tmpImageName);
const command =
this.deviceType === 'emulator'
? `xcrun simctl io ${this.serial} screenshot ${tmpFilePath}`
: `idb screenshot --udid ${this.serial} ${tmpFilePath}`;
return exec(command)
.then(() => fs.readFile(tmpFilePath))
.then(async (buffer) => {
await fs.unlink(tmpFilePath);
return buffer;
});
// HACK: Will restructure the types to allow for the ! to be removed.
return await this.iOSBridge.screenshot!(this.serial);
}
navigateToLocation(location: string) {