webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
45 lines (35 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getPuppeteer;
var _puppeteerCore = _interopRequireDefault(require("puppeteer-core"));
var _constants = require("../../constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function getPuppeteer() {
if (this.puppeteer) {
return this.puppeteer;
}
const chromiumOptions = this.capabilities['goog:chromeOptions'] || this.capabilities['ms:edgeOptions'];
if (chromiumOptions && chromiumOptions.debuggerAddress) {
this.puppeteer = await _puppeteerCore.default.connect({
browserURL: `http://${chromiumOptions.debuggerAddress}`,
defaultViewport: null
});
return this.puppeteer;
}
if (this.capabilities.browserName.toLowerCase() === 'firefox') {
const majorVersion = parseInt(this.capabilities.browserVersion.split('.').shift(), 10);
if (majorVersion >= 79) {
const ffOptions = this.capabilities['moz:firefoxOptions'];
const ffArgs = this.requestedCapabilities['moz:firefoxOptions'].args;
const rdPort = ffOptions && ffOptions.debuggerAddress ? ffOptions.debuggerAddress : ffArgs[ffArgs.findIndex(arg => arg === _constants.FF_REMOTE_DEBUG_ARG) + 1];
this.puppeteer = await _puppeteerCore.default.connect({
browserURL: `http://localhost:${rdPort}`,
defaultViewport: null
});
return this.puppeteer;
}
}
throw new Error('Using DevTools capabilities is not supported for this session. ' + 'This feature is only supported for local testing on Chrome, Firefox and Chromium Edge.');
}