1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.multiremote = exports.attach = exports.remote = void 0;
|
7 |
|
8 | var _path = _interopRequireDefault(require("path"));
|
9 |
|
10 | var _webdriver = _interopRequireDefault(require("webdriver"));
|
11 |
|
12 | var _logger = _interopRequireDefault(require("@wdio/logger"));
|
13 |
|
14 | var _config = require("@wdio/config");
|
15 |
|
16 | var _utils = require("@wdio/utils");
|
17 |
|
18 | var _multiremote = _interopRequireDefault(require("./multiremote"));
|
19 |
|
20 | var _constants = require("./constants");
|
21 |
|
22 | var _utils2 = require("./utils");
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | 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; }
|
27 |
|
28 | 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; }
|
29 |
|
30 | 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; }
|
31 |
|
32 | const log = (0, _logger.default)('webdriverio');
|
33 |
|
34 | const remote = async function (params = {}, remoteModifier) {
|
35 | _logger.default.setLogLevelsConfig(params.logLevels, params.logLevel);
|
36 |
|
37 | const config = (0, _config.validateConfig)(_constants.WDIO_DEFAULTS, params, Object.keys(_webdriver.default.DEFAULTS));
|
38 | const automationProtocol = await (0, _utils2.getAutomationProtocol)(config);
|
39 |
|
40 | const modifier = (client, options) => {
|
41 | Object.assign(options, Object.entries(config).reduce((a, [k, v]) => v == null ? a : _objectSpread({}, a, {
|
42 | [k]: v
|
43 | }), {}));
|
44 |
|
45 | if (typeof remoteModifier === 'function') {
|
46 | client = remoteModifier(client, options);
|
47 | }
|
48 |
|
49 | options.automationProtocol = automationProtocol;
|
50 | return client;
|
51 | };
|
52 |
|
53 | if (params.user && params.key) {
|
54 | params = Object.assign({}, (0, _config.detectBackend)(params), params);
|
55 | }
|
56 |
|
57 | if (params.outputDir) {
|
58 | process.env.WDIO_LOG_PATH = _path.default.join(params.outputDir, 'wdio.log');
|
59 | }
|
60 |
|
61 | const prototype = (0, _utils2.getPrototype)('browser');
|
62 | log.info(`Initiate new session using the ${automationProtocol} protocol`);
|
63 |
|
64 | const ProtocolDriver = require(automationProtocol).default;
|
65 |
|
66 | const instance = await ProtocolDriver.newSession(params, modifier, prototype, _utils.wrapCommand);
|
67 |
|
68 | if (params.runner && !(0, _utils2.isStub)(automationProtocol)) {
|
69 | const origAddCommand = instance.addCommand.bind(instance);
|
70 |
|
71 | instance.addCommand = (name, fn, attachToElement) => origAddCommand(name, (0, _utils.runFnInFiberContext)(fn), attachToElement);
|
72 |
|
73 | const origOverwriteCommand = instance.overwriteCommand.bind(instance);
|
74 |
|
75 | instance.overwriteCommand = (name, fn, attachToElement) => origOverwriteCommand(name, (0, _utils.runFnInFiberContext)(fn), attachToElement);
|
76 | }
|
77 |
|
78 | instance.addLocatorStrategy = (0, _utils2.addLocatorStrategyHandler)(instance);
|
79 | return instance;
|
80 | };
|
81 |
|
82 | exports.remote = remote;
|
83 |
|
84 | const attach = function (params) {
|
85 | const prototype = (0, _utils2.getPrototype)('browser');
|
86 | return _webdriver.default.attachToSession(params, null, prototype, _utils.wrapCommand);
|
87 | };
|
88 |
|
89 | exports.attach = attach;
|
90 |
|
91 | const multiremote = async function (params = {}, config = {}) {
|
92 | const multibrowser = new _multiremote.default();
|
93 | const browserNames = Object.keys(params);
|
94 | await Promise.all(browserNames.map(async browserName => {
|
95 | const instance = await remote(params[browserName]);
|
96 | return multibrowser.addInstance(browserName, instance);
|
97 | }));
|
98 | const prototype = (0, _utils2.getPrototype)('browser');
|
99 | const sessionParams = (0, _utils2.isStub)(config.automationProtocol) ? undefined : {
|
100 | sessionId: '',
|
101 | isW3C: multibrowser.instances[browserNames[0]].isW3C,
|
102 | logLevel: multibrowser.instances[browserNames[0]].options.logLevel
|
103 | };
|
104 | const ProtocolDriver = (0, _utils2.isStub)(config.automationProtocol) ? require(config.automationProtocol).default : _webdriver.default;
|
105 | const driver = ProtocolDriver.attachToSession(sessionParams, multibrowser.modifier.bind(multibrowser), prototype, _utils.wrapCommand);
|
106 |
|
107 | if (!(0, _utils2.isStub)(config.automationProtocol)) {
|
108 | const origAddCommand = driver.addCommand.bind(driver);
|
109 |
|
110 | driver.addCommand = (name, fn, attachToElement) => {
|
111 | origAddCommand(name, (0, _utils.runFnInFiberContext)(fn), attachToElement, Object.getPrototypeOf(multibrowser.baseInstance), multibrowser.instances);
|
112 | };
|
113 |
|
114 | const origOverwriteCommand = driver.overwriteCommand.bind(driver);
|
115 |
|
116 | driver.overwriteCommand = (name, fn, attachToElement) => {
|
117 | origOverwriteCommand(name, (0, _utils.runFnInFiberContext)(fn), attachToElement, Object.getPrototypeOf(multibrowser.baseInstance), multibrowser.instances);
|
118 | };
|
119 | }
|
120 |
|
121 | driver.addLocatorStrategy = (0, _utils2.addLocatorStrategyHandler)(driver);
|
122 | return driver;
|
123 | };
|
124 |
|
125 | exports.multiremote = multiremote; |
\ | No newline at end of file |