@applitools/driver 1.15.3 → 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,21 @@
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
+
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)
13
+
14
+
15
+ ### Features
16
+
17
+ * add set of env variables to skip/ignore some optional automations ([#2097](https://github.com/applitools/eyes.sdk.javascript1/issues/2097)) ([bd3b08c](https://github.com/applitools/eyes.sdk.javascript1/commit/bd3b08c3d2997eb98d545b308a1f15501192178e))
18
+
3
19
  ## [1.15.3](https://github.com/applitools/eyes.sdk.javascript1/compare/js/driver@1.15.2...js/driver@1.15.3) (2023-12-12)
4
20
 
5
21
 
package/dist/driver.js CHANGED
@@ -85,12 +85,17 @@ class Driver {
85
85
  }
86
86
  async refresh({ reset } = {}) {
87
87
  if (reset) {
88
- this._driverInfo = undefined;
89
- this._environment = undefined;
90
- this._viewport = undefined;
91
- this._features = undefined;
92
- this._helper = undefined;
93
- this._state = {};
88
+ if (utils.general.getEnvValue('AVOID_DRIVER_STATE_REST', 'boolean')) {
89
+ this._logger.log(`Skipping reset of the driver state`);
90
+ }
91
+ else {
92
+ this._driverInfo = undefined;
93
+ this._environment = undefined;
94
+ this._viewport = undefined;
95
+ this._features = undefined;
96
+ this._helper = undefined;
97
+ this._state = {};
98
+ }
94
99
  }
95
100
  const spec = this._spec;
96
101
  let currentContext = this.currentContext.target;
@@ -277,8 +282,8 @@ class Driver {
277
282
  return this._environment;
278
283
  }
279
284
  async getViewport() {
280
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
281
- 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;
282
287
  if (!this._viewport) {
283
288
  const environment = await this.getEnvironment();
284
289
  const driverInfo = await this.getDriverInfo();
@@ -295,16 +300,15 @@ class Driver {
295
300
  const capabilitiesViewport = capabilities ? (0, capabilities_1.extractCapabilitiesViewport)(capabilities) : null;
296
301
  this._logger.log('Extracted capabilities viewport', capabilitiesViewport);
297
302
  this._viewport = { ...capabilitiesViewport, ...this._viewport };
298
- (_a = (_y = this._viewport).pixelRatio) !== null && _a !== void 0 ? _a : (_y.pixelRatio = 1);
299
303
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
300
304
  let windowSize = await this._spec.getWindowSize(this.target);
301
- (_b = (_z = this._viewport).displaySize) !== null && _b !== void 0 ? _b : (_z.displaySize = windowSize);
302
- 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')) &&
303
307
  this._viewport.displaySize.height > this._viewport.displaySize.width) {
304
308
  this._viewport.displaySize = utils.geometry.rotate(this._viewport.displaySize, 90);
305
309
  }
306
310
  if (environment.isAndroid) {
307
- // bar sizes could be extracted only on android
311
+ (_c = (_2 = this._viewport).pixelRatio) !== null && _c !== void 0 ? _c : (_2.pixelRatio = 1);
308
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 : {};
309
313
  if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
310
314
  this._logger.log('Driver status bar', statusBar);
@@ -331,20 +335,26 @@ class Driver {
331
335
  }
332
336
  }
333
337
  // bar sizes have to be scaled on android
334
- (_0 = this._viewport).statusBarSize && (_0.statusBarSize = this._viewport.statusBarSize / this._viewport.pixelRatio);
335
- (_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);
336
340
  windowSize = utils.geometry.scale(windowSize, 1 / this._viewport.pixelRatio);
337
- (_2 = this._viewport).displaySize && (_2.displaySize = utils.geometry.scale(this._viewport.displaySize, 1 / this._viewport.pixelRatio));
338
- (_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);
339
343
  }
340
344
  else if (environment.isIOS) {
341
- 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'))
342
351
  this._viewport.statusBarSize = 0;
343
352
  }
344
- (_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);
345
355
  // calculate viewport location
346
- (_p = (_5 = this._viewport).viewportLocation) !== null && _p !== void 0 ? _p : (_5.viewportLocation = {
347
- 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,
348
358
  y: this._viewport.statusBarSize,
349
359
  });
350
360
  // calculate viewport size
@@ -352,7 +362,7 @@ class Driver {
352
362
  this._viewport.viewportSize = { ...this._viewport.displaySize };
353
363
  this._viewport.viewportSize.height -= this._viewport.statusBarSize;
354
364
  if (environment.isAndroid) {
355
- 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'] -=
356
366
  this._viewport.navigationBarSize;
357
367
  }
358
368
  }
@@ -382,13 +392,13 @@ class Driver {
382
392
  }
383
393
  if (environment.isWeb) {
384
394
  const browserViewport = await this.execute(snippets.getViewport);
385
- (_s = (_6 = this._viewport).viewportSize) !== null && _s !== void 0 ? _s : (_6.viewportSize = browserViewport.viewportSize);
386
- (_t = (_7 = this._viewport).pixelRatio) !== null && _t !== void 0 ? _t : (_7.pixelRatio = browserViewport.pixelRatio);
387
- (_u = (_8 = this._viewport).viewportScale) !== null && _u !== void 0 ? _u : (_8.viewportScale = browserViewport.viewportScale);
388
- (_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);
389
399
  }
390
- (_w = (_10 = this._viewport).pixelRatio) !== null && _w !== void 0 ? _w : (_10.pixelRatio = 1);
391
- (_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);
392
402
  this._logger.log('Extracted viewport', this._viewport);
393
403
  }
394
404
  return this._viewport;
@@ -413,17 +423,23 @@ class Driver {
413
423
  async getDriverUrl() {
414
424
  var _a;
415
425
  const driverInfo = await this.getDriverInfo();
416
- return (_a = driverInfo.remoteHostname) !== null && _a !== void 0 ? _a : null;
426
+ return (_a = driverInfo.driverServerUrl) !== null && _a !== void 0 ? _a : null;
417
427
  }
418
428
  async getHelper() {
419
429
  var _a, _b, _c;
420
430
  if (this._helper === undefined) {
421
- const environment = await this.getEnvironment();
422
- this._logger.log(`Extracting helper for ${environment.isIOS ? 'ios' : 'android'}`);
423
- this._helper = environment.isIOS
424
- ? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this })
425
- : await helper_android_1.HelperAndroid.make({ spec: this._spec, driver: this });
426
- this._logger.log(`Extracted helper of type ${(_a = this._helper) === null || _a === void 0 ? void 0 : _a.name}`);
431
+ if (utils.general.getEnvValue('IGNORE_HELPER_LIB', 'boolean')) {
432
+ this._logger.log(`Skipping helper lib extraction`);
433
+ this._helper = null;
434
+ }
435
+ else {
436
+ const environment = await this.getEnvironment();
437
+ this._logger.log(`Extracting helper for ${environment.isIOS ? 'ios' : 'android'}`);
438
+ this._helper = environment.isIOS
439
+ ? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this })
440
+ : await helper_android_1.HelperAndroid.make({ spec: this._spec, driver: this });
441
+ this._logger.log(`Extracted helper of type ${(_a = this._helper) === null || _a === void 0 ? void 0 : _a.name}`);
442
+ }
427
443
  }
428
444
  this._logger.log(`Returning helper for of type ${(_c = (_b = this._helper) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : null}`);
429
445
  return this._helper;
@@ -744,24 +760,29 @@ class Driver {
744
760
  if (environment.isWeb)
745
761
  return (_a = this._viewport) === null || _a === void 0 ? void 0 : _a.orientation;
746
762
  if (environment.isAndroid) {
747
- this._logger.log('Extracting device orientation using adb command on android');
748
- const rotation = await this.execute('mobile:shell', {
749
- command: "dumpsys window | grep 'mCurrentRotation' | cut -d = -f2",
750
- })
751
- .then(rotation => { var _a; return (_a = rotation === null || rotation === void 0 ? void 0 : rotation.trim) === null || _a === void 0 ? void 0 : _a.call(rotation); })
752
- .catch(() => null);
753
- if (rotation) {
754
- let orientation = undefined;
755
- if (rotation === 'ROTATION_0' || rotation === '0')
756
- orientation = 'portrait';
757
- else if (rotation === 'ROTATION_90' || rotation === '3')
758
- orientation = 'landscape-secondary';
759
- else if (rotation === 'ROTATION_180' || rotation === '2')
760
- orientation = 'portrait-secondary';
761
- else if (rotation === 'ROTATION_270' || rotation === '1')
762
- orientation = 'landscape';
763
- this._logger.log('Extracted device orientation:', orientation);
764
- return orientation;
763
+ if (utils.general.getEnvValue('AVOID_ADB_USAGE', 'boolean')) {
764
+ this._logger.log(`Skipping device orientation extraction using adb command on android`);
765
+ }
766
+ else {
767
+ this._logger.log('Extracting device orientation using adb command on android');
768
+ const rotation = await this.execute('mobile:shell', {
769
+ command: "dumpsys window | grep 'mCurrentRotation' | cut -d = -f2",
770
+ })
771
+ .then(rotation => { var _a; return (_a = rotation === null || rotation === void 0 ? void 0 : rotation.trim) === null || _a === void 0 ? void 0 : _a.call(rotation); })
772
+ .catch(() => null);
773
+ if (rotation) {
774
+ let orientation = undefined;
775
+ if (rotation === 'ROTATION_0' || rotation === '0')
776
+ orientation = 'portrait';
777
+ else if (rotation === 'ROTATION_90' || rotation === '3')
778
+ orientation = 'landscape-secondary';
779
+ else if (rotation === 'ROTATION_180' || rotation === '2')
780
+ orientation = 'portrait-secondary';
781
+ else if (rotation === 'ROTATION_270' || rotation === '1')
782
+ orientation = 'landscape';
783
+ this._logger.log('Extracted device orientation:', orientation);
784
+ return orientation;
785
+ }
765
786
  }
766
787
  }
767
788
  this._logger.log('Extracting device orientation');
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.15.3",
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>;