1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _utils = require("@wdio/utils");
|
9 |
|
10 | 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; }
|
11 |
|
12 | 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; }
|
13 |
|
14 | 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; }
|
15 |
|
16 | const WARN_ON_COMMANDS = ['addCommand', 'overwriteCommand'];
|
17 |
|
18 | class ProtocolStub {
|
19 | static async newSession(options = {}) {
|
20 | const capabilities = emulateSessionCapabilities(options.capabilities || {});
|
21 | const browser = addCommands(_objectSpread({
|
22 | capabilities
|
23 | }, (0, _utils.capabilitiesEnvironmentDetector)(capabilities, options._automationProtocol)));
|
24 | return browser;
|
25 | }
|
26 |
|
27 | static reloadSession() {
|
28 | throw new Error('Protocol Stub: Make sure to start webdriver or devtools session before reloading it.');
|
29 | }
|
30 |
|
31 | static attachToSession(options, modifier) {
|
32 | if (options || !modifier) {
|
33 | return ProtocolStub.newSession(options);
|
34 | }
|
35 |
|
36 | return addCommands(modifier({
|
37 | commandList: []
|
38 | }));
|
39 | }
|
40 |
|
41 | }
|
42 |
|
43 | exports.default = ProtocolStub;
|
44 |
|
45 | function addCommands(browser) {
|
46 | WARN_ON_COMMANDS.forEach(commandName => {
|
47 | browser[commandName] = commandNotAvailable(commandName);
|
48 | });
|
49 | return browser;
|
50 | }
|
51 |
|
52 | function emulateSessionCapabilities(caps) {
|
53 | const capabilities = {};
|
54 | Object.entries(caps).forEach(([key, value]) => {
|
55 | const newKey = key.replace('appium:', '');
|
56 | capabilities[newKey] = value;
|
57 | });
|
58 |
|
59 | if (caps.browserName && caps.browserName.toLowerCase() === 'chrome') {
|
60 | capabilities.chrome = true;
|
61 | }
|
62 |
|
63 | return capabilities;
|
64 | }
|
65 |
|
66 | function commandNotAvailable(commandName) {
|
67 | return () => {
|
68 | throw new Error(`Unable to use '${commandName}' before browser session is started.`);
|
69 | };
|
70 | } |
\ | No newline at end of file |