@applitools/driver 1.11.37 → 1.11.39

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.
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCapabilities = void 0;
4
- function parseCapabilities(capabilities) {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
3
+ exports.extractCapabilitiesViewport = exports.extractCapabilitiesEnvironment = void 0;
4
+ function extractCapabilitiesEnvironment(capabilities) {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6
6
  if (capabilities.capabilities)
7
7
  capabilities = capabilities.capabilities;
8
- const info = {
8
+ const environment = {
9
9
  browserName: !capabilities.app && !capabilities.bundleId
10
10
  ? ((_a = capabilities.browserName) !== null && _a !== void 0 ? _a : (_b = capabilities.desired) === null || _b === void 0 ? void 0 : _b.browserName) || undefined
11
11
  : undefined,
@@ -17,36 +17,43 @@ function parseCapabilities(capabilities) {
17
17
  isChrome: isChrome(capabilities),
18
18
  isECClient: Boolean(capabilities['applitools:isECClient']),
19
19
  };
20
- if (info.isMobile) {
21
- info.deviceName = ((_h = (_g = capabilities.desired) === null || _g === void 0 ? void 0 : _g.deviceName) !== null && _h !== void 0 ? _h : capabilities.deviceName) || undefined;
22
- info.orientation = (_k = ((_j = capabilities.deviceOrientation) !== null && _j !== void 0 ? _j : capabilities.orientation)) === null || _k === void 0 ? void 0 : _k.toLowerCase();
23
- info.isIOS = isIOS(capabilities);
24
- info.isAndroid = isAndroid(capabilities);
25
- if (!info.browserName) {
26
- info.isNative = true;
20
+ if (environment === null || environment === void 0 ? void 0 : environment.isMobile) {
21
+ environment.deviceName = ((_h = (_g = capabilities.desired) === null || _g === void 0 ? void 0 : _g.deviceName) !== null && _h !== void 0 ? _h : capabilities.deviceName) || undefined;
22
+ environment.isIOS = isIOS(capabilities);
23
+ environment.isAndroid = isAndroid(capabilities);
24
+ if (!environment.browserName) {
25
+ environment.isNative = true;
27
26
  }
28
- else if (info.isIOS && !/mobilesafari/i.test(capabilities.CFBundleIdentifier)) {
29
- info.browserName = undefined;
30
- info.isNative = true;
27
+ else if (environment.isIOS && !/mobilesafari/i.test(capabilities.CFBundleIdentifier)) {
28
+ environment.browserName = undefined;
29
+ environment.isNative = true;
31
30
  }
32
31
  else {
33
- info.isNative = false;
32
+ environment.isNative = false;
34
33
  }
35
34
  }
36
- if (info.isNative) {
37
- info.displaySize = extractDisplaySize(capabilities);
38
- info.pixelRatio = capabilities.pixelRatio;
39
- info.statusBarSize = (_l = capabilities.statBarHeight) !== null && _l !== void 0 ? _l : (_m = capabilities.viewportRect) === null || _m === void 0 ? void 0 : _m.top;
40
- if (info.displaySize && info.orientation && capabilities.viewportRect) {
41
- info.navigationBarSize =
42
- info.orientation === 'landscape'
43
- ? info.displaySize.width - (capabilities.viewportRect.left + capabilities.viewportRect.width)
44
- : info.displaySize.height - (capabilities.viewportRect.top + capabilities.viewportRect.height);
45
- }
35
+ return environment;
36
+ }
37
+ exports.extractCapabilitiesEnvironment = extractCapabilitiesEnvironment;
38
+ function extractCapabilitiesViewport(capabilities) {
39
+ var _a, _b, _c, _d;
40
+ if (capabilities.capabilities)
41
+ capabilities = capabilities.capabilities;
42
+ const viewport = {
43
+ displaySize: extractDisplaySize(capabilities),
44
+ orientation: (_b = ((_a = capabilities.deviceOrientation) !== null && _a !== void 0 ? _a : capabilities.orientation)) === null || _b === void 0 ? void 0 : _b.toLowerCase(),
45
+ pixelRatio: capabilities.pixelRatio,
46
+ statusBarSize: (_c = capabilities.statBarHeight) !== null && _c !== void 0 ? _c : (_d = capabilities.viewportRect) === null || _d === void 0 ? void 0 : _d.top,
47
+ };
48
+ if (viewport.displaySize && viewport.orientation && capabilities.viewportRect) {
49
+ viewport.navigationBarSize =
50
+ viewport.orientation === 'landscape'
51
+ ? viewport.displaySize.width - (capabilities.viewportRect.left + capabilities.viewportRect.width)
52
+ : viewport.displaySize.height - (capabilities.viewportRect.top + capabilities.viewportRect.height);
46
53
  }
47
- return info;
54
+ return viewport;
48
55
  }
49
- exports.parseCapabilities = parseCapabilities;
56
+ exports.extractCapabilitiesViewport = extractCapabilitiesViewport;
50
57
  function isW3C(capabilities) {
51
58
  const isW3C = Boolean((capabilities.platformName || capabilities.browserVersion) &&
52
59
  (capabilities.platformVersion || capabilities.hasOwnProperty('setWindowRect')));
package/dist/context.js CHANGED
@@ -101,11 +101,12 @@ class Context {
101
101
  var _a;
102
102
  await this.focus();
103
103
  const { parent, all, wait } = options;
104
- const transformedSelector = specUtils.transformSelector(this._spec, selector, this.driver);
104
+ const environment = await this.driver.getEnvironment();
105
+ const transformedSelector = specUtils.transformSelector(this._spec, selector, environment);
105
106
  let elements = [];
106
107
  if (wait) {
107
108
  if (this._spec.waitForSelector) {
108
- const element = await this._spec.waitForSelector(this.target, specUtils.transformSelector(this._spec, selector, this.driver), parent, wait);
109
+ const element = await this._spec.waitForSelector(this.target, specUtils.transformSelector(this._spec, selector, environment), parent, wait);
109
110
  if (element)
110
111
  elements = [element];
111
112
  }
@@ -113,7 +114,7 @@ class Context {
113
114
  let waiting = true;
114
115
  const timeout = setTimeout(() => (waiting = false), wait.timeout);
115
116
  while (waiting) {
116
- const element = await this._spec.findElement(this.target, specUtils.transformSelector(this._spec, selector, this.driver), parent);
117
+ const element = await this._spec.findElement(this.target, specUtils.transformSelector(this._spec, selector, environment), parent);
117
118
  if (element) {
118
119
  clearTimeout(timeout);
119
120
  elements = [element];
@@ -393,12 +394,13 @@ class Context {
393
394
  async getScrollingElement() {
394
395
  if (!(this._scrollingElement instanceof element_1.Element)) {
395
396
  await this.focus();
397
+ const environment = await this.driver.getEnvironment();
396
398
  if (this._scrollingElement) {
397
399
  this._scrollingElement = await this.element(this._scrollingElement);
398
400
  }
399
- else if (this.driver.isWeb) {
401
+ else if (environment.isWeb) {
400
402
  let selector;
401
- if (this.driver.isIOS && !this.driver.isEmulation) {
403
+ if (environment.isIOS && !environment.isEmulation) {
402
404
  selector = 'html';
403
405
  this._logger.log(`Using hardcoded default scrolling element for Safari on iOS - "${selector}"`);
404
406
  }
@@ -518,12 +520,13 @@ class Context {
518
520
  else
519
521
  region = { x: 0, y: 0, width: Infinity, height: Infinity };
520
522
  let currentContext = this;
523
+ const environment = await this.driver.getEnvironment();
521
524
  while (currentContext) {
522
525
  const contextRegion = await currentContext.getClientRegion();
523
526
  // const contextScrollingRegion = await currentContext.getScrollingRegion()
524
527
  const parentContextInnerOffset = (_b = (await ((_a = currentContext.parent) === null || _a === void 0 ? void 0 : _a.getInnerOffset()))) !== null && _b !== void 0 ? _b : { x: 0, y: 0 };
525
528
  // TODO revisit
526
- if (this.driver.isWeb ||
529
+ if (environment.isWeb ||
527
530
  (!utils.geometry.equals(contextRegion, region) && utils.geometry.contains(contextRegion, region))) {
528
531
  this._logger.log('Intersecting context region', contextRegion, 'with context region', region);
529
532
  region = utils.geometry.intersect(contextRegion, utils.geometry.offset(region, contextRegion));
@@ -535,11 +538,14 @@ class Context {
535
538
  return region;
536
539
  }
537
540
  async getCookies() {
538
- var _a, _b, _c;
539
- if (this.driver.isNative)
541
+ var _a, _b;
542
+ const environment = await this.driver.getEnvironment();
543
+ if (!environment.isWeb)
540
544
  return [];
541
545
  await this.focus();
542
- return (_c = (_b = (_a = this._spec).getCookies) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, true)) !== null && _c !== void 0 ? _c : [];
546
+ const cookies = await ((_b = (_a = this._spec).getCookies) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, true));
547
+ this._logger.log('Extracted context cookies', cookies);
548
+ return cookies !== null && cookies !== void 0 ? cookies : [];
543
549
  }
544
550
  async preserveInnerOffset() {
545
551
  this._state.innerOffset = await this.getInnerOffset();