@applitools/driver 1.16.0 → 1.16.2

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,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.16.2](https://github.com/applitools/eyes.sdk.javascript1/compare/js/driver@1.16.1...js/driver@1.16.2) (2024-01-30)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * losing root context after layout breakpoints reload ([#2113](https://github.com/applitools/eyes.sdk.javascript1/issues/2113)) ([afa1473](https://github.com/applitools/eyes.sdk.javascript1/commit/afa14735e5539ab0f79aa610e6ec1ea8989a5922))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * @applitools/snippets bumped to 2.4.25
14
+ #### Bug Fixes
15
+
16
+ * losing root context after layout breakpoints reload ([#2113](https://github.com/applitools/eyes.sdk.javascript1/issues/2113)) ([afa1473](https://github.com/applitools/eyes.sdk.javascript1/commit/afa14735e5539ab0f79aa610e6ec1ea8989a5922))
17
+
18
+ ## [1.16.1](https://github.com/applitools/eyes.sdk.javascript1/compare/js/driver@1.16.0...js/driver@1.16.1) (2023-12-19)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * 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))
24
+ * fixed extraction of the driver server url ([ddc6449](https://github.com/applitools/eyes.sdk.javascript1/commit/ddc6449fc72166ab26c99e9ba7bb83c05fd591d6))
25
+ * 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))
26
+
3
27
  ## [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
28
 
5
29
 
package/dist/driver.js CHANGED
@@ -77,7 +77,10 @@ class Driver {
77
77
  this._currentContext = context;
78
78
  }
79
79
  async reloadPage() {
80
- await this.mainContext.execute(snippets.reloadPage).catch(() => null);
80
+ if (this._spec.reload)
81
+ await this._spec.reload(this.target);
82
+ else
83
+ await this.mainContext.execute(snippets.reloadPage).catch(() => null);
81
84
  const refreshThis = await this.refresh({ reset: false });
82
85
  const scrollingElement = await this.mainContext.getScrollingElement();
83
86
  await (scrollingElement === null || scrollingElement === void 0 ? void 0 : scrollingElement.refresh());
@@ -282,8 +285,8 @@ class Driver {
282
285
  return this._environment;
283
286
  }
284
287
  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;
288
+ 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;
289
+ var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
287
290
  if (!this._viewport) {
288
291
  const environment = await this.getEnvironment();
289
292
  const driverInfo = await this.getDriverInfo();
@@ -300,16 +303,15 @@ class Driver {
300
303
  const capabilitiesViewport = capabilities ? (0, capabilities_1.extractCapabilitiesViewport)(capabilities) : null;
301
304
  this._logger.log('Extracted capabilities viewport', capabilitiesViewport);
302
305
  this._viewport = { ...capabilitiesViewport, ...this._viewport };
303
- (_a = (_y = this._viewport).pixelRatio) !== null && _a !== void 0 ? _a : (_y.pixelRatio = 1);
304
306
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
305
307
  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')) &&
308
+ (_a = (_1 = this._viewport).displaySize) !== null && _a !== void 0 ? _a : (_1.displaySize = windowSize);
309
+ if (((_b = this._viewport.orientation) === null || _b === void 0 ? void 0 : _b.startsWith('landscape')) &&
308
310
  this._viewport.displaySize.height > this._viewport.displaySize.width) {
309
311
  this._viewport.displaySize = utils.geometry.rotate(this._viewport.displaySize, 90);
310
312
  }
311
313
  if (environment.isAndroid) {
312
- // bar sizes could be extracted only on android
314
+ (_c = (_2 = this._viewport).pixelRatio) !== null && _c !== void 0 ? _c : (_2.pixelRatio = 1);
313
315
  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
316
  if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
315
317
  this._logger.log('Driver status bar', statusBar);
@@ -336,20 +338,26 @@ class Driver {
336
338
  }
337
339
  }
338
340
  // 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);
341
+ (_3 = this._viewport).statusBarSize && (_3.statusBarSize = this._viewport.statusBarSize / this._viewport.pixelRatio);
342
+ (_4 = this._viewport).navigationBarSize && (_4.navigationBarSize = this._viewport.navigationBarSize / this._viewport.pixelRatio);
341
343
  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);
344
+ (_5 = this._viewport).displaySize && (_5.displaySize = utils.geometry.scale(this._viewport.displaySize, 1 / this._viewport.pixelRatio));
345
+ (_l = (_6 = this._viewport).navigationBarSize) !== null && _l !== void 0 ? _l : (_6.navigationBarSize = 0);
344
346
  }
345
347
  else if (environment.isIOS) {
346
- if ((_m = this._viewport.orientation) === null || _m === void 0 ? void 0 : _m.startsWith('landscape'))
348
+ if (!this._viewport.pixelRatio || !this._viewport.statusBarSize) {
349
+ const screen = await this.execute('mobile:deviceScreenInfo');
350
+ this._viewport.pixelRatio = (_m = screen.scale) !== null && _m !== void 0 ? _m : 0;
351
+ this._viewport.statusBarSize = (_o = screen.statusBarSize) === null || _o === void 0 ? void 0 : _o.height;
352
+ }
353
+ if ((_p = this._viewport.orientation) === null || _p === void 0 ? void 0 : _p.startsWith('landscape'))
347
354
  this._viewport.statusBarSize = 0;
348
355
  }
349
- (_o = (_4 = this._viewport).statusBarSize) !== null && _o !== void 0 ? _o : (_4.statusBarSize = 0);
356
+ (_q = (_7 = this._viewport).pixelRatio) !== null && _q !== void 0 ? _q : (_7.pixelRatio = 1);
357
+ (_r = (_8 = this._viewport).statusBarSize) !== null && _r !== void 0 ? _r : (_8.statusBarSize = 0);
350
358
  // 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,
359
+ (_s = (_9 = this._viewport).viewportLocation) !== null && _s !== void 0 ? _s : (_9.viewportLocation = {
360
+ x: this._viewport.orientation === 'landscape' ? (_t = this._viewport.navigationBarSize) !== null && _t !== void 0 ? _t : 0 : 0,
353
361
  y: this._viewport.statusBarSize,
354
362
  });
355
363
  // calculate viewport size
@@ -357,7 +365,7 @@ class Driver {
357
365
  this._viewport.viewportSize = { ...this._viewport.displaySize };
358
366
  this._viewport.viewportSize.height -= this._viewport.statusBarSize;
359
367
  if (environment.isAndroid) {
360
- this._viewport.viewportSize[((_r = this._viewport.orientation) === null || _r === void 0 ? void 0 : _r.startsWith('landscape')) ? 'width' : 'height'] -=
368
+ this._viewport.viewportSize[((_u = this._viewport.orientation) === null || _u === void 0 ? void 0 : _u.startsWith('landscape')) ? 'width' : 'height'] -=
361
369
  this._viewport.navigationBarSize;
362
370
  }
363
371
  }
@@ -387,13 +395,13 @@ class Driver {
387
395
  }
388
396
  if (environment.isWeb) {
389
397
  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);
398
+ (_v = (_10 = this._viewport).viewportSize) !== null && _v !== void 0 ? _v : (_10.viewportSize = browserViewport.viewportSize);
399
+ (_w = (_11 = this._viewport).pixelRatio) !== null && _w !== void 0 ? _w : (_11.pixelRatio = browserViewport.pixelRatio);
400
+ (_x = (_12 = this._viewport).viewportScale) !== null && _x !== void 0 ? _x : (_12.viewportScale = browserViewport.viewportScale);
401
+ (_y = (_13 = this._viewport).orientation) !== null && _y !== void 0 ? _y : (_13.orientation = browserViewport.orientation);
394
402
  }
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);
403
+ (_z = (_14 = this._viewport).pixelRatio) !== null && _z !== void 0 ? _z : (_14.pixelRatio = 1);
404
+ (_0 = (_15 = this._viewport).viewportScale) !== null && _0 !== void 0 ? _0 : (_15.viewportScale = 1);
397
405
  this._logger.log('Extracted viewport', this._viewport);
398
406
  }
399
407
  return this._viewport;
@@ -418,7 +426,7 @@ class Driver {
418
426
  async getDriverUrl() {
419
427
  var _a;
420
428
  const driverInfo = await this.getDriverInfo();
421
- return (_a = driverInfo.remoteHostname) !== null && _a !== void 0 ? _a : null;
429
+ return (_a = driverInfo.driverServerUrl) !== null && _a !== void 0 ? _a : null;
422
430
  }
423
431
  async getHelper() {
424
432
  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.2",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@applitools/logger": "2.0.14",
77
- "@applitools/snippets": "2.4.24",
77
+ "@applitools/snippets": "2.4.25",
78
78
  "@applitools/utils": "1.7.0",
79
79
  "semver": "7.5.4"
80
80
  },
@@ -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 {};
@@ -127,6 +127,7 @@ export interface SpecDriver<T extends SpecType> {
127
127
  getCurrentWorld?(driver: T['driver']): Promise<string>;
128
128
  getWorlds?(driver: T['driver']): Promise<string[]>;
129
129
  switchWorld?(driver: T['driver'], id: string): Promise<void>;
130
+ reload?(driver: T['driver']): Promise<void>;
130
131
  }
131
132
  export type WaitOptions = {
132
133
  state?: 'exist' | 'visible';
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>;