UNPKG

webdriverio

Version:

Next-gen browser and mobile automation test framework for Node.js

70 lines (53 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _utils = require("@wdio/utils"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const WARN_ON_COMMANDS = ['addCommand', 'overwriteCommand']; class ProtocolStub { static async newSession(options = {}) { const capabilities = emulateSessionCapabilities(options.capabilities || {}); const browser = addCommands(_objectSpread({ capabilities }, (0, _utils.capabilitiesEnvironmentDetector)(capabilities, options._automationProtocol))); return browser; } static reloadSession() { throw new Error('Protocol Stub: Make sure to start webdriver or devtools session before reloading it.'); } static attachToSession(options, modifier) { if (options || !modifier) { return ProtocolStub.newSession(options); } return addCommands(modifier({ commandList: [] })); } } exports.default = ProtocolStub; function addCommands(browser) { WARN_ON_COMMANDS.forEach(commandName => { browser[commandName] = commandNotAvailable(commandName); }); return browser; } function emulateSessionCapabilities(caps) { const capabilities = {}; Object.entries(caps).forEach(([key, value]) => { const newKey = key.replace('appium:', ''); capabilities[newKey] = value; }); if (caps.browserName && caps.browserName.toLowerCase() === 'chrome') { capabilities.chrome = true; } return capabilities; } function commandNotAvailable(commandName) { return () => { throw new Error(`Unable to use '${commandName}' before browser session is started.`); }; }