Rocket.Chat.ReactNative/e2e/helpers/screenshot.js

24 lines
610 B
JavaScript
Raw Normal View History

2018-05-23 13:39:18 +00:00
const { execSync } = require('child_process');
const { existsSync, mkdirSync } = require('fs');
const SCREENSHOT_DIR = '/tmp/screenshots';
const SCREENSHOT_OPTIONS = {
timeout: 2000,
killSignal: 'SIGKILL'
};
let screenshotIndex = 0;
const takeScreenshot = () => {
if (!existsSync(SCREENSHOT_DIR)) { mkdirSync(SCREENSHOT_DIR); }
const screenshotFilename = `${ SCREENSHOT_DIR }/screenshot-${ screenshotIndex++ }.png`;
try {
execSync(`xcrun simctl io booted screenshot ${ screenshotFilename }`, SCREENSHOT_OPTIONS);
} catch (error) {
console.log('erro');
}
};
module.exports = { takeScreenshot };