@applitools/driver 1.16.0 → 1.16.1

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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.16.1](https://github.com/applitools/eyes.sdk.javascript1/compare/js/driver@1.16.0...js/driver@1.16.1) (2023-12-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fixed bug with screenshot not being properly scaled on ios devices with appium 2 ([#2092](https://github.com/applitools/eyes.sdk.javascript1/issues/2092)) ([26678bf](https://github.com/applitools/eyes.sdk.javascript1/commit/26678bfe254def506ea82e6a645519d6567fb3fd))
9
+ * fixed extraction of the driver server url ([ddc6449](https://github.com/applitools/eyes.sdk.javascript1/commit/ddc6449fc72166ab26c99e9ba7bb83c05fd591d6))
10
+ * fixed infinite loop that may appear during attribute extraction ([#2102](https://github.com/applitools/eyes.sdk.javascript1/issues/2102)) ([6bef680](https://github.com/applitools/eyes.sdk.javascript1/commit/6bef680fbd2d5c26a46cf2a4f00bd083d1d02109))
11
+
3
12
  ## [1.16.0](https://github.com/applitools/eyes.sdk.javascript1/compare/js/driver@1.15.3...js/driver@1.16.0) (2023-12-18)
4
13
 
5
14
 
package/dist/driver.js CHANGED
@@ -282,8 +282,8 @@ class Driver {
282
282
  return this._environment;
283
283
  }
284
284
  async getViewport() {
285
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
286
- var _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
285
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
286
+ var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
287
287
  if (!this._viewport) {
288
288
  const environment = await this.getEnvironment();
289
289
  const driverInfo = await this.getDriverInfo();
@@ -300,16 +300,15 @@ class Driver {
300
300
  const capabilitiesViewport = capabilities ? (0, capabilities_1.extractCapabilitiesViewport)(capabilities) : null;
301
301
  this._logger.log('Extracted capabilities viewport', capabilitiesViewport);
302
302
  this._viewport = { ...capabilitiesViewport, ...this._viewport };
303
- (_a = (_y = this._viewport).pixelRatio) !== null && _a !== void 0 ? _a : (_y.pixelRatio = 1);
304
303
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
305
304
  let windowSize = await this._spec.getWindowSize(this.target);
306
- (_b = (_z = this._viewport).displaySize) !== null && _b !== void 0 ? _b : (_z.displaySize = windowSize);
307
- if (((_c = this._viewport.orientation) === null || _c === void 0 ? void 0 : _c.startsWith('landscape')) &&
305
+ (_a = (_1 = this._viewport).displaySize) !== null && _a !== void 0 ? _a : (_1.displaySize = windowSize);
306
+ if (((_b = this._viewport.orientation) === null || _b === void 0 ? void 0 : _b.startsWith('landscape')) &&
308
307
  this._viewport.displaySize.height > this._viewport.displaySize.width) {
309
308
  this._viewport.displaySize = utils.geometry.rotate(this._viewport.displaySize, 90);
310
309
  }
311
310
  if (environment.isAndroid) {
312
- // bar sizes could be extracted only on android
311
+ (_c = (_2 = this._viewport).pixelRatio) !== null && _c !== void 0 ? _c : (_2.pixelRatio = 1);
313
312
  const { statusBar, navigationBar } = (_f = (await ((_e = (_d = this._spec).getSystemBars) === null || _e === void 0 ? void 0 : _e.call(_d, this.target).catch(() => undefined)))) !== null && _f !== void 0 ? _f : {};
314
313
  if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
315
314
  this._logger.log('Driver status bar', statusBar);
@@ -336,20 +335,26 @@ class Driver {
336
335
  }
337
336
  }
338
337
  // bar sizes have to be scaled on android
339
- (_0 = this._viewport).statusBarSize && (_0.statusBarSize = this._viewport.statusBarSize / this._viewport.pixelRatio);
340
- (_1 = this._viewport).navigationBarSize && (_1.navigationBarSize = this._viewport.navigationBarSize / this._viewport.pixelRatio);
338
+ (_3 = this._viewport).statusBarSize && (_3.statusBarSize = this._viewport.statusBarSize / this._viewport.pixelRatio);
339
+ (_4 = this._viewport).navigationBarSize && (_4.navigationBarSize = this._viewport.navigationBarSize / this._viewport.pixelRatio);
341
340
  windowSize = utils.geometry.scale(windowSize, 1 / this._viewport.pixelRatio);
342
- (_2 = this._viewport).displaySize && (_2.displaySize = utils.geometry.scale(this._viewport.displaySize, 1 / this._viewport.pixelRatio));
343
- (_l = (_3 = this._viewport).navigationBarSize) !== null && _l !== void 0 ? _l : (_3.navigationBarSize = 0);
341
+ (_5 = this._viewport).displaySize && (_5.displaySize = utils.geometry.scale(this._viewport.displaySize, 1 / this._viewport.pixelRatio));
342
+ (_l = (_6 = this._viewport).navigationBarSize) !== null && _l !== void 0 ? _l : (_6.navigationBarSize = 0);
344
343
  }
345
344
  else if (environment.isIOS) {
346
- if ((_m = this._viewport.orientation) === null || _m === void 0 ? void 0 : _m.startsWith('landscape'))
345
+ if (!this._viewport.pixelRatio || !this._viewport.statusBarSize) {
346
+ const screen = await this.execute('mobile:deviceScreenInfo');
347
+ this._viewport.pixelRatio = (_m = screen.scale) !== null && _m !== void 0 ? _m : 0;
348
+ this._viewport.statusBarSize = (_o = screen.statusBarSize) === null || _o === void 0 ? void 0 : _o.height;
349
+ }
350
+ if ((_p = this._viewport.orientation) === null || _p === void 0 ? void 0 : _p.startsWith('landscape'))
347
351
  this._viewport.statusBarSize = 0;
348
352
  }
349
- (_o = (_4 = this._viewport).statusBarSize) !== null && _o !== void 0 ? _o : (_4.statusBarSize = 0);
353
+ (_q = (_7 = this._viewport).pixelRatio) !== null && _q !== void 0 ? _q : (_7.pixelRatio = 1);
354
+ (_r = (_8 = this._viewport).statusBarSize) !== null && _r !== void 0 ? _r : (_8.statusBarSize = 0);
350
355
  // calculate viewport location
351
- (_p = (_5 = this._viewport).viewportLocation) !== null && _p !== void 0 ? _p : (_5.viewportLocation = {
352
- x: this._viewport.orientation === 'landscape' ? (_q = this._viewport.navigationBarSize) !== null && _q !== void 0 ? _q : 0 : 0,
356
+ (_s = (_9 = this._viewport).viewportLocation) !== null && _s !== void 0 ? _s : (_9.viewportLocation = {
357
+ x: this._viewport.orientation === 'landscape' ? (_t = this._viewport.navigationBarSize) !== null && _t !== void 0 ? _t : 0 : 0,
353
358
  y: this._viewport.statusBarSize,
354
359
  });
355
360
  // calculate viewport size
@@ -357,7 +362,7 @@ class Driver {
357
362
  this._viewport.viewportSize = { ...this._viewport.displaySize };
358
363
  this._viewport.viewportSize.height -= this._viewport.statusBarSize;
359
364
  if (environment.isAndroid) {
360
- this._viewport.viewportSize[((_r = this._viewport.orientation) === null || _r === void 0 ? void 0 : _r.startsWith('landscape')) ? 'width' : 'height'] -=
365
+ this._viewport.viewportSize[((_u = this._viewport.orientation) === null || _u === void 0 ? void 0 : _u.startsWith('landscape')) ? 'width' : 'height'] -=
361
366
  this._viewport.navigationBarSize;
362
367
  }
363
368
  }
@@ -387,13 +392,13 @@ class Driver {
387
392
  }
388
393
  if (environment.isWeb) {
389
394
  const browserViewport = await this.execute(snippets.getViewport);
390
- (_s = (_6 = this._viewport).viewportSize) !== null && _s !== void 0 ? _s : (_6.viewportSize = browserViewport.viewportSize);
391
- (_t = (_7 = this._viewport).pixelRatio) !== null && _t !== void 0 ? _t : (_7.pixelRatio = browserViewport.pixelRatio);
392
- (_u = (_8 = this._viewport).viewportScale) !== null && _u !== void 0 ? _u : (_8.viewportScale = browserViewport.viewportScale);
393
- (_v = (_9 = this._viewport).orientation) !== null && _v !== void 0 ? _v : (_9.orientation = browserViewport.orientation);
395
+ (_v = (_10 = this._viewport).viewportSize) !== null && _v !== void 0 ? _v : (_10.viewportSize = browserViewport.viewportSize);
396
+ (_w = (_11 = this._viewport).pixelRatio) !== null && _w !== void 0 ? _w : (_11.pixelRatio = browserViewport.pixelRatio);
397
+ (_x = (_12 = this._viewport).viewportScale) !== null && _x !== void 0 ? _x : (_12.viewportScale = browserViewport.viewportScale);
398
+ (_y = (_13 = this._viewport).orientation) !== null && _y !== void 0 ? _y : (_13.orientation = browserViewport.orientation);
394
399
  }
395
- (_w = (_10 = this._viewport).pixelRatio) !== null && _w !== void 0 ? _w : (_10.pixelRatio = 1);
396
- (_x = (_11 = this._viewport).viewportScale) !== null && _x !== void 0 ? _x : (_11.viewportScale = 1);
400
+ (_z = (_14 = this._viewport).pixelRatio) !== null && _z !== void 0 ? _z : (_14.pixelRatio = 1);
401
+ (_0 = (_15 = this._viewport).viewportScale) !== null && _0 !== void 0 ? _0 : (_15.viewportScale = 1);
397
402
  this._logger.log('Extracted viewport', this._viewport);
398
403
  }
399
404
  return this._viewport;
@@ -418,7 +423,7 @@ class Driver {
418
423
  async getDriverUrl() {
419
424
  var _a;
420
425
  const driverInfo = await this.getDriverInfo();
421
- return (_a = driverInfo.remoteHostname) !== null && _a !== void 0 ? _a : null;
426
+ return (_a = driverInfo.driverServerUrl) !== null && _a !== void 0 ? _a : null;
422
427
  }
423
428
  async getHelper() {
424
429
  var _a, _b, _c;
package/dist/element.js CHANGED
@@ -189,14 +189,14 @@ class Element {
189
189
  if (!contentRegion || !environment.isAndroid) {
190
190
  let attrContentRegion = null;
191
191
  try {
192
- const size = JSON.parse(await this.getAttribute('contentSize'));
192
+ const { left, top, width, height, scrollableOffset } = JSON.parse(await this.getAttribute('contentSize'));
193
+ if ([left, top, width, height, scrollableOffset].some(value => !utils.types.isNumber(value)))
194
+ throw new Error('Invalid contentSize');
193
195
  attrContentRegion = {
194
- x: size.left,
195
- y: size.top,
196
- width: size.width,
197
- height: environment.isIOS
198
- ? Math.max(size.height, size.scrollableOffset)
199
- : size.height + size.scrollableOffset,
196
+ x: left,
197
+ y: top,
198
+ width: width,
199
+ height: environment.isIOS ? Math.max(height, scrollableOffset) : height + scrollableOffset,
200
200
  };
201
201
  }
202
202
  catch (err) {
@@ -368,9 +368,8 @@ class Element {
368
368
  return text;
369
369
  }
370
370
  async getAttribute(name) {
371
- var _a;
372
371
  // we assumes that attributes are not changed during the session
373
- if ((_a = this._state.attributes) === null || _a === void 0 ? void 0 : _a[name]) {
372
+ if (utils.types.has(this._state.attributes, name)) {
374
373
  if (this._state.attributes[name] instanceof Error)
375
374
  throw this._state.attributes[name];
376
375
  return this._state.attributes[name];
@@ -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.getCurrentWorld = exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.getElementText = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.toSimpleCommonSelector = exports.toSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
26
+ exports.performAction = exports.getElementAttribute = exports.getElementRegion = exports.getCurrentWorld = exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.getElementText = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.toSimpleCommonSelector = exports.toSelector = 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';
@@ -141,3 +141,15 @@ async function getCurrentWorld(driver) {
141
141
  return driver.getCurrentWorld();
142
142
  }
143
143
  exports.getCurrentWorld = getCurrentWorld;
144
+ async function getElementRegion(_driver, element) {
145
+ return element.region;
146
+ }
147
+ exports.getElementRegion = getElementRegion;
148
+ async function getElementAttribute(_driver, element, attr) {
149
+ return element.attrs[attr];
150
+ }
151
+ exports.getElementAttribute = getElementAttribute;
152
+ async function performAction(_driver, _steps) {
153
+ return;
154
+ }
155
+ exports.performAction = performAction;
@@ -18,7 +18,12 @@ class HelperIOS {
18
18
  }
19
19
  async getContentRegion(element) {
20
20
  var _a, _b;
21
- await this._element.click();
21
+ const { x, y } = await this._spec.getElementRegion(this._driver.target, this._element.target);
22
+ await this._spec.performAction(this._driver.target, [
23
+ { action: 'press', x, y },
24
+ { action: 'wait', ms: 300 },
25
+ { action: 'release' },
26
+ ]);
22
27
  const sizeLabel = await this._driver.element({ type: 'name', selector: 'applitools_content_size_label' });
23
28
  const sizeString = await (sizeLabel === null || sizeLabel === void 0 ? void 0 : sizeLabel.getText());
24
29
  if (!sizeString)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -1,4 +1,4 @@
1
- import type { Size } from '@applitools/utils';
1
+ import type { Region, Size } from '@applitools/utils';
2
2
  import type { DriverInfo } from '../types';
3
3
  export type Driver = any;
4
4
  export type Element = any;
@@ -36,4 +36,7 @@ export declare function getUrl(driver: Driver): Promise<string>;
36
36
  export declare function getTitle(driver: Driver): Promise<string>;
37
37
  export declare function visit(driver: Driver, url: string): Promise<void>;
38
38
  export declare function getCurrentWorld(driver: Driver): Promise<any>;
39
+ export declare function getElementRegion(_driver: Driver, element: Element): Promise<Region>;
40
+ export declare function getElementAttribute(_driver: Driver, element: Element, attr: string): Promise<string>;
41
+ export declare function performAction(_driver: Driver, _steps: any[]): Promise<void>;
39
42
  export {};
package/types/types.d.ts CHANGED
@@ -68,7 +68,7 @@ export type Features = {
68
68
  };
69
69
  export type DriverInfo = {
70
70
  sessionId?: string;
71
- remoteHostname?: string;
71
+ driverServerUrl?: string;
72
72
  userAgent?: UserAgent | null;
73
73
  capabilities?: Capabilities | null;
74
74
  viewport?: Partial<Viewport>;