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:
committed by
Facebook GitHub Bot
parent
f515df1c01
commit
52b3edc5ad
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user