@applitools/spec-driver-webdriver 1.0.55 → 1.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.57](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-webdriver@1.0.56...js/spec-driver-webdriver@1.0.57) (2024-02-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fixed issue with cdp commands on chromium browsers ([#2180](https://github.com/applitools/eyes.sdk.javascript1/issues/2180)) ([550fc77](https://github.com/applitools/eyes.sdk.javascript1/commit/550fc772d3988aae29e6f4a1a11d2a408072dc38))
9
+
10
+ ## [1.0.56](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-webdriver@1.0.55...js/spec-driver-webdriver@1.0.56) (2024-02-06)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * avoid error when extracting driver capabilities ([#2176](https://github.com/applitools/eyes.sdk.javascript1/issues/2176)) ([8971f1c](https://github.com/applitools/eyes.sdk.javascript1/commit/8971f1c07a73c1259e117c5c3c8d43d1d324c584))
16
+
3
17
  ## [1.0.55](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-webdriver@1.0.54...js/spec-driver-webdriver@1.0.55) (2024-01-30)
4
18
 
5
19
 
@@ -74,16 +74,6 @@ function extractEnvironment(capabilities) {
74
74
  isW3C,
75
75
  };
76
76
  }
77
- function command(method, url, body) {
78
- if (getFrameworkMajorVersion() < 8) {
79
- const { default: command } = require('webdriver/build/command');
80
- return command(method, url, body);
81
- }
82
- else {
83
- const { command } = require('webdriver');
84
- return command(method, url, body);
85
- }
86
- }
87
77
  function getFrameworkMajorVersion() {
88
78
  const version = require('webdriver/package.json').version;
89
79
  return Number.parseInt(version);
@@ -144,89 +134,90 @@ function isStaleElementError(error) {
144
134
  exports.isStaleElementError = isStaleElementError;
145
135
  function toDriver(driver) {
146
136
  var _a, _b, _c;
147
- if (!utils.types.has(driver, ['sessionId', 'serverUrl']))
148
- return driver;
149
- const url = new URL(driver.serverUrl);
150
- const environment = extractEnvironment(driver.capabilities);
151
- const options = {
152
- sessionId: driver.sessionId,
153
- protocol: url.protocol ? url.protocol.replace(/:$/, '') : undefined,
154
- hostname: url.hostname,
155
- port: Number(url.port) || undefined,
156
- path: url.pathname,
157
- capabilities: driver.capabilities,
158
- logLevel: 'silent',
159
- ...environment,
160
- };
161
- if (!options.port) {
162
- if (options.protocol === 'http')
163
- options.port = 80;
164
- if (options.protocol === 'https')
165
- options.port = 443;
137
+ let transformedDriver;
138
+ if (utils.types.has(driver, ['sessionId', 'serverUrl'])) {
139
+ const url = new URL(driver.serverUrl);
140
+ const environment = extractEnvironment(driver.capabilities);
141
+ const options = {
142
+ sessionId: driver.sessionId,
143
+ protocol: url.protocol ? url.protocol.replace(/:$/, '') : undefined,
144
+ hostname: url.hostname,
145
+ port: Number(url.port) || undefined,
146
+ path: url.pathname,
147
+ capabilities: driver.capabilities,
148
+ logLevel: 'silent',
149
+ ...environment,
150
+ };
151
+ if (!options.port) {
152
+ if (options.protocol === 'http')
153
+ options.port = 80;
154
+ if (options.protocol === 'https')
155
+ options.port = 443;
156
+ }
157
+ if ((_a = driver.proxy) === null || _a === void 0 ? void 0 : _a.url) {
158
+ const proxyUrl = new URL(driver.proxy.url);
159
+ proxyUrl.username = (_b = driver.proxy.username) !== null && _b !== void 0 ? _b : proxyUrl.username;
160
+ proxyUrl.password = (_c = driver.proxy.password) !== null && _c !== void 0 ? _c : proxyUrl.password;
161
+ const proxyOptions = { ...(0, url_1.parse)(proxyUrl.href), rejectUnauthorized: false };
162
+ const httpAgent = (0, http_proxy_agent_1.default)(proxyOptions);
163
+ const httpsAgent = (0, https_proxy_agent_1.default)(proxyOptions);
164
+ httpsAgent.callback = utils.general.wrap(httpsAgent.callback.bind(httpsAgent), (fn, request, options, ...rest) => {
165
+ return fn(request, { ...options, rejectUnauthorized: false }, ...rest);
166
+ });
167
+ options.agent = { http: httpAgent, https: httpsAgent };
168
+ }
169
+ else {
170
+ const httpAgent = http_1.default.globalAgent;
171
+ const httpsAgent = new https_1.default.Agent({ rejectUnauthorized: false });
172
+ options.agent = { http: httpAgent, https: httpsAgent };
173
+ }
174
+ const WebDriver = getWebDriver();
175
+ transformedDriver = WebDriver.attachToSession(options);
176
+ transformedDriver.original = driver.original;
166
177
  }
167
- if ((_a = driver.proxy) === null || _a === void 0 ? void 0 : _a.url) {
168
- const proxyUrl = new URL(driver.proxy.url);
169
- proxyUrl.username = (_b = driver.proxy.username) !== null && _b !== void 0 ? _b : proxyUrl.username;
170
- proxyUrl.password = (_c = driver.proxy.password) !== null && _c !== void 0 ? _c : proxyUrl.password;
171
- const proxyOptions = { ...(0, url_1.parse)(proxyUrl.href), rejectUnauthorized: false };
172
- const httpAgent = (0, http_proxy_agent_1.default)(proxyOptions);
173
- const httpsAgent = (0, https_proxy_agent_1.default)(proxyOptions);
174
- httpsAgent.callback = utils.general.wrap(httpsAgent.callback.bind(httpsAgent), (fn, request, options, ...rest) => {
175
- return fn(request, { ...options, rejectUnauthorized: false }, ...rest);
178
+ else {
179
+ // NOTE: this is needed to a rare case when this function is used not on the SecondaryDriver but on a derivative of the Driver
180
+ transformedDriver = Object.create(driver, {
181
+ original: { enumerable: false, get: () => driver },
176
182
  });
177
- options.agent = { http: httpAgent, https: httpsAgent };
178
183
  }
179
- else {
180
- const httpAgent = http_1.default.globalAgent;
181
- const httpsAgent = new https_1.default.Agent({ rejectUnauthorized: false });
182
- options.agent = { http: httpAgent, https: httpsAgent };
184
+ if (utils.types.isFunction(transformedDriver, 'addCommand')) {
185
+ const command = getFrameworkMajorVersion() < 8 ? require('webdriver/build/command').default : require('webdriver').command;
186
+ transformedDriver.addCommand('_getWindowSize', command('GET', '/session/:sessionId/window/current/size', {
187
+ command: '_getWindowSize',
188
+ description: '',
189
+ ref: '',
190
+ parameters: [],
191
+ }));
192
+ transformedDriver.addCommand('_setWindowSize', command('POST', '/session/:sessionId/window/current/size', {
193
+ command: '_setWindowSize',
194
+ parameters: [
195
+ { name: 'width', type: 'number', required: true, description: '' },
196
+ { name: 'height', type: 'number', required: true, description: '' },
197
+ ],
198
+ description: '',
199
+ ref: '',
200
+ }));
201
+ transformedDriver.addCommand('setWindowPosition', command('POST', '/session/:sessionId/window/current/position', {
202
+ command: 'setWindowPosition',
203
+ parameters: [
204
+ { name: 'x', type: 'number', required: true, description: '' },
205
+ { name: 'y', type: 'number', required: true, description: '' },
206
+ ],
207
+ description: '',
208
+ ref: '',
209
+ }));
210
+ transformedDriver.addCommand('sendCommandAndGetResult', command('POST', '/session/:sessionId/chromium/send_command_and_get_result', {
211
+ command: 'sendCommandAndGetResult',
212
+ parameters: [
213
+ { name: 'cmd', type: 'string', required: true, description: '' },
214
+ { name: 'params', type: 'object', required: true, description: '' },
215
+ ],
216
+ description: 'Send a command to the DevTools debugger and wait for the result.',
217
+ ref: '',
218
+ }));
183
219
  }
184
- const WebDriver = getWebDriver();
185
- const attachedDriver = WebDriver.attachToSession(options, undefined, {
186
- _getWindowSize: {
187
- value: command('GET', '/session/:sessionId/window/current/size', {
188
- command: '_getWindowSize',
189
- description: '',
190
- ref: '',
191
- parameters: [],
192
- }),
193
- },
194
- _setWindowSize: {
195
- value: command('POST', '/session/:sessionId/window/current/size', {
196
- command: '_setWindowSize',
197
- parameters: [
198
- { name: 'width', type: 'number', required: true, description: '' },
199
- { name: 'height', type: 'number', required: true, description: '' },
200
- ],
201
- description: '',
202
- ref: '',
203
- }),
204
- },
205
- setWindowPosition: {
206
- value: command('POST', '/session/:sessionId/window/current/position', {
207
- command: 'setWindowPosition',
208
- parameters: [
209
- { name: 'x', type: 'number', required: true, description: '' },
210
- { name: 'y', type: 'number', required: true, description: '' },
211
- ],
212
- description: '',
213
- ref: '',
214
- }),
215
- },
216
- sendCommandAndGetResult: {
217
- value: command('POST', '/session/:sessionId/chromium/send_command_and_get_result', {
218
- command: 'sendCommandAndGetResult',
219
- parameters: [
220
- { name: 'cmd', type: 'string', required: true, description: '' },
221
- { name: 'params', type: 'object', required: true, description: '' },
222
- ],
223
- description: 'Send a command to the DevTools debugger and wait for the result.',
224
- ref: '',
225
- }),
226
- },
227
- });
228
- attachedDriver.original = driver.original;
229
- return attachedDriver;
220
+ return transformedDriver;
230
221
  }
231
222
  exports.toDriver = toDriver;
232
223
  function toElement(element) {
@@ -346,15 +337,8 @@ async function getDriverInfo(driver) {
346
337
  exports.getDriverInfo = getDriverInfo;
347
338
  async function getCapabilities(driver) {
348
339
  var _a;
349
- try {
350
- const capabilities = await ((_a = driver.getSession) === null || _a === void 0 ? void 0 : _a.call(driver));
351
- return utils.types.isObject(capabilities) ? capabilities : driver.capabilities;
352
- }
353
- catch (error) {
354
- if (/Cannot call non W3C standard command while in W3C mode/i.test(error.message))
355
- return driver.capabilities;
356
- throw new Error(`Unable to retrieve capabilities due to an error. The original error is ${error.message}`);
357
- }
340
+ const capabilities = await ((_a = driver.getSession) === null || _a === void 0 ? void 0 : _a.call(driver).catch(() => null));
341
+ return utils.types.isObject(capabilities) ? capabilities : driver.capabilities;
358
342
  }
359
343
  exports.getCapabilities = getCapabilities;
360
344
  async function getWindowSize(driver) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/spec-driver-webdriver",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "keywords": [
5
5
  "webdriver",
6
6
  "chrome devtools protocol",