@applitools/spec-driver-webdriver 1.0.41 → 1.0.42

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,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.42](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-webdriver@1.0.41...js/spec-driver-webdriver@1.0.42) (2023-08-18)
4
+
5
+
6
+ ### Code Refactoring
7
+
8
+ * refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * @applitools/utils bumped to 1.5.1
14
+ #### Code Refactoring
15
+
16
+ * refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
17
+ * @applitools/logger bumped to 2.0.8
18
+ #### Code Refactoring
19
+
20
+ * refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
21
+
22
+
23
+
24
+ * @applitools/snippets bumped to 2.4.23
25
+ #### Code Refactoring
26
+
27
+ * refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
28
+ * @applitools/driver bumped to 1.13.5
29
+ #### Bug Fixes
30
+
31
+ * optimize driver usage in close ([#1867](https://github.com/applitools/eyes.sdk.javascript1/issues/1867)) ([60dff6b](https://github.com/applitools/eyes.sdk.javascript1/commit/60dff6b160e69d3893c91a1125d668fa18b43072))
32
+
33
+
34
+ #### Code Refactoring
35
+
36
+ * refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
37
+
38
+
39
+
40
+
3
41
  ## [1.0.41](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-webdriver@1.0.40...js/spec-driver-webdriver@1.0.41) (2023-08-03)
4
42
 
5
43
 
@@ -26,15 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.build = exports.switchWorld = exports.getWorlds = exports.getCurrentWorld = exports.performAction = exports.getElementAttribute = exports.getElementRegion = exports.setOrientation = exports.getOrientation = exports.getSystemBars = exports.hover = exports.click = exports.takeScreenshot = exports.visit = exports.getUrl = exports.getTitle = exports.getDriverInfo = exports.getCapabilities = exports.getCookies = exports.setWindowSize = exports.getWindowSize = exports.getElementText = exports.setElementText = exports.findElements = exports.findElement = exports.childContext = exports.parentContext = exports.mainContext = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractHostName = exports.untransformSelector = exports.transformSelector = exports.transformElement = exports.transformDriver = exports.isSelector = exports.isShadowRoot = exports.isElement = exports.isDriver = void 0;
29
+ exports.build = exports.switchWorld = exports.getWorlds = exports.getCurrentWorld = exports.takeScreenshot = exports.performAction = exports.visit = exports.getUrl = exports.getTitle = exports.getCookies = exports.getSystemBars = exports.setOrientation = exports.getOrientation = exports.setViewportSize = exports.setWindowSize = exports.getWindowSize = exports.getCapabilities = exports.getDriverInfo = exports.childContext = exports.parentContext = exports.mainContext = exports.click = exports.hover = exports.getElementText = exports.setElementText = exports.getElementAttribute = exports.getElementRegion = exports.findElements = exports.findElement = exports.executeScript = exports.toSimpleCommonSelector = exports.toSelector = exports.toElement = exports.toDriver = exports.isStaleElementError = exports.isEqualElements = exports.isSelector = exports.isShadowRoot = exports.isSecondaryElement = exports.isElement = exports.isSecondaryDriver = exports.isDriver = void 0;
30
30
  const url_1 = require("url");
31
- const utils = __importStar(require("@applitools/utils"));
32
- const webdriver_1 = __importStar(require("webdriver"));
33
31
  const http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
34
32
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
35
33
  const http_1 = __importDefault(require("http"));
36
34
  const https_1 = __importDefault(require("https"));
37
- // #region HELPERS
35
+ const utils = __importStar(require("@applitools/utils"));
38
36
  const LEGACY_ELEMENT_ID = 'ELEMENT';
39
37
  const ELEMENT_ID = 'element-6066-11e4-a52e-4f735466cecf';
40
38
  const SHADOW_ROOT_ID = 'shadow-6066-11e4-a52e-4f735466cecf';
@@ -76,25 +74,78 @@ function extractEnvironment(capabilities) {
76
74
  isW3C,
77
75
  };
78
76
  }
79
- // #endregion
80
- // #region UTILITY
77
+ function command(method, url, body) {
78
+ if (getFrameworkMajorVersion() < 8) {
79
+ let commandPath;
80
+ try {
81
+ commandPath = require.resolve('webdriver/build/command', { paths: [`${process.cwd()}/node_modules`] });
82
+ }
83
+ catch {
84
+ commandPath = 'webdriver/build/command';
85
+ }
86
+ const { default: command } = require(commandPath);
87
+ return command(method, url, body);
88
+ }
89
+ else {
90
+ let frameworkPath;
91
+ try {
92
+ frameworkPath = require.resolve('webdriver', { paths: [`${process.cwd()}/node_modules`] });
93
+ }
94
+ catch {
95
+ frameworkPath = 'webdriver';
96
+ }
97
+ const { command } = require(frameworkPath);
98
+ return command(method, url, body);
99
+ }
100
+ }
101
+ function getFrameworkMajorVersion() {
102
+ let version;
103
+ try {
104
+ version = require(require.resolve('webdriver/package.json', { paths: [`${process.cwd()}/node_modules`] })).version;
105
+ }
106
+ catch {
107
+ version = require('webdriver/package.json').version;
108
+ }
109
+ return Number.parseInt(version);
110
+ }
111
+ function getWebDriver() {
112
+ let frameworkPath;
113
+ try {
114
+ frameworkPath = require.resolve('webdriver', { paths: [`${process.cwd()}/node_modules`] });
115
+ }
116
+ catch {
117
+ frameworkPath = 'webdriver';
118
+ }
119
+ return getFrameworkMajorVersion() < 8 ? require(frameworkPath).default : require(frameworkPath);
120
+ }
81
121
  function isDriver(driver) {
82
122
  if (!driver)
83
123
  return false;
84
- return utils.types.has(driver, ['sessionId', 'serverUrl']) || utils.types.instanceOf(driver, 'Browser');
124
+ return utils.types.instanceOf(driver, 'Browser');
85
125
  }
86
126
  exports.isDriver = isDriver;
127
+ function isSecondaryDriver(driver) {
128
+ if (!driver)
129
+ return false;
130
+ return utils.types.has(driver, ['sessionId', 'serverUrl']);
131
+ }
132
+ exports.isSecondaryDriver = isSecondaryDriver;
87
133
  function isElement(element) {
88
- var _a;
89
134
  if (!element)
90
135
  return false;
91
- return Boolean((_a = element.elementId) !== null && _a !== void 0 ? _a : extractElementId(element));
136
+ return !!extractElementId(element);
92
137
  }
93
138
  exports.isElement = isElement;
139
+ function isSecondaryElement(element) {
140
+ if (!element)
141
+ return false;
142
+ return !!element.elementId;
143
+ }
144
+ exports.isSecondaryElement = isSecondaryElement;
94
145
  function isShadowRoot(shadowRoot) {
95
146
  if (!shadowRoot)
96
147
  return false;
97
- return Boolean(extractShadowRootId(shadowRoot));
148
+ return !!extractShadowRootId(shadowRoot);
98
149
  }
99
150
  exports.isShadowRoot = isShadowRoot;
100
151
  function isSelector(selector) {
@@ -103,7 +154,22 @@ function isSelector(selector) {
103
154
  return utils.types.has(selector, ['using', 'value']);
104
155
  }
105
156
  exports.isSelector = isSelector;
106
- function transformDriver(driver) {
157
+ function isEqualElements(_driver, element1, element2) {
158
+ if (!element1 || !element2)
159
+ return false;
160
+ const elementId1 = extractElementId(element1);
161
+ const elementId2 = extractElementId(element2);
162
+ return elementId1 === elementId2;
163
+ }
164
+ exports.isEqualElements = isEqualElements;
165
+ function isStaleElementError(error) {
166
+ if (!error)
167
+ return false;
168
+ const errOrResult = error.originalError || error;
169
+ return errOrResult instanceof Error && errOrResult.name === 'stale element reference';
170
+ }
171
+ exports.isStaleElementError = isStaleElementError;
172
+ function toDriver(driver) {
107
173
  var _a, _b, _c;
108
174
  if (!utils.types.has(driver, ['sessionId', 'serverUrl']))
109
175
  return driver;
@@ -119,6 +185,12 @@ function transformDriver(driver) {
119
185
  logLevel: 'silent',
120
186
  ...environment,
121
187
  };
188
+ if (!options.port) {
189
+ if (options.protocol === 'http')
190
+ options.port = 80;
191
+ if (options.protocol === 'https')
192
+ options.port = 443;
193
+ }
122
194
  if ((_a = driver.proxy) === null || _a === void 0 ? void 0 : _a.url) {
123
195
  const proxyUrl = new URL(driver.proxy.url);
124
196
  proxyUrl.username = (_b = driver.proxy.username) !== null && _b !== void 0 ? _b : proxyUrl.username;
@@ -136,15 +208,10 @@ function transformDriver(driver) {
136
208
  const httpsAgent = new https_1.default.Agent({ rejectUnauthorized: false });
137
209
  options.agent = { http: httpAgent, https: httpsAgent };
138
210
  }
139
- if (!options.port) {
140
- if (options.protocol === 'http')
141
- options.port = 80;
142
- if (options.protocol === 'https')
143
- options.port = 443;
144
- }
145
- const additionalCommands = {
211
+ const WebDriver = getWebDriver();
212
+ const attachedDriver = WebDriver.attachToSession(options, undefined, {
146
213
  _getWindowSize: {
147
- value: (0, webdriver_1.command)('GET', '/session/:sessionId/window/current/size', {
214
+ value: command('GET', '/session/:sessionId/window/current/size', {
148
215
  command: '_getWindowSize',
149
216
  description: '',
150
217
  ref: '',
@@ -152,7 +219,7 @@ function transformDriver(driver) {
152
219
  }),
153
220
  },
154
221
  _setWindowSize: {
155
- value: (0, webdriver_1.command)('POST', '/session/:sessionId/window/current/size', {
222
+ value: command('POST', '/session/:sessionId/window/current/size', {
156
223
  command: '_setWindowSize',
157
224
  parameters: [
158
225
  { name: 'width', type: 'number', required: true, description: '' },
@@ -163,7 +230,7 @@ function transformDriver(driver) {
163
230
  }),
164
231
  },
165
232
  setWindowPosition: {
166
- value: (0, webdriver_1.command)('POST', '/session/:sessionId/window/current/position', {
233
+ value: command('POST', '/session/:sessionId/window/current/position', {
167
234
  command: 'setWindowPosition',
168
235
  parameters: [
169
236
  { name: 'x', type: 'number', required: true, description: '' },
@@ -173,81 +240,46 @@ function transformDriver(driver) {
173
240
  ref: '',
174
241
  }),
175
242
  },
176
- };
177
- return webdriver_1.default.attachToSession(options, undefined, additionalCommands);
243
+ });
244
+ attachedDriver.original = driver.original;
245
+ return attachedDriver;
178
246
  }
179
- exports.transformDriver = transformDriver;
180
- function transformElement(element) {
247
+ exports.toDriver = toDriver;
248
+ function toElement(element) {
181
249
  const elementId = utils.types.has(element, 'elementId') ? element.elementId : extractElementId(element);
182
250
  return { [ELEMENT_ID]: elementId, [LEGACY_ELEMENT_ID]: elementId };
183
251
  }
184
- exports.transformElement = transformElement;
185
- function transformSelector(selector) {
186
- if (utils.types.isString(selector)) {
187
- return { using: 'css selector', value: selector };
188
- }
189
- else if (utils.types.has(selector, 'selector')) {
190
- if (!utils.types.isString(selector.selector))
252
+ exports.toElement = toElement;
253
+ function toSelector(selector) {
254
+ if (utils.types.has(selector, 'selector')) {
255
+ if (utils.types.has(selector, 'type') && selector.type && utils.types.isString(selector.selector)) {
256
+ return { using: selector.type === 'css' ? 'css selector' : selector.type, value: selector.selector };
257
+ }
258
+ else if (isSelector(selector.selector)) {
191
259
  return selector.selector;
192
- return {
193
- using: utils.types.isNull(selector.type) || selector.type === 'css' ? 'css selector' : selector.type,
194
- value: selector.selector,
195
- };
260
+ }
261
+ else {
262
+ selector = selector.selector;
263
+ }
196
264
  }
197
- else {
198
- return selector;
265
+ if (utils.types.isString(selector)) {
266
+ return { using: 'css selector', value: selector };
199
267
  }
268
+ return selector;
200
269
  }
201
- exports.transformSelector = transformSelector;
202
- function untransformSelector(selector) {
270
+ exports.toSelector = toSelector;
271
+ function toSimpleCommonSelector(selector) {
203
272
  if (utils.types.has(selector, ['using', 'value'])) {
204
273
  return { type: selector.using === 'css selector' ? 'css' : selector.using, selector: selector.value };
205
274
  }
206
275
  return selector;
207
276
  }
208
- exports.untransformSelector = untransformSelector;
209
- function extractHostName(driver) {
210
- var _a, _b;
211
- return (_b = (_a = driver.options) === null || _a === void 0 ? void 0 : _a.hostname) !== null && _b !== void 0 ? _b : null;
212
- }
213
- exports.extractHostName = extractHostName;
214
- function isStaleElementError(error) {
215
- if (!error)
216
- return false;
217
- const errOrResult = error.originalError || error;
218
- return errOrResult instanceof Error && errOrResult.name === 'stale element reference';
219
- }
220
- exports.isStaleElementError = isStaleElementError;
221
- // #endregion
222
- // #region COMMANDS
223
- async function isEqualElements(_driver, element1, element2) {
224
- if (!element1 || !element2)
225
- return false;
226
- const elementId1 = extractElementId(element1);
227
- const elementId2 = extractElementId(element2);
228
- return elementId1 === elementId2;
229
- }
230
- exports.isEqualElements = isEqualElements;
277
+ exports.toSimpleCommonSelector = toSimpleCommonSelector;
231
278
  async function executeScript(driver, script, arg) {
232
279
  script = utils.types.isFunction(script) ? `return (${script}).apply(null, arguments)` : script;
233
280
  return driver.executeScript(script, [arg]);
234
281
  }
235
282
  exports.executeScript = executeScript;
236
- async function mainContext(driver) {
237
- await driver.switchToFrame(null);
238
- return driver;
239
- }
240
- exports.mainContext = mainContext;
241
- async function parentContext(driver) {
242
- await driver.switchToParentFrame();
243
- return driver;
244
- }
245
- exports.parentContext = parentContext;
246
- async function childContext(driver, element) {
247
- await driver.switchToFrame(element);
248
- return driver;
249
- }
250
- exports.childContext = childContext;
251
283
  async function findElement(driver, selector, parent) {
252
284
  const parentId = parent ? (isShadowRoot(parent) ? extractShadowRootId(parent) : extractElementId(parent)) : null;
253
285
  try {
@@ -256,8 +288,13 @@ async function findElement(driver, selector, parent) {
256
288
  : await driver.findElement(selector.using, selector.value);
257
289
  return isElement(element) ? element : null;
258
290
  }
259
- catch {
260
- return null;
291
+ catch (error) {
292
+ if (/element could not be located/i.test(error.message) ||
293
+ /cannot locate an element/i.test(error.message) ||
294
+ /wasn\'t found/i.test(error.message)) {
295
+ return null;
296
+ }
297
+ throw error;
261
298
  }
262
299
  }
263
300
  exports.findElement = findElement;
@@ -268,6 +305,14 @@ async function findElements(driver, selector, parent) {
268
305
  : await driver.findElements(selector.using, selector.value);
269
306
  }
270
307
  exports.findElements = findElements;
308
+ async function getElementRegion(driver, element) {
309
+ return driver.getElementRect(extractElementId(element));
310
+ }
311
+ exports.getElementRegion = getElementRegion;
312
+ async function getElementAttribute(driver, element, attr) {
313
+ return driver.getElementAttribute(extractElementId(element), attr);
314
+ }
315
+ exports.getElementAttribute = getElementAttribute;
271
316
  async function setElementText(driver, element, text) {
272
317
  await driver.elementClear(extractElementId(element));
273
318
  await driver.elementSendKeys(extractElementId(element), text);
@@ -277,6 +322,55 @@ async function getElementText(driver, element) {
277
322
  return driver.getElementText(extractElementId(element));
278
323
  }
279
324
  exports.getElementText = getElementText;
325
+ async function hover(driver, element) {
326
+ if (!driver.isW3C)
327
+ return await driver.moveToElement(extractElementId(element));
328
+ await driver.performActions([
329
+ {
330
+ type: 'pointer',
331
+ id: 'mouse',
332
+ parameters: { pointerType: 'mouse' },
333
+ actions: [{ type: 'pointerMove', duration: 0, origin: element, x: 0, y: 0 }],
334
+ },
335
+ ]);
336
+ }
337
+ exports.hover = hover;
338
+ async function click(driver, element) {
339
+ await driver.elementClick(extractElementId(element));
340
+ }
341
+ exports.click = click;
342
+ async function mainContext(driver) {
343
+ await driver.switchToFrame(null);
344
+ return driver;
345
+ }
346
+ exports.mainContext = mainContext;
347
+ async function parentContext(driver) {
348
+ await driver.switchToParentFrame();
349
+ return driver;
350
+ }
351
+ exports.parentContext = parentContext;
352
+ async function childContext(driver, element) {
353
+ await driver.switchToFrame(element);
354
+ return driver;
355
+ }
356
+ exports.childContext = childContext;
357
+ async function getDriverInfo(driver) {
358
+ return { sessionId: driver.sessionId };
359
+ }
360
+ exports.getDriverInfo = getDriverInfo;
361
+ async function getCapabilities(driver) {
362
+ var _a;
363
+ try {
364
+ const capabilities = await ((_a = driver.getSession) === null || _a === void 0 ? void 0 : _a.call(driver));
365
+ return utils.types.isObject(capabilities) ? capabilities : driver.capabilities;
366
+ }
367
+ catch (error) {
368
+ if (/Cannot call non W3C standard command while in W3C mode/i.test(error.message))
369
+ return driver.capabilities;
370
+ throw new Error(`Unable to retrieve capabilities due to an error. The original error is ${error.message}`);
371
+ }
372
+ }
373
+ exports.getCapabilities = getCapabilities;
280
374
  async function getWindowSize(driver) {
281
375
  try {
282
376
  const rect = await driver.getWindowRect();
@@ -297,6 +391,27 @@ async function setWindowSize(driver, size) {
297
391
  }
298
392
  }
299
393
  exports.setWindowSize = setWindowSize;
394
+ async function setViewportSize(driver, size) {
395
+ await driver.sendCommandAndGetResult('Emulation.setDeviceMetricsOverride', {
396
+ ...size,
397
+ deviceScaleFactor: 0,
398
+ mobile: false,
399
+ });
400
+ }
401
+ exports.setViewportSize = setViewportSize;
402
+ async function getOrientation(browser) {
403
+ const orientation = await browser.getOrientation();
404
+ return orientation.toLowerCase();
405
+ }
406
+ exports.getOrientation = getOrientation;
407
+ async function setOrientation(browser, orientation) {
408
+ return await browser.setOrientation(orientation);
409
+ }
410
+ exports.setOrientation = setOrientation;
411
+ async function getSystemBars(browser) {
412
+ return browser.getSystemBars();
413
+ }
414
+ exports.getSystemBars = getSystemBars;
300
415
  async function getCookies(driver, context) {
301
416
  if (context)
302
417
  return driver.getAllCookies();
@@ -315,23 +430,6 @@ async function getCookies(driver, context) {
315
430
  });
316
431
  }
317
432
  exports.getCookies = getCookies;
318
- async function getCapabilities(driver) {
319
- var _a;
320
- try {
321
- const capabilities = await ((_a = driver.getSession) === null || _a === void 0 ? void 0 : _a.call(driver));
322
- return utils.types.isObject(capabilities) ? capabilities : driver.capabilities;
323
- }
324
- catch (error) {
325
- if (/Cannot call non W3C standard command while in W3C mode/i.test(error.message))
326
- return driver.capabilities;
327
- throw new Error(`Unable to retrieve capabilities due to an error. The original error is ${error.message}`);
328
- }
329
- }
330
- exports.getCapabilities = getCapabilities;
331
- async function getDriverInfo(driver) {
332
- return { sessionId: driver.sessionId };
333
- }
334
- exports.getDriverInfo = getDriverInfo;
335
433
  async function getTitle(driver) {
336
434
  return driver.getTitle();
337
435
  }
@@ -344,60 +442,14 @@ async function visit(driver, url) {
344
442
  await driver.navigateTo(url);
345
443
  }
346
444
  exports.visit = visit;
347
- async function takeScreenshot(driver) {
348
- return driver.takeScreenshot();
349
- }
350
- exports.takeScreenshot = takeScreenshot;
351
- async function click(driver, element) {
352
- const resolvedElement = isSelector(element) ? await findElement(driver, element) : element;
353
- if (resolvedElement)
354
- await driver.elementClick(extractElementId(resolvedElement));
355
- }
356
- exports.click = click;
357
- async function hover(driver, element) {
358
- if (!driver.isW3C)
359
- return await driver.moveToElement(extractElementId(element));
360
- const { x, y, width, height } = await driver.getElementRect(extractElementId(element));
361
- const { scrollX, scrollY } = await driver.executeScript('return {scrollX:window.pageXOffset,scrollY:window.pageYOffset}', []);
362
- const offsetX = Math.floor(x - scrollX + width / 2);
363
- const offsetY = Math.floor(y - scrollY + height / 2);
364
- await driver.performActions([
365
- {
366
- type: 'pointer',
367
- id: 'mouse',
368
- parameters: { pointerType: 'mouse' },
369
- actions: [{ type: 'pointerMove', duration: 0, x: offsetX, y: offsetY }],
370
- },
371
- ]);
372
- }
373
- exports.hover = hover;
374
- // #endregion
375
- // #region APPIUM COMMANDS
376
- async function getSystemBars(browser) {
377
- return browser.getSystemBars();
378
- }
379
- exports.getSystemBars = getSystemBars;
380
- async function getOrientation(browser) {
381
- const orientation = await browser.getOrientation();
382
- return orientation.toLowerCase();
383
- }
384
- exports.getOrientation = getOrientation;
385
- async function setOrientation(browser, orientation) {
386
- return await browser.setOrientation(orientation);
387
- }
388
- exports.setOrientation = setOrientation;
389
- async function getElementRegion(driver, element) {
390
- return driver.getElementRect(extractElementId(element));
391
- }
392
- exports.getElementRegion = getElementRegion;
393
- async function getElementAttribute(driver, element, attr) {
394
- return driver.getElementAttribute(extractElementId(element), attr);
395
- }
396
- exports.getElementAttribute = getElementAttribute;
397
445
  async function performAction(driver, steps) {
398
446
  return driver.touchPerform(steps.map(({ action, ...options }) => ({ action, options })));
399
447
  }
400
448
  exports.performAction = performAction;
449
+ async function takeScreenshot(driver) {
450
+ return driver.takeScreenshot();
451
+ }
452
+ exports.takeScreenshot = takeScreenshot;
401
453
  async function getCurrentWorld(driver) {
402
454
  const world = await driver.getContext();
403
455
  return utils.types.isString(world) ? world : world.id;
@@ -412,13 +464,20 @@ async function switchWorld(driver, id) {
412
464
  await driver.switchContext(id);
413
465
  }
414
466
  exports.switchWorld = switchWorld;
415
- // #endregion
416
- // #region TESTING
417
467
  const browserOptionsNames = {
418
468
  chrome: 'goog:chromeOptions',
419
469
  firefox: 'moz:firefoxOptions',
420
470
  };
471
+ /*
472
+ * Spawn a browser with a given configuration (INTERNAL USE ONLY)
473
+ *
474
+ * NOTE:
475
+ * This function is intended for internal use only. As a result it relies on some dev dependencies.
476
+ * When wiring the spec-driver up to an SDK and calling this function, if you don't have the same dev deps
477
+ * installed in the SDK, then this function will error.
478
+ */
421
479
  async function build(env) {
480
+ const WebDriver = getWebDriver();
422
481
  const parseEnv = require('@applitools/test-utils/src/parse-env');
423
482
  const { browser = '', capabilities, url, proxy, configurable = true, args = [], headless, logLevel = 'silent', } = parseEnv(env);
424
483
  const options = {
@@ -454,8 +513,7 @@ async function build(env) {
454
513
  };
455
514
  }
456
515
  options.agent = { https: require('https').Agent({ rejectUnauthorized: false }) };
457
- const driver = await webdriver_1.default.newSession(options);
516
+ const driver = await WebDriver.newSession(options);
458
517
  return [driver, () => driver.deleteSession()];
459
518
  }
460
519
  exports.build = build;
461
- // #endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/spec-driver-webdriver",
3
- "version": "1.0.41",
3
+ "version": "1.0.42",
4
4
  "keywords": [
5
5
  "webdriver",
6
6
  "chrome devtools protocol",
@@ -45,11 +45,12 @@
45
45
  "lint": "run --top-level eslint '**/*.ts'",
46
46
  "build": "run --top-level tspc --project ./tsconfig.build.json",
47
47
  "test": "run --top-level mocha './test/**/*.spec.ts' -r @applitools/test-utils/mocha-hooks/docker --exit",
48
- "setup": "run --top-level browsers:setup"
48
+ "setup": "run --top-level browsers:setup",
49
+ "up:framework": "yarn add --dev --caret webdriver${APPLITOOLS_FRAMEWORK_VERSION:+@$APPLITOOLS_FRAMEWORK_VERSION}"
49
50
  },
50
51
  "dependencies": {
51
- "@applitools/driver": "1.13.4",
52
- "@applitools/utils": "1.5.0",
52
+ "@applitools/driver": "1.13.5",
53
+ "@applitools/utils": "1.5.1",
53
54
  "http-proxy-agent": "5.0.0",
54
55
  "https-proxy-agent": "5.0.1"
55
56
  },
@@ -59,10 +60,10 @@
59
60
  "@applitools/test-utils": "^1.5.17",
60
61
  "@types/node": "^12.20.55",
61
62
  "nock": "^13.3.2",
62
- "webdriver": "^7.30.0"
63
+ "webdriver": "^8.14.3"
63
64
  },
64
65
  "peerDependencies": {
65
- "webdriver": ">=7.27.0"
66
+ "webdriver": ">=6.0.0"
66
67
  },
67
68
  "engines": {
68
69
  "node": ">=12.13.0"
package/types/index.d.ts CHANGED
@@ -1,36 +1,42 @@
1
- declare const _default: import('@applitools/driver').SpecDriver<SpecType>;
1
+ declare const _default: SpecDriver;
2
2
  export default _default;
3
- export function isDriver(driver: any): driver is Driver;
3
+ export function isDriver(driver: any): driver is Driver<unknown>;
4
+ export function isSecondaryDriver(driver: any): driver is StaticDriver<unknown>;
4
5
  export function isElement(element: any): element is Element;
6
+ export function isSecondaryElement(element: any): element is StaticElement;
5
7
  export function isShadowRoot(shadowRoot: any): shadowRoot is ShadowRoot;
6
8
  export function isSelector(selector: any): selector is Selector;
7
- export function transformDriver(driver: Driver | StaticDriver): Driver;
8
- export function transformElement(element: Element | StaticElement): Element;
9
- export function transformSelector(selector: import('@applitools/driver').CommonSelector<Selector>): Selector;
10
- export function untransformSelector(selector: Selector): import('@applitools/driver').CommonSelector;
11
- export function extractHostName(driver: Driver): null | string;
9
+ export function isEqualElements(_driver: Driver<unknown>, element1: Element, element2: Element): boolean;
12
10
  export function isStaleElementError(error: any): boolean;
13
- export function isEqualElements(_driver: Driver, element1: Element, element2: Element): Promise<boolean>;
14
- export function executeScript(driver: Driver, script: string | ((arg: any) => any), arg: any): Promise<any>;
15
- export function mainContext(driver: Driver): Promise<Driver>;
16
- export function parentContext(driver: Driver): Promise<Driver>;
17
- export function childContext(driver: Driver, element: Element): Promise<Driver>;
18
- export function findElement(driver: Driver, selector: Selector, parent?: undefined | Element | ShadowRoot): Promise<null | Element>;
19
- export function findElements(driver: Driver, selector: Selector, parent?: undefined | Element | ShadowRoot): Promise<Array<Element>>;
20
- export function setElementText(driver: Driver, element: Element, text: string): Promise<void>;
21
- export function getElementText(driver: Driver, element: Element): Promise<string>;
22
- export function getWindowSize(driver: Driver): Promise<{ width: number; height: number; }>;
23
- export function setWindowSize(driver: Driver, size: { width: number; height: number; }): Promise<void>;
24
- export function getCookies(driver: Driver, context?: undefined | boolean): Promise<Array<import('@applitools/driver').Cookie>>;
25
- export function getCapabilities(driver: Driver): Promise<Record<string, any>>;
26
- export function getDriverInfo(driver: Driver): Promise<import('@applitools/driver').DriverInfo>;
27
- export function getTitle(driver: Driver): Promise<string>;
28
- export function getUrl(driver: Driver): Promise<string>;
29
- export function visit(driver: Driver, url: string): Promise<void>;
30
- export function takeScreenshot(driver: Driver): Promise<string>;
31
- export function click(driver: Driver, element: Element | Selector): Promise<void>;
32
- export function hover(driver: Driver, element: Element): Promise<any>;
33
- export function getSystemBars(browser: Driver): Promise<{ statusBar: {
11
+ export function toDriver<TOriginalDriver = never>(driver: StaticDriver<TOriginalDriver>): Driver<TOriginalDriver> | Promise<Driver<TOriginalDriver>>;
12
+ export function toElement(element: StaticElement): Element;
13
+ export function toSelector(selector: import('@applitools/driver').CommonSelector<Selector>): Selector;
14
+ export function toSimpleCommonSelector(selector: Selector): import('@applitools/driver').CommonSelector;
15
+ export function executeScript(driver: Driver<unknown>, script: string | ((arg: any) => any), arg: any): Promise<any>;
16
+ export function findElement(driver: Driver<unknown>, selector: Selector, parent?: undefined | Element | ShadowRoot): Promise<null | Element>;
17
+ export function findElements(driver: Driver<unknown>, selector: Selector, parent?: undefined | Element | ShadowRoot): Promise<Array<Element>>;
18
+ export function getElementRegion(driver: Driver<unknown>, element: Element): Promise<{
19
+ x: number;
20
+ y: number;
21
+ width: number;
22
+ height: number;
23
+ }>;
24
+ export function getElementAttribute(driver: Driver<unknown>, element: Element, attr: string): Promise<string>;
25
+ export function setElementText(driver: Driver<unknown>, element: Element, text: string): Promise<void>;
26
+ export function getElementText(driver: Driver<unknown>, element: Element): Promise<string>;
27
+ export function hover(driver: Driver<unknown>, element: Element): Promise<void>;
28
+ export function click(driver: Driver<unknown>, element: Element): Promise<void>;
29
+ export function mainContext(driver: Driver<unknown>): Promise<Driver<unknown>>;
30
+ export function parentContext(driver: Driver<unknown>): Promise<Driver<unknown>>;
31
+ export function childContext(driver: Driver<unknown>, element: Element): Promise<Driver<unknown>>;
32
+ export function getDriverInfo(driver: Driver<unknown>): Promise<import('@applitools/driver').DriverInfo>;
33
+ export function getCapabilities(driver: Driver<unknown>): Promise<Record<string, any>>;
34
+ export function getWindowSize(driver: Driver<unknown>): Promise<{ width: number; height: number; }>;
35
+ export function setWindowSize(driver: Driver<unknown>, size: { width: number; height: number; }): Promise<void>;
36
+ export function setViewportSize(driver: Driver<unknown>, size: { width: number; height: number; }): Promise<void>;
37
+ export function getOrientation(browser: Driver<unknown>): Promise<"portrait" | "landscape">;
38
+ export function setOrientation(browser: Driver<unknown>, orientation: "portrait" | "landscape"): Promise<void>;
39
+ export function getSystemBars(browser: Driver<unknown>): Promise<{ statusBar: {
34
40
  visible: boolean;
35
41
  x: number;
36
42
  y: number;
@@ -43,21 +49,32 @@ export function getSystemBars(browser: Driver): Promise<{ statusBar: {
43
49
  height: number;
44
50
  width: number;
45
51
  }; }>;
46
- export function getOrientation(browser: Driver): Promise<"portrait" | "landscape">;
47
- export function setOrientation(browser: Driver, orientation: "portrait" | "landscape"): Promise<void>;
48
- export function getElementRegion(driver: Driver, element: Element): Promise<{
49
- x: number;
50
- y: number;
51
- width: number;
52
- height: number;
53
- }>;
54
- export function getElementAttribute(driver: Driver, element: Element, attr: string): Promise<string>;
55
- export function performAction(driver: Driver, steps: Array<any>): Promise<void>;
56
- export function getCurrentWorld(driver: Driver): Promise<string>;
57
- export function getWorlds(driver: Driver): Promise<Array<string>>;
58
- export function switchWorld(driver: Driver, id: string): Promise<void>;
59
- export function build(env: any): Promise<[Driver, () => Promise<void>]>;
60
- export type Driver = import('webdriver').Client & { original?: any; } & { __applitoolsBrand?: undefined; };
52
+ export function getCookies(driver: Driver<unknown>, context?: undefined | boolean): Promise<Array<import('@applitools/driver').Cookie>>;
53
+ export function getTitle(driver: Driver<unknown>): Promise<string>;
54
+ export function getUrl(driver: Driver<unknown>): Promise<string>;
55
+ export function visit(driver: Driver<unknown>, url: string): Promise<void>;
56
+ export function performAction(driver: Driver<unknown>, steps: Array<any>): Promise<void>;
57
+ export function takeScreenshot(driver: Driver<unknown>): Promise<string>;
58
+ export function getCurrentWorld(driver: Driver<unknown>): Promise<string>;
59
+ export function getWorlds(driver: Driver<unknown>): Promise<Array<string>>;
60
+ export function switchWorld(driver: Driver<unknown>, id: string): Promise<void>;
61
+ export function build(env: any): Promise<[Driver<unknown>, () => Promise<void>]>;
62
+ export type StaticDriver<TOriginalDriver = unknown> = {
63
+ sessionId: string;
64
+ serverUrl: string;
65
+ capabilities: Record<string, any>;
66
+ proxy?: undefined | { url: string; username?: undefined | string; password?: undefined | string; };
67
+ original?: undefined | TOriginalDriver;
68
+ };
69
+ export type StaticElement = { elementId: string; };
70
+ export type SecondarySpecType = {
71
+ driver: StaticDriver<unknown>;
72
+ context: never;
73
+ element: StaticElement;
74
+ selector: never;
75
+ secondary: never;
76
+ };
77
+ export type Driver<TOriginalDriver = unknown> = import('webdriver').Client & { original: TOriginalDriver; } & { __applitoolsBrand?: undefined; };
61
78
  export type Element = ({ 'element-6066-11e4-a52e-4f735466cecf': string; } | { ELEMENT: string; }) & { __applitoolsBrand?: undefined; };
62
79
  export type ShadowRoot = {
63
80
  'shadow-6066-11e4-a52e-4f735466cecf': string;
@@ -68,6 +85,11 @@ export type Selector = {
68
85
  value: string;
69
86
  __applitoolsBrand?: undefined;
70
87
  };
71
- export type SpecType = { driver: Driver; context: Driver; element: Element; selector: Selector; };
72
- export type StaticDriver = { sessionId: string; serverUrl: string; capabilities: Record<string, any>; proxy?: undefined | { url: string; username?: undefined | string; password?: undefined | string; }; };
73
- export type StaticElement = { elementId: string; };
88
+ export type PrimarySpecType = {
89
+ driver: Driver<unknown>;
90
+ context: Driver<unknown>;
91
+ element: Element;
92
+ selector: Selector;
93
+ secondary: SecondarySpecType;
94
+ };
95
+ export type SpecDriver = import('@applitools/driver').SpecDriver<PrimarySpecType>;