@applitools/driver 1.9.7 → 1.9.8

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.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCapabilities = void 0;
4
4
  function parseCapabilities(capabilities, customConfig) {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
6
6
  if (capabilities.capabilities)
7
7
  capabilities = capabilities.capabilities;
8
8
  if (!(customConfig === null || customConfig === void 0 ? void 0 : customConfig.keepPlatformNameAsIs)) {
@@ -35,9 +35,9 @@ function parseCapabilities(capabilities, customConfig) {
35
35
  if (info.isNative) {
36
36
  info.displaySize = extractDisplaySize(capabilities);
37
37
  info.pixelRatio = capabilities.pixelRatio;
38
- info.statusBarHeight = capabilities.statBarHeight;
38
+ info.statusBarSize = (_o = capabilities.statBarHeight) !== null && _o !== void 0 ? _o : (_p = capabilities.viewportRect) === null || _p === void 0 ? void 0 : _p.top;
39
39
  if (info.displaySize && info.orientation && capabilities.viewportRect) {
40
- info.navigationBarHeight =
40
+ info.navigationBarSize =
41
41
  info.orientation === 'landscape'
42
42
  ? info.displaySize.width - (capabilities.viewportRect.left + capabilities.viewportRect.width)
43
43
  : info.displaySize.height - (capabilities.viewportRect.top + capabilities.viewportRect.height);
package/dist/context.js CHANGED
@@ -232,12 +232,11 @@ class Context {
232
232
  }
233
233
  return {
234
234
  context,
235
- shadow: root ? new element_1.Element({ spec: this._spec, context, element, logger: this._logger, root }) : null,
235
+ shadow: element && new element_1.Element({ spec: this._spec, context, element, logger: this._logger }),
236
236
  selector: currentSelector,
237
237
  };
238
238
  }
239
239
  async element(elementOrSelector) {
240
- var _a;
241
240
  if (this._spec.isElement(elementOrSelector)) {
242
241
  return new element_1.Element({ spec: this._spec, context: this, element: elementOrSelector, logger: this._logger });
243
242
  }
@@ -249,7 +248,7 @@ class Context {
249
248
  const root = await this.root(elementOrSelector);
250
249
  if (!root)
251
250
  return null;
252
- const element = await this._spec.findElement(root.context.target, specUtils.transformSelector(this._spec, root.selector, this.driver), (_a = root.shadow) === null || _a === void 0 ? void 0 : _a.target);
251
+ const element = await this._spec.findElement(root.context.target, specUtils.transformSelector(this._spec, root.selector, this.driver), root.shadow && (await root.shadow.getShadowRoot()));
253
252
  // TODO root.selector is not a full selector from context root to an element, but selector inside a shadow
254
253
  return element
255
254
  ? new element_1.Element({ spec: this._spec, context: root.context, element, selector: root.selector, logger: this._logger })
@@ -260,7 +259,6 @@ class Context {
260
259
  }
261
260
  }
262
261
  async elements(elementOrSelector) {
263
- var _a;
264
262
  if (this._spec.isElement(elementOrSelector)) {
265
263
  return [new element_1.Element({ spec: this._spec, context: this, element: elementOrSelector, logger: this._logger })];
266
264
  }
@@ -272,7 +270,7 @@ class Context {
272
270
  const root = await this.root(elementOrSelector);
273
271
  if (!root)
274
272
  return [];
275
- const elements = await this._spec.findElements(root.context.target, specUtils.transformSelector(this._spec, root.selector, this.driver), (_a = root.shadow) === null || _a === void 0 ? void 0 : _a.target);
273
+ const elements = await this._spec.findElements(root.context.target, specUtils.transformSelector(this._spec, root.selector, this.driver), root.shadow && (await root.shadow.getShadowRoot()));
276
274
  return elements.map((element, index) => {
277
275
  // TODO root.selector is not a full selector from context root to an element, but selector inside a shadow
278
276
  return new element_1.Element({
package/dist/driver.js CHANGED
@@ -107,13 +107,13 @@ class Driver {
107
107
  var _a;
108
108
  return (_a = this._driverInfo.viewportScale) !== null && _a !== void 0 ? _a : 1;
109
109
  }
110
- get statusBarHeight() {
110
+ get statusBarSize() {
111
111
  var _a;
112
- return (_a = this._driverInfo.statusBarHeight) !== null && _a !== void 0 ? _a : (this.isNative ? 0 : undefined);
112
+ return (_a = this._driverInfo.statusBarSize) !== null && _a !== void 0 ? _a : (this.isNative ? 0 : undefined);
113
113
  }
114
- get navigationBarHeight() {
114
+ get navigationBarSize() {
115
115
  var _a;
116
- return (_a = this._driverInfo.navigationBarHeight) !== null && _a !== void 0 ? _a : (this.isNative ? 0 : undefined);
116
+ return (_a = this._driverInfo.navigationBarSize) !== null && _a !== void 0 ? _a : (this.isNative ? 0 : undefined);
117
117
  }
118
118
  get isNative() {
119
119
  var _a, _b;
@@ -144,84 +144,100 @@ class Driver {
144
144
  this._currentContext = context;
145
145
  }
146
146
  async init() {
147
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
148
- var _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
147
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
148
+ var _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
149
149
  const capabilities = await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
150
150
  this._logger.log('Driver capabilities', capabilities);
151
151
  const capabilitiesInfo = capabilities ? (0, capabilities_1.parseCapabilities)(capabilities, this._customConfig) : undefined;
152
152
  const driverInfo = await ((_d = (_c = this._spec).getDriverInfo) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
153
153
  this._driverInfo = { ...capabilitiesInfo, ...driverInfo };
154
+ if (this.isMobile) {
155
+ this._driverInfo.orientation =
156
+ (_e = (await this.getOrientation().catch(() => undefined))) !== null && _e !== void 0 ? _e : this._driverInfo.orientation;
157
+ }
154
158
  if (this.isWeb) {
155
- (_e = (_x = this._driverInfo).pixelRatio) !== null && _e !== void 0 ? _e : (_x.pixelRatio = await this.execute(snippets.getPixelRatio));
156
- (_f = (_y = this._driverInfo).viewportScale) !== null && _f !== void 0 ? _f : (_y.viewportScale = await this.execute(snippets.getViewportScale));
157
- (_g = (_z = this._driverInfo).userAgent) !== null && _g !== void 0 ? _g : (_z.userAgent = await this.execute(snippets.getUserAgent));
159
+ (_f = (_y = this._driverInfo).pixelRatio) !== null && _f !== void 0 ? _f : (_y.pixelRatio = await this.execute(snippets.getPixelRatio));
160
+ (_g = (_z = this._driverInfo).viewportScale) !== null && _g !== void 0 ? _g : (_z.viewportScale = await this.execute(snippets.getViewportScale));
161
+ (_h = (_0 = this._driverInfo).userAgent) !== null && _h !== void 0 ? _h : (_0.userAgent = await this.execute(snippets.getUserAgent));
158
162
  if (this._driverInfo.userAgent) {
159
163
  const userAgentInfo = (0, user_agent_1.parseUserAgent)(this._driverInfo.userAgent);
160
- this._driverInfo.browserName = (_h = userAgentInfo.browserName) !== null && _h !== void 0 ? _h : this._driverInfo.browserName;
161
- this._driverInfo.browserVersion = (_j = userAgentInfo.browserVersion) !== null && _j !== void 0 ? _j : this._driverInfo.browserVersion;
164
+ this._driverInfo.browserName = (_j = userAgentInfo.browserName) !== null && _j !== void 0 ? _j : this._driverInfo.browserName;
165
+ this._driverInfo.browserVersion = (_k = userAgentInfo.browserVersion) !== null && _k !== void 0 ? _k : this._driverInfo.browserVersion;
162
166
  if (this._driverInfo.isMobile) {
163
- (_k = (_0 = this._driverInfo).platformName) !== null && _k !== void 0 ? _k : (_0.platformName = userAgentInfo.platformName);
164
- (_l = (_1 = this._driverInfo).platformVersion) !== null && _l !== void 0 ? _l : (_1.platformVersion = userAgentInfo.platformVersion);
167
+ (_l = (_1 = this._driverInfo).platformName) !== null && _l !== void 0 ? _l : (_1.platformName = userAgentInfo.platformName);
168
+ (_m = (_2 = this._driverInfo).platformVersion) !== null && _m !== void 0 ? _m : (_2.platformVersion = userAgentInfo.platformVersion);
165
169
  }
166
170
  else {
167
- this._driverInfo.platformName = (_m = userAgentInfo.platformName) !== null && _m !== void 0 ? _m : this._driverInfo.platformName;
168
- this._driverInfo.platformVersion = (_o = userAgentInfo.platformVersion) !== null && _o !== void 0 ? _o : this._driverInfo.platformVersion;
171
+ this._driverInfo.platformName = (_o = userAgentInfo.platformName) !== null && _o !== void 0 ? _o : this._driverInfo.platformName;
172
+ this._driverInfo.platformVersion = (_p = userAgentInfo.platformVersion) !== null && _p !== void 0 ? _p : this._driverInfo.platformVersion;
169
173
  }
170
174
  }
171
- (_p = (_2 = this._driverInfo).features) !== null && _p !== void 0 ? _p : (_2.features = {});
172
- (_q = (_3 = this._driverInfo.features).allCookies) !== null && _q !== void 0 ? _q : (_3.allCookies = /chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile);
175
+ (_q = (_3 = this._driverInfo).features) !== null && _q !== void 0 ? _q : (_3.features = {});
176
+ (_r = (_4 = this._driverInfo.features).allCookies) !== null && _r !== void 0 ? _r : (_4.allCookies = /chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile);
173
177
  }
174
178
  else {
175
179
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
176
180
  let windowSize = await this._spec.getWindowSize(this.target);
177
- (_r = (_4 = this._driverInfo).displaySize) !== null && _r !== void 0 ? _r : (_4.displaySize = windowSize);
178
- const orientation = await this.getOrientation();
181
+ (_s = (_5 = this._driverInfo).displaySize) !== null && _s !== void 0 ? _s : (_5.displaySize = windowSize);
179
182
  if (this.isAndroid) {
180
183
  // bar sizes could be extracted only on android
181
- const barsSize = await ((_t = (_s = this._spec).getBarsSize) === null || _t === void 0 ? void 0 : _t.call(_s, this.target).catch(() => undefined));
182
- if (barsSize) {
183
- this._logger.log('Driver bars size', barsSize);
184
- // navigation bar height is replaced with the width in landscape orientation on android (due to the bug in appium)
185
- if (orientation === 'landscape')
186
- barsSize.navigationBarHeight = barsSize.navigationBarWidth;
184
+ const systemBars = await ((_u = (_t = this._spec).getSystemBars) === null || _u === void 0 ? void 0 : _u.call(_t, this.target).catch(() => null));
185
+ const { statusBar, navigationBar } = systemBars !== null && systemBars !== void 0 ? systemBars : {};
186
+ if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
187
+ this._logger.log('Driver status bar', statusBar);
188
+ const statusBarSize = statusBar.height;
187
189
  // when status bar is overlapping content on android it returns status bar height equal to display height
188
- if (barsSize.statusBarHeight < this._driverInfo.displaySize.height) {
189
- this._driverInfo.statusBarHeight = Math.max((_u = this._driverInfo.statusBarHeight) !== null && _u !== void 0 ? _u : 0, barsSize.statusBarHeight);
190
+ if (statusBarSize < this._driverInfo.displaySize.height) {
191
+ this._driverInfo.statusBarSize = Math.max((_v = this._driverInfo.statusBarSize) !== null && _v !== void 0 ? _v : 0, statusBarSize);
190
192
  }
191
- // when navigation bar is invisible on android it returns navigation bar height equal to display height
192
- if (barsSize.navigationBarHeight < this._driverInfo.displaySize.height) {
193
- this._driverInfo.navigationBarHeight = Math.max((_v = this._driverInfo.navigationBarHeight) !== null && _v !== void 0 ? _v : 0, barsSize.navigationBarHeight);
193
+ }
194
+ if (navigationBar === null || navigationBar === void 0 ? void 0 : navigationBar.visible) {
195
+ this._logger.log('Driver navigation size', navigationBar);
196
+ // if navigation bar is placed on the right side is screen the the orientation is landscape-secondary
197
+ if (navigationBar.x > 0)
198
+ this._driverInfo.orientation = 'landscape-secondary';
199
+ // navigation bar size could be its height or width depending on screen orientation
200
+ const navigationBarSize = navigationBar[this.orientation.startsWith('landscape') ? 'width' : 'height'];
201
+ // when navigation bar is invisible on android it returns navigation bar size equal to display size
202
+ if (navigationBarSize <
203
+ this._driverInfo.displaySize[this.orientation.startsWith('landscape') ? 'width' : 'height']) {
204
+ this._driverInfo.navigationBarSize = Math.max((_w = this._driverInfo.navigationBarSize) !== null && _w !== void 0 ? _w : 0, navigationBarSize);
194
205
  }
195
206
  else {
196
- this._driverInfo.navigationBarHeight = 0;
207
+ this._driverInfo.navigationBarSize = 0;
197
208
  }
198
- // bar heights have to be scaled on android
199
- (_5 = this._driverInfo).statusBarHeight && (_5.statusBarHeight = this._driverInfo.statusBarHeight / this.pixelRatio);
200
- (_6 = this._driverInfo).navigationBarHeight && (_6.navigationBarHeight = this._driverInfo.navigationBarHeight / this.pixelRatio);
201
209
  }
202
- windowSize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio);
203
- (_7 = this._driverInfo).displaySize && (_7.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
210
+ // bar sizes have to be scaled on android
211
+ (_6 = this._driverInfo).statusBarSize && (_6.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio);
212
+ (_7 = this._driverInfo).navigationBarSize && (_7.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio);
213
+ windowSize = utils.geometry.scale(windowSize, 1 / this.pixelRatio);
214
+ (_8 = this._driverInfo).displaySize && (_8.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
204
215
  }
216
+ // calculate viewport location
217
+ (_x = (_9 = this._driverInfo).viewportLocation) !== null && _x !== void 0 ? _x : (_9.viewportLocation = {
218
+ x: this.orientation === 'landscape' ? this.navigationBarSize : 0,
219
+ y: this.statusBarSize,
220
+ });
205
221
  // calculate viewport size
206
222
  if (!this._driverInfo.viewportSize) {
207
- if (this.navigationBarHeight > 1) {
208
- if (orientation === 'landscape') {
223
+ if (this.navigationBarSize > 1) {
224
+ if (this.orientation.startsWith('landscape')) {
209
225
  this._driverInfo.viewportSize = {
210
- width: this._driverInfo.displaySize.height - this.navigationBarHeight,
211
- height: this._driverInfo.displaySize.width - this.statusBarHeight,
226
+ width: this._driverInfo.displaySize.height - this.navigationBarSize,
227
+ height: this._driverInfo.displaySize.width - this.statusBarSize,
212
228
  };
213
229
  }
214
230
  else {
215
231
  this._driverInfo.viewportSize = {
216
232
  width: this._driverInfo.displaySize.width,
217
- height: this._driverInfo.displaySize.height - this.statusBarHeight - this.navigationBarHeight,
233
+ height: this._driverInfo.displaySize.height - this.statusBarSize - this.navigationBarSize,
218
234
  };
219
235
  }
220
236
  }
221
237
  else {
222
238
  this._driverInfo.viewportSize = {
223
239
  width: windowSize.width,
224
- height: windowSize.height - this.statusBarHeight,
240
+ height: windowSize.height - this.statusBarSize,
225
241
  };
226
242
  }
227
243
  }
@@ -247,9 +263,6 @@ class Driver {
247
263
  ? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this, logger: this._logger })
248
264
  : await helper_android_1.HelperAndroid.make({ spec: this._spec, driver: this, logger: this._logger });
249
265
  }
250
- if (this.isMobile) {
251
- (_w = (_8 = this._driverInfo).orientation) !== null && _w !== void 0 ? _w : (_8.orientation = await this.getOrientation().catch(() => undefined));
252
- }
253
266
  this._logger.log('Combined driver info', this._driverInfo);
254
267
  return this;
255
268
  }
@@ -416,7 +429,7 @@ class Driver {
416
429
  return this.currentContext;
417
430
  }
418
431
  async normalizeRegion(region) {
419
- if (this.isWeb || !utils.types.has(this._driverInfo, ['viewportSize', 'statusBarHeight']))
432
+ if (this.isWeb)
420
433
  return region;
421
434
  let normalizedRegion = region;
422
435
  if (this.isAndroid) {
@@ -425,10 +438,7 @@ class Driver {
425
438
  if (this.isIOS && utils.geometry.isIntersected(normalizedRegion, this._driverInfo.safeArea)) {
426
439
  normalizedRegion = utils.geometry.intersect(normalizedRegion, this._driverInfo.safeArea);
427
440
  }
428
- normalizedRegion = utils.geometry.offsetNegative(normalizedRegion, {
429
- x: this.isAndroid && this.orientation === 'landscape' && this.platformVersion > 7 ? this.navigationBarHeight : 0,
430
- y: this.statusBarHeight,
431
- });
441
+ normalizedRegion = utils.geometry.offsetNegative(normalizedRegion, this._driverInfo.viewportLocation);
432
442
  if (normalizedRegion.y < 0) {
433
443
  normalizedRegion.height += normalizedRegion.y;
434
444
  normalizedRegion.y = 0;
@@ -455,6 +465,13 @@ class Driver {
455
465
  }
456
466
  return image;
457
467
  }
468
+ async getViewportRegion() {
469
+ var _a, _b;
470
+ return {
471
+ ...((_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.viewportLocation) !== null && _b !== void 0 ? _b : { x: 0, y: 0 }),
472
+ ...(await this.getViewportSize()),
473
+ };
474
+ }
458
475
  async getViewportSize() {
459
476
  var _a;
460
477
  let size;
@@ -466,7 +483,7 @@ class Driver {
466
483
  else {
467
484
  this._logger.log('Extracting viewport size from native driver');
468
485
  size = await this.getDisplaySize();
469
- size.height -= this.statusBarHeight;
486
+ size.height -= this.statusBarSize;
470
487
  }
471
488
  this._logger.log(`Rounding viewport size using`, this._customConfig.useCeilForViewportSize ? 'ceil' : 'round');
472
489
  if (this._customConfig.useCeilForViewportSize) {
@@ -531,7 +548,7 @@ class Driver {
531
548
  return this._driverInfo.displaySize;
532
549
  }
533
550
  let size = await this._spec.getWindowSize(this.target);
534
- if ((await this.getOrientation()) === 'landscape' && size.height > size.width) {
551
+ if ((await this.getOrientation()).startsWith('landscape') && size.height > size.width) {
535
552
  size = { width: size.height, height: size.width };
536
553
  }
537
554
  const normalizedSize = this.isAndroid ? utils.geometry.scale(size, 1 / this.pixelRatio) : size;
@@ -541,7 +558,27 @@ class Driver {
541
558
  async getOrientation() {
542
559
  if (this.isWeb && !this.isMobile)
543
560
  return;
544
- const orientation = await this._spec.getOrientation(this.target);
561
+ let orientation;
562
+ if (this.isAndroid) {
563
+ this._logger.log('Extracting device orientation using adb command on android');
564
+ const rotation = await this.execute('mobile:shell', {
565
+ command: "dumpsys window | grep 'mCurrentRotation' | cut -d = -f2",
566
+ })
567
+ .then(r => { var _a; return (_a = r === null || r === void 0 ? void 0 : r.trim) === null || _a === void 0 ? void 0 : _a.call(r); })
568
+ .catch(() => null);
569
+ if (rotation === 'ROTATION_0')
570
+ orientation = 'portrait';
571
+ else if (rotation === 'ROTATION_90')
572
+ orientation = 'landscape-secondary';
573
+ else if (rotation === 'ROTATION_180')
574
+ orientation = 'portrait-secondary';
575
+ else if (rotation === 'ROTATION_270')
576
+ orientation = 'landscape';
577
+ }
578
+ if (!orientation) {
579
+ this._logger.log('Extracting device orientation');
580
+ orientation = await this._spec.getOrientation(this.target);
581
+ }
545
582
  this._logger.log('Extracted device orientation:', orientation);
546
583
  return orientation;
547
584
  }
package/dist/element.js CHANGED
@@ -39,16 +39,9 @@ class Element {
39
39
  if (options.logger)
40
40
  this._logger = options.logger;
41
41
  if (this._spec.isElement(options.element)) {
42
- let elementToUse = options.element;
43
- if (options.root) {
44
- elementToUse = options.root;
45
- this._target = elementToUse;
46
- }
47
- else {
48
- this._target = (_c = (_b = (_a = this._spec).transformElement) === null || _b === void 0 ? void 0 : _b.call(_a, elementToUse)) !== null && _c !== void 0 ? _c : elementToUse;
49
- }
42
+ this._target = (_c = (_b = (_a = this._spec).transformElement) === null || _b === void 0 ? void 0 : _b.call(_a, options.element)) !== null && _c !== void 0 ? _c : options.element;
50
43
  // Some frameworks contains information about the selector inside an element
51
- this._selector = (_d = options.selector) !== null && _d !== void 0 ? _d : (_f = (_e = this._spec).extractSelector) === null || _f === void 0 ? void 0 : _f.call(_e, elementToUse);
44
+ this._selector = (_d = options.selector) !== null && _d !== void 0 ? _d : (_f = (_e = this._spec).extractSelector) === null || _f === void 0 ? void 0 : _f.call(_e, options.element);
52
45
  this._index = options.index;
53
46
  }
54
47
  else if (specUtils.isSelector(this._spec, options.selector)) {
@@ -57,6 +50,9 @@ class Element {
57
50
  else {
58
51
  throw new TypeError('Element constructor called with argument of unknown type!');
59
52
  }
53
+ if (this._selector && this._spec.untransformSelector) {
54
+ this._commonSelector = this._spec.untransformSelector(this._spec.transformSelector(this._selector));
55
+ }
60
56
  }
61
57
  get target() {
62
58
  return this._target;
@@ -64,6 +60,12 @@ class Element {
64
60
  get selector() {
65
61
  return this._selector;
66
62
  }
63
+ get commonSelector() {
64
+ return this._commonSelector;
65
+ }
66
+ get index() {
67
+ return this._index;
68
+ }
67
69
  get context() {
68
70
  return this._context;
69
71
  }
@@ -218,8 +220,8 @@ class Element {
218
220
  if (this.driver.isAndroid) {
219
221
  this._state.contentSize = utils.geometry.scale(this._state.contentSize, 1 / this.driver.pixelRatio);
220
222
  }
221
- if (contentRegion.y < this.driver.statusBarHeight) {
222
- this._state.contentSize.height -= this.driver.statusBarHeight - contentRegion.y;
223
+ if (contentRegion.y < this.driver.statusBarSize) {
224
+ this._state.contentSize.height -= this.driver.statusBarSize - contentRegion.y;
223
225
  }
224
226
  return this._state.contentSize;
225
227
  }
@@ -277,6 +279,11 @@ class Element {
277
279
  }
278
280
  });
279
281
  }
282
+ async getShadowRoot() {
283
+ if (!this.driver.isWeb)
284
+ return null;
285
+ return this._spec.executeScript(this.context.target, snippets.getShadowRoot, [this.target]);
286
+ }
280
287
  async getTouchPadding() {
281
288
  var _a, _b;
282
289
  if (this._state.touchPadding == null) {
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.transformSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
26
+ exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.untransformSelector = exports.transformSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
27
27
  const utils = __importStar(require("@applitools/utils"));
28
28
  function isDriver(driver) {
29
29
  return driver && driver.constructor.name === 'MockDriver';
@@ -41,6 +41,24 @@ function transformSelector(selector) {
41
41
  return utils.types.has(selector, 'selector') ? selector.selector : selector;
42
42
  }
43
43
  exports.transformSelector = transformSelector;
44
+ function untransformSelector(selector) {
45
+ if (utils.types.isString(selector)) {
46
+ return { type: 'css', selector: selector };
47
+ }
48
+ else if (utils.types.has(selector, ['using', 'value'])) {
49
+ return { type: selector.using === 'css selector' ? 'css' : selector.using, selector: selector.value };
50
+ }
51
+ else if (utils.types.has(selector, ['selector'])) {
52
+ return selector;
53
+ }
54
+ }
55
+ exports.untransformSelector = untransformSelector;
56
+ function extractSelector(element) {
57
+ if (utils.types.has(element, ['selector'])) {
58
+ return element.selector;
59
+ }
60
+ }
61
+ exports.extractSelector = extractSelector;
44
62
  function isStaleElementError() {
45
63
  return false;
46
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "@applitools/logger": "1.1.13",
80
80
  "@applitools/snippets": "2.4.3",
81
- "@applitools/types": "1.5.4",
81
+ "@applitools/types": "1.5.5",
82
82
  "@applitools/utils": "1.3.9"
83
83
  },
84
84
  "devDependencies": {
package/types/driver.d.ts CHANGED
@@ -34,11 +34,11 @@ export declare class Driver<TDriver, TContext, TElement, TSelector> {
34
34
  get browserName(): string;
35
35
  get browserVersion(): string | number;
36
36
  get userAgent(): string;
37
- get orientation(): 'portrait' | 'landscape';
37
+ get orientation(): 'portrait' | 'landscape' | 'portrait-secondary' | 'landscape-secondary';
38
38
  get pixelRatio(): number;
39
39
  get viewportScale(): number;
40
- get statusBarHeight(): number;
41
- get navigationBarHeight(): number;
40
+ get statusBarSize(): number;
41
+ get navigationBarSize(): number;
42
42
  get isNative(): boolean;
43
43
  get isWeb(): boolean;
44
44
  get isMobile(): boolean;
@@ -59,10 +59,11 @@ export declare class Driver<TDriver, TContext, TElement, TSelector> {
59
59
  elements(selector: types.Selector<TSelector>): Promise<Element<TDriver, TContext, TElement, TSelector>[]>;
60
60
  execute(script: ((arg: any) => any) | string, arg?: any): Promise<any>;
61
61
  takeScreenshot(): Promise<Buffer>;
62
+ getViewportRegion(): Promise<types.Region>;
62
63
  getViewportSize(): Promise<types.Size>;
63
64
  setViewportSize(size: types.Size): Promise<void>;
64
65
  getDisplaySize(): Promise<types.Size>;
65
- getOrientation(): Promise<'portrait' | 'landscape'>;
66
+ getOrientation(): Promise<'portrait' | 'landscape' | 'portrait-secondary' | 'landscape-secondary'>;
66
67
  setOrientation(orientation: 'portrait' | 'landscape'): Promise<void>;
67
68
  getCookies(): Promise<types.Cookie[]>;
68
69
  getTitle(): Promise<string>;
@@ -13,6 +13,7 @@ export declare class Element<TDriver, TContext, TElement, TSelector> {
13
13
  private _target;
14
14
  private _context;
15
15
  private _selector;
16
+ private _commonSelector?;
16
17
  private _index;
17
18
  private _state;
18
19
  private _originalOverflow;
@@ -25,10 +26,11 @@ export declare class Element<TDriver, TContext, TElement, TSelector> {
25
26
  selector?: types.Selector<TSelector>;
26
27
  index?: number;
27
28
  logger?: Logger;
28
- root?: TElement;
29
29
  });
30
30
  get target(): TElement;
31
31
  get selector(): types.Selector<TSelector>;
32
+ get commonSelector(): types.Selector<never>;
33
+ get index(): number;
32
34
  get context(): Context<TDriver, TContext, TElement, TSelector>;
33
35
  get driver(): import("./driver").Driver<TDriver, TContext, TElement, TSelector>;
34
36
  get isRef(): boolean;
@@ -41,6 +43,7 @@ export declare class Element<TDriver, TContext, TElement, TSelector> {
41
43
  isPager(): Promise<boolean>;
42
44
  isScrollable(): Promise<boolean>;
43
45
  isRoot(): Promise<boolean>;
46
+ getShadowRoot(): Promise<TElement>;
44
47
  getTouchPadding(): Promise<number>;
45
48
  getText(): Promise<string>;
46
49
  getAttribute(name: string): Promise<string>;
@@ -6,12 +6,18 @@ export declare type Selector = string | {
6
6
  using: string;
7
7
  value: string;
8
8
  };
9
+ declare type CommonSelector = string | {
10
+ selector: Selector | string;
11
+ type?: string;
12
+ };
9
13
  export declare function isDriver(driver: any): driver is Driver;
10
14
  export declare function isElement(element: any): element is Element;
11
15
  export declare function isSelector(selector: any): selector is Selector;
12
16
  export declare function transformSelector(selector: Selector | {
13
17
  selector: Selector;
14
18
  }): Selector;
19
+ export declare function untransformSelector(selector: Selector): CommonSelector;
20
+ export declare function extractSelector(element: Element): any;
15
21
  export declare function isStaleElementError(): boolean;
16
22
  export declare function isEqualElements(_driver: Driver, element1: Element, element2: Element): Promise<boolean>;
17
23
  export declare function executeScript(driver: Driver, script: ((arg: any) => any) | string, arg: any): Promise<any>;
@@ -28,3 +34,4 @@ export declare function getOrientation(_driver: Driver): Promise<'portrait' | 'l
28
34
  export declare function getUrl(driver: Driver): Promise<string>;
29
35
  export declare function getTitle(driver: Driver): Promise<string>;
30
36
  export declare function visit(driver: Driver, url: string): Promise<void>;
37
+ export {};