UNPKG

wdio-iedriver-service

Version:
109 lines (83 loc) 3.99 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _iedriver = require('iedriver'); var _iedriver2 = _interopRequireDefault(_iedriver); var _fsExtra = require('fs-extra'); var _fsExtra2 = _interopRequireDefault(_fsExtra); var _getFilePath = require('./utils/getFilePath'); var _getFilePath2 = _interopRequireDefault(_getFilePath); var _child_process = require('child_process'); var _child_process2 = _interopRequireDefault(_child_process); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var binPath = _iedriver2.default.path; var DEFAULT_LOG_FILENAME = 'IEDriver.txt'; var IEDriverLauncher = function () { function IEDriverLauncher() { _classCallCheck(this, IEDriverLauncher); this.ieDriverLogs = null; this.ieDriverArgs = {}; this.logToStdout = false; this.killInstances = false; } _createClass(IEDriverLauncher, [{ key: 'onPrepare', value: function onPrepare(config) { var _this = this; this.ieDriverArgs = config.ieDriverArgs || {}; this.ieDriverLogs = config.ieDriverLogs; this.logToStdout = config.logToStdout; this.killInstances = config.killInstances; return new Promise(function (resolve, reject) { _this.process = _child_process2.default.execFile(binPath, [], function (err, stdout, stderr) { if (err) { console.log('Error in process: ' + err); return reject(err); } }); if (_this.process) { if (typeof _this.ieDriverLogs === 'string') { _this._redirectLogStream(); } resolve(); } }); } }, { key: 'onComplete', value: function onComplete() { var _this2 = this; return new Promise(function (resolve, reject) { if (_this2.process) { if (_this2.killInstances === true) { var killer = _child_process2.default.spawn('taskkill', ['/F', '/IM', 'iexplore.exe']); killer.on('close', function (code) { _this2.process.kill(); resolve(); }); } else { _this2.process.kill(); resolve(); } } else { reject('Process not started'); } }); } }, { key: '_redirectLogStream', value: function _redirectLogStream() { var logFile = (0, _getFilePath2.default)(this.ieDriverLogs, DEFAULT_LOG_FILENAME); // ensure file & directory exists _fsExtra2.default.ensureFileSync(logFile); var logStream = _fsExtra2.default.createWriteStream(logFile, { flags: 'w' }); this.process.stdout.pipe(logStream); this.process.stderr.pipe(logStream); } }]); return IEDriverLauncher; }(); exports.default = IEDriverLauncher;