@applitools/driver 1.9.8 → 1.9.11

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/dist/driver.js CHANGED
@@ -144,8 +144,8 @@ 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, _x;
148
- var _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
147
+ 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;
148
+ var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
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;
@@ -156,29 +156,29 @@ class Driver {
156
156
  (_e = (await this.getOrientation().catch(() => undefined))) !== null && _e !== void 0 ? _e : this._driverInfo.orientation;
157
157
  }
158
158
  if (this.isWeb) {
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));
159
+ (_f = (_1 = this._driverInfo).pixelRatio) !== null && _f !== void 0 ? _f : (_1.pixelRatio = await this.execute(snippets.getPixelRatio));
160
+ (_g = (_2 = this._driverInfo).viewportScale) !== null && _g !== void 0 ? _g : (_2.viewportScale = await this.execute(snippets.getViewportScale));
161
+ (_h = (_3 = this._driverInfo).userAgent) !== null && _h !== void 0 ? _h : (_3.userAgent = await this.execute(snippets.getUserAgent));
162
162
  if (this._driverInfo.userAgent) {
163
163
  const userAgentInfo = (0, user_agent_1.parseUserAgent)(this._driverInfo.userAgent);
164
164
  this._driverInfo.browserName = (_j = userAgentInfo.browserName) !== null && _j !== void 0 ? _j : this._driverInfo.browserName;
165
165
  this._driverInfo.browserVersion = (_k = userAgentInfo.browserVersion) !== null && _k !== void 0 ? _k : this._driverInfo.browserVersion;
166
166
  if (this._driverInfo.isMobile) {
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);
167
+ (_l = (_4 = this._driverInfo).platformName) !== null && _l !== void 0 ? _l : (_4.platformName = userAgentInfo.platformName);
168
+ (_m = (_5 = this._driverInfo).platformVersion) !== null && _m !== void 0 ? _m : (_5.platformVersion = userAgentInfo.platformVersion);
169
169
  }
170
170
  else {
171
171
  this._driverInfo.platformName = (_o = userAgentInfo.platformName) !== null && _o !== void 0 ? _o : this._driverInfo.platformName;
172
172
  this._driverInfo.platformVersion = (_p = userAgentInfo.platformVersion) !== null && _p !== void 0 ? _p : this._driverInfo.platformVersion;
173
173
  }
174
174
  }
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);
175
+ (_q = (_6 = this._driverInfo).features) !== null && _q !== void 0 ? _q : (_6.features = {});
176
+ (_r = (_7 = this._driverInfo.features).allCookies) !== null && _r !== void 0 ? _r : (_7.allCookies = /chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile);
177
177
  }
178
178
  else {
179
179
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
180
180
  let windowSize = await this._spec.getWindowSize(this.target);
181
- (_s = (_5 = this._driverInfo).displaySize) !== null && _s !== void 0 ? _s : (_5.displaySize = windowSize);
181
+ (_s = (_8 = this._driverInfo).displaySize) !== null && _s !== void 0 ? _s : (_8.displaySize = windowSize);
182
182
  if (this.isAndroid) {
183
183
  // bar sizes could be extracted only on android
184
184
  const systemBars = await ((_u = (_t = this._spec).getSystemBars) === null || _u === void 0 ? void 0 : _u.call(_t, this.target).catch(() => null));
@@ -197,47 +197,39 @@ class Driver {
197
197
  if (navigationBar.x > 0)
198
198
  this._driverInfo.orientation = 'landscape-secondary';
199
199
  // navigation bar size could be its height or width depending on screen orientation
200
- const navigationBarSize = navigationBar[this.orientation.startsWith('landscape') ? 'width' : 'height'];
200
+ const navigationBarSize = navigationBar[((_w = this.orientation) === null || _w === void 0 ? void 0 : _w.startsWith('landscape')) ? 'width' : 'height'];
201
201
  // when navigation bar is invisible on android it returns navigation bar size equal to display size
202
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);
203
+ this._driverInfo.displaySize[((_x = this.orientation) === null || _x === void 0 ? void 0 : _x.startsWith('landscape')) ? 'width' : 'height']) {
204
+ this._driverInfo.navigationBarSize = Math.max((_y = this._driverInfo.navigationBarSize) !== null && _y !== void 0 ? _y : 0, navigationBarSize);
205
205
  }
206
206
  else {
207
207
  this._driverInfo.navigationBarSize = 0;
208
208
  }
209
209
  }
210
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);
211
+ (_9 = this._driverInfo).statusBarSize && (_9.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio);
212
+ (_10 = this._driverInfo).navigationBarSize && (_10.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio);
213
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));
214
+ (_11 = this._driverInfo).displaySize && (_11.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
215
215
  }
216
216
  // calculate viewport location
217
- (_x = (_9 = this._driverInfo).viewportLocation) !== null && _x !== void 0 ? _x : (_9.viewportLocation = {
217
+ (_z = (_12 = this._driverInfo).viewportLocation) !== null && _z !== void 0 ? _z : (_12.viewportLocation = {
218
218
  x: this.orientation === 'landscape' ? this.navigationBarSize : 0,
219
219
  y: this.statusBarSize,
220
220
  });
221
221
  // calculate viewport size
222
222
  if (!this._driverInfo.viewportSize) {
223
- if (this.navigationBarSize > 1) {
224
- if (this.orientation.startsWith('landscape')) {
225
- this._driverInfo.viewportSize = {
226
- width: this._driverInfo.displaySize.height - this.navigationBarSize,
227
- height: this._driverInfo.displaySize.width - this.statusBarSize,
228
- };
229
- }
230
- else {
231
- this._driverInfo.viewportSize = {
232
- width: this._driverInfo.displaySize.width,
233
- height: this._driverInfo.displaySize.height - this.statusBarSize - this.navigationBarSize,
234
- };
235
- }
223
+ if ((_0 = this.orientation) === null || _0 === void 0 ? void 0 : _0.startsWith('landscape')) {
224
+ this._driverInfo.viewportSize = {
225
+ width: this._driverInfo.displaySize.height - this.navigationBarSize,
226
+ height: this._driverInfo.displaySize.width - this.statusBarSize,
227
+ };
236
228
  }
237
229
  else {
238
230
  this._driverInfo.viewportSize = {
239
- width: windowSize.width,
240
- height: windowSize.height - this.statusBarSize,
231
+ width: this._driverInfo.displaySize.width,
232
+ height: this._driverInfo.displaySize.height - this.statusBarSize - this.navigationBarSize,
241
233
  };
242
234
  }
243
235
  }
@@ -540,7 +532,7 @@ class Driver {
540
532
  throw new Error('Failed to set viewport size!');
541
533
  }
542
534
  async getDisplaySize() {
543
- var _a;
535
+ var _a, _b;
544
536
  if (this.isWeb && !this.isMobile)
545
537
  return;
546
538
  if ((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.displaySize) {
@@ -548,7 +540,7 @@ class Driver {
548
540
  return this._driverInfo.displaySize;
549
541
  }
550
542
  let size = await this._spec.getWindowSize(this.target);
551
- if ((await this.getOrientation()).startsWith('landscape') && size.height > size.width) {
543
+ if (((_b = (await this.getOrientation())) === null || _b === void 0 ? void 0 : _b.startsWith('landscape')) && size.height > size.width) {
552
544
  size = { width: size.height, height: size.width };
553
545
  }
554
546
  const normalizedSize = this.isAndroid ? utils.geometry.scale(size, 1 / this.pixelRatio) : size;
@@ -28,7 +28,8 @@ const utils = __importStar(require("@applitools/utils"));
28
28
  class HelperAndroid {
29
29
  constructor(options) {
30
30
  this._spec = options.spec;
31
- this._element = options.element;
31
+ this._input = options.input;
32
+ this._action = options.action;
32
33
  this._legacy = options.legacy;
33
34
  this._logger = options.logger;
34
35
  this.name = this._legacy ? 'android-legacy' : 'android';
@@ -36,18 +37,17 @@ class HelperAndroid {
36
37
  static async make(options) {
37
38
  const { spec, driver, logger } = options;
38
39
  let legacy = false;
39
- let element = await driver.element({
40
- type: 'xpath',
41
- selector: '//*[@content-desc="EyesAppiumHelperEDT"]',
42
- });
43
- if (!element) {
40
+ let input = await driver.element({ type: 'xpath', selector: '//*[@content-desc="EyesAppiumHelperEDT"]' });
41
+ if (!input) {
44
42
  legacy = true;
45
- element = await driver.element({
46
- type: '-android uiautomator',
47
- selector: 'new UiSelector().description("EyesAppiumHelper")',
48
- });
43
+ input = await driver.element({ type: 'xpath', selector: '//*[@content-desc="EyesAppiumHelper"]' });
49
44
  }
50
- return element ? new HelperAndroid({ spec, element, legacy, logger }) : null;
45
+ const action = !legacy
46
+ ? await driver.element({ type: 'xpath', selector: '//*[@content-desc="EyesAppiumHelper_Action"]' })
47
+ : null;
48
+ return input
49
+ ? new HelperAndroid({ spec, input, action, legacy, logger })
50
+ : null;
51
51
  }
52
52
  async _getElementId(element) {
53
53
  const resourceId = await element.getAttribute('resource-id');
@@ -56,21 +56,25 @@ class HelperAndroid {
56
56
  return resourceId.split('/')[1];
57
57
  }
58
58
  async getContentSize(element) {
59
+ console.log('getContentSize', !!this._action);
59
60
  let contentHeightString;
60
61
  if (this._legacy) {
61
- await this._element.click();
62
- contentHeightString = await this._element.getText();
62
+ await this._input.click();
63
+ contentHeightString = await this._input.getText();
63
64
  }
64
65
  else {
65
66
  const elementId = await this._getElementId(element);
66
67
  if (!elementId)
67
68
  return null;
68
- await this._element.type(`offset;${elementId};0;0;0`);
69
- await this._element.click();
70
- contentHeightString = await this._element.getText();
71
- await this._element.type('');
69
+ await this._input.type(`offset;${elementId};0;0;0`);
70
+ if (this._action)
71
+ await this._action.type('1');
72
+ else
73
+ await this._input.click();
74
+ contentHeightString = await this._input.getText();
75
+ await this._input.type('');
72
76
  }
73
- const region = await this._spec.getElementRegion(this._element.driver.target, element.target);
77
+ const region = await this._spec.getElementRegion(this._input.driver.target, element.target);
74
78
  const contentHeight = Number(contentHeightString);
75
79
  if (Number.isNaN(contentHeight))
76
80
  return utils.geometry.size(region);
@@ -82,10 +86,13 @@ class HelperAndroid {
82
86
  const elementId = await this._getElementId(element);
83
87
  if (!elementId)
84
88
  return null;
85
- await this._element.type(`getRect;${elementId};0;0`);
86
- await this._element.click();
87
- const regionString = await this._element.getText();
88
- await this._element.type('');
89
+ await this._input.type(`getRect;${elementId};0;0`);
90
+ if (this._action)
91
+ await this._action.type('1');
92
+ else
93
+ await this._input.click();
94
+ const regionString = await this._input.getText();
95
+ await this._input.type('');
89
96
  const [, x, y, height, width] = regionString.match(/\[(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?)\]/);
90
97
  const region = { x: Number(x), y: Number(y), width: Number(width), height: Number(height) };
91
98
  if (Number.isNaN(region.x + region.y + region.width + region.height))
@@ -98,9 +105,12 @@ class HelperAndroid {
98
105
  const elementId = await this._getElementId(element);
99
106
  if (!elementId)
100
107
  return null;
101
- await this._element.type(`moveToTop;${elementId};0;-1`);
102
- await this._element.click();
103
- await this._element.type('');
108
+ await this._input.type(`moveToTop;${elementId};0;-1`);
109
+ if (this._action)
110
+ await this._action.type('1');
111
+ else
112
+ await this._input.click();
113
+ await this._input.type('');
104
114
  }
105
115
  async scrollBy(element, offset) {
106
116
  if (this._legacy)
@@ -108,17 +118,23 @@ class HelperAndroid {
108
118
  const elementId = await this._getElementId(element);
109
119
  if (!elementId)
110
120
  return null;
111
- await this._element.type(`scroll;${elementId};${offset.y};0;0`);
112
- await this._element.click();
113
- await this._element.type('');
121
+ await this._input.type(`scroll;${elementId};${offset.y};0;0`);
122
+ if (this._action)
123
+ await this._action.type('1');
124
+ else
125
+ await this._input.click();
126
+ await this._input.type('');
114
127
  }
115
128
  async getTouchPadding() {
116
129
  if (this._legacy)
117
130
  return null;
118
- await this._element.type(`getTouchPadding;0;0;0;0`);
119
- await this._element.click();
120
- const touchPaddingString = await this._element.getText();
121
- await this._element.type('');
131
+ await this._input.type(`getTouchPadding;0;0;0;0`);
132
+ if (this._action)
133
+ await this._action.type('1');
134
+ else
135
+ await this._input.click();
136
+ const touchPaddingString = await this._input.getText();
137
+ await this._input.type('');
122
138
  const touchPadding = Number(touchPaddingString);
123
139
  if (Number.isNaN(touchPadding))
124
140
  return null;
@@ -40,10 +40,12 @@ function transformSelector(spec, selector, environment) {
40
40
  if ((environment === null || environment === void 0 ? void 0 : environment.isWeb) && isCommonSelector(spec, selector)) {
41
41
  if (selector.type === 'id')
42
42
  selector = { type: 'css', selector: `#${selector.selector}` };
43
- if (selector.type === 'name')
43
+ else if (selector.type === 'name')
44
44
  selector = { type: 'css', selector: `[name="${selector.selector}"]` };
45
- if (selector.type === 'class name')
45
+ else if (selector.type === 'class name')
46
46
  selector = { type: 'css', selector: `.${selector.selector}` };
47
+ else if (selector.type === 'tag name')
48
+ selector = { type: 'css', selector: `${selector.selector}` };
47
49
  }
48
50
  return (_b = (_a = spec.transformSelector) === null || _a === void 0 ? void 0 : _a.call(spec, selector)) !== null && _b !== void 0 ? _b : selector;
49
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.9.8",
3
+ "version": "1.9.11",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -17,7 +17,7 @@
17
17
  "repository": {
18
18
  "type": "git",
19
19
  "url": "git://github.com/applitools/eyes.sdk.javascript1.git",
20
- "directory": "packages/driver"
20
+ "directory": "js/packages/driver"
21
21
  },
22
22
  "license": "SEE LICENSE IN LICENSE",
23
23
  "author": {
@@ -64,7 +64,9 @@
64
64
  "scripts": {
65
65
  "lint": "eslint '**/*.ts'",
66
66
  "build": "tsc",
67
- "test": "mocha --no-timeouts -r ts-node/register ./test/**/*.spec.ts",
67
+ "test": "yarn test:unit",
68
+ "test:sanity": "yarn test:unit",
69
+ "test:unit": "mocha --no-timeouts -r ts-node/register ./test/unit/*.spec.ts",
68
70
  "deps": "bongo deps",
69
71
  "preversion": "bongo preversion",
70
72
  "version": "bongo version",
@@ -76,13 +78,13 @@
76
78
  }
77
79
  },
78
80
  "dependencies": {
79
- "@applitools/logger": "1.1.13",
81
+ "@applitools/logger": "1.1.14",
80
82
  "@applitools/snippets": "2.4.3",
81
- "@applitools/types": "1.5.5",
82
- "@applitools/utils": "1.3.9"
83
+ "@applitools/types": "1.5.6",
84
+ "@applitools/utils": "1.3.10"
83
85
  },
84
86
  "devDependencies": {
85
- "@applitools/bongo": "^2.1.5",
87
+ "@applitools/bongo": "^2.1.6",
86
88
  "@types/mocha": "^9.1.1",
87
89
  "@types/node": "^17.0.31",
88
90
  "@typescript-eslint/eslint-plugin": "^5.22.0",
@@ -9,13 +9,15 @@ export declare class HelperAndroid<TDriver, TContext, TElement, TSelector> {
9
9
  logger: Logger;
10
10
  }): Promise<HelperAndroid<TDriver, TContext, TElement, TSelector> | null>;
11
11
  private readonly _spec;
12
- private readonly _element;
12
+ private readonly _input;
13
+ private readonly _action?;
13
14
  private readonly _legacy;
14
15
  private _logger;
15
16
  readonly name: 'android' | 'android-legacy';
16
17
  constructor(options: {
17
18
  spec: types.SpecDriver<TDriver, TContext, TElement, TSelector>;
18
- element: Element<TDriver, TContext, TElement, TSelector>;
19
+ input: Element<TDriver, TContext, TElement, TSelector>;
20
+ action?: Element<TDriver, TContext, TElement, TSelector>;
19
21
  legacy: boolean;
20
22
  logger?: any;
21
23
  });