@applitools/driver 1.9.16 → 1.9.19

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/element.js CHANGED
@@ -50,7 +50,10 @@ class Element {
50
50
  else {
51
51
  throw new TypeError('Element constructor called with argument of unknown type!');
52
52
  }
53
- if (this._selector && this._spec.untransformSelector) {
53
+ if (specUtils.isSimpleCommonSelector(this._selector)) {
54
+ this._commonSelector = this._selector;
55
+ }
56
+ else if (this._selector && this._spec.untransformSelector) {
54
57
  this._commonSelector = this._spec.untransformSelector(this._spec.transformSelector(this._selector));
55
58
  }
56
59
  }
@@ -90,8 +93,8 @@ class Element {
90
93
  }
91
94
  async contains(innerElement) {
92
95
  const contains = await this.withRefresh(async () => {
93
- var _a, _b, _c, _d;
94
- var _e;
96
+ var _a, _b, _c, _d, _e;
97
+ var _f;
95
98
  innerElement = innerElement instanceof Element ? innerElement.target : innerElement;
96
99
  if (this.driver.isWeb) {
97
100
  this._logger.log('Checking if web element with selector', this.selector, 'contains element', innerElement);
@@ -105,25 +108,34 @@ class Element {
105
108
  if (await this.equals(innerElement))
106
109
  return false;
107
110
  // if the inner element region is contained in this element region, then it then could be assumed that the inner element is contained in this element
108
- const contentRegion = (_c = (await ((_b = this.driver.helper) === null || _b === void 0 ? void 0 : _b.getContentRegion(this)))) !== null && _c !== void 0 ? _c : (await this.getAttribute('contentSize')
109
- .then(data => {
110
- const contentSize = JSON.parse(data);
111
- return {
112
- x: contentSize.left,
113
- y: contentSize.top,
114
- width: contentSize.width,
115
- height: this.driver.isIOS
116
- ? Math.max(contentSize.height, contentSize.scrollableOffset)
117
- : contentSize.height + contentSize.scrollableOffset,
111
+ let contentRegion = await ((_b = this.driver.helper) === null || _b === void 0 ? void 0 : _b.getContentRegion(this));
112
+ if (!contentRegion || !this.driver.isAndroid) {
113
+ const nativeContentRegion = await this.getAttribute('contentSize')
114
+ .then(data => {
115
+ const contentSize = JSON.parse(data);
116
+ return {
117
+ x: contentSize.left,
118
+ y: contentSize.top,
119
+ width: contentSize.width,
120
+ height: this.driver.isIOS
121
+ ? Math.max(contentSize.height, contentSize.scrollableOffset)
122
+ : contentSize.height + contentSize.scrollableOffset,
123
+ };
124
+ })
125
+ .catch(err => {
126
+ this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
127
+ return this._spec.getElementRegion(this.driver.target, this.target);
128
+ });
129
+ contentRegion = {
130
+ x: nativeContentRegion.x,
131
+ y: nativeContentRegion.y,
132
+ width: Math.max((_c = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.width) !== null && _c !== void 0 ? _c : 0, nativeContentRegion.width),
133
+ height: Math.max((_d = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.height) !== null && _d !== void 0 ? _d : 0, nativeContentRegion.height),
118
134
  };
119
- })
120
- .catch(err => {
121
- this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
122
- return this._spec.getElementRegion(this.driver.target, this.target);
123
- }));
135
+ }
124
136
  const innerRegion = await this._spec.getElementRegion(this.driver.target, innerElement);
125
137
  const contains = utils.geometry.contains(contentRegion, innerRegion);
126
- (_d = (_e = this._state).containedElements) !== null && _d !== void 0 ? _d : (_e.containedElements = new Map());
138
+ (_e = (_f = this._state).containedElements) !== null && _e !== void 0 ? _e : (_f.containedElements = new Map());
127
139
  this._state.containedElements.set(innerElement, contains);
128
140
  return contains;
129
141
  }
@@ -182,7 +194,7 @@ class Element {
182
194
  if (this._state.contentSize)
183
195
  return this._state.contentSize;
184
196
  const size = await this.withRefresh(async () => {
185
- var _a, _b;
197
+ var _a, _b, _c;
186
198
  if (this.driver.isWeb) {
187
199
  this._logger.log('Extracting content size of web element with selector', this.selector);
188
200
  return this.context.execute(snippets.getElementContentSize, [this]);
@@ -190,23 +202,34 @@ class Element {
190
202
  else {
191
203
  this._logger.log('Extracting content size of native element with selector', this.selector);
192
204
  try {
193
- const contentRegion = (_b = (await ((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.getContentRegion(this)))) !== null && _b !== void 0 ? _b : (await this.getAttribute('contentSize')
194
- .then(data => {
195
- const contentSize = JSON.parse(data);
196
- return {
197
- x: contentSize.left,
198
- y: contentSize.top,
199
- width: contentSize.width,
200
- height: this.driver.isIOS
201
- ? Math.max(contentSize.height, contentSize.scrollableOffset)
202
- : contentSize.height + contentSize.scrollableOffset,
205
+ let contentRegion = await ((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.getContentRegion(this));
206
+ this._logger.log('Extracted native content region using helper library', contentRegion);
207
+ // on android extraction of this argument will perform non-deterministic touch action, so it is better to avoid it
208
+ if (!contentRegion || !this.driver.isAndroid) {
209
+ const attrContentRegion = await this.getAttribute('contentSize')
210
+ .then(data => {
211
+ const contentSize = JSON.parse(data);
212
+ return {
213
+ x: contentSize.left,
214
+ y: contentSize.top,
215
+ width: contentSize.width,
216
+ height: this.driver.isIOS
217
+ ? Math.max(contentSize.height, contentSize.scrollableOffset)
218
+ : contentSize.height + contentSize.scrollableOffset,
219
+ };
220
+ })
221
+ .catch(err => {
222
+ this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
223
+ return this._spec.getElementRegion(this.driver.target, this.target);
224
+ });
225
+ this._logger.log('Extracted native content region using attribute', attrContentRegion);
226
+ contentRegion = {
227
+ x: attrContentRegion.x,
228
+ y: attrContentRegion.y,
229
+ width: Math.max((_b = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.width) !== null && _b !== void 0 ? _b : 0, attrContentRegion.width),
230
+ height: Math.max((_c = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.height) !== null && _c !== void 0 ? _c : 0, attrContentRegion.height),
203
231
  };
204
- })
205
- .catch(err => {
206
- this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
207
- return this._spec.getElementRegion(this.driver.target, this.target);
208
- }));
209
- this._logger.log('Extracted native content region', contentRegion);
232
+ }
210
233
  this._state.contentSize = utils.geometry.size(contentRegion);
211
234
  if (this.driver.isAndroid) {
212
235
  this._state.contentSize = utils.geometry.scale(this._state.contentSize, 1 / this.driver.pixelRatio);
@@ -277,6 +300,7 @@ class Element {
277
300
  }
278
301
  async getTouchPadding() {
279
302
  var _a, _b;
303
+ var _c;
280
304
  if (this._state.touchPadding == null) {
281
305
  if (this.driver.isWeb)
282
306
  this._state.touchPadding = 0;
@@ -284,16 +308,18 @@ class Element {
284
308
  this._state.touchPadding = 10;
285
309
  else if (this.driver.isAndroid) {
286
310
  if (((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.name) === 'android') {
287
- this._state.touchPadding = (await ((_b = this.driver.helper) === null || _b === void 0 ? void 0 : _b.getTouchPadding())) || 20;
311
+ this._state.touchPadding = await this.driver.helper.getTouchPadding();
312
+ this._logger.log('Touch padding extracted using helper library', this._state.touchPadding);
288
313
  }
289
- else {
290
- const touchPadding = await this.getAttribute('contentSize')
314
+ if (!this._state.touchPadding) {
315
+ this._state.touchPadding = await this.getAttribute('contentSize')
291
316
  .then(data => JSON.parse(data).touchPadding)
292
317
  .catch(err => {
293
318
  this._logger.warn(`Unable to get the attribute 'contentSize' when looking up 'touchPadding' due to the following error: '${err.message}'`);
294
319
  });
295
- this._state.touchPadding = touchPadding || 20;
320
+ this._logger.log('Touch padding extracted using attribute', this._state.touchPadding);
296
321
  }
322
+ (_b = (_c = this._state).touchPadding) !== null && _b !== void 0 ? _b : (_c.touchPadding = 20);
297
323
  this._logger.log('Touch padding set:', this._state.touchPadding);
298
324
  }
299
325
  }
@@ -31,6 +31,17 @@ class HelperAndroid {
31
31
  return null;
32
32
  return resourceId.split('/')[1];
33
33
  }
34
+ async _command(command) {
35
+ await this._input.type(command);
36
+ await this._input.click();
37
+ let text = await this._input.getText();
38
+ if (this._action && text === command) {
39
+ await this._action.type('1').catch(() => null);
40
+ text = await this._input.getText();
41
+ }
42
+ await this._input.type('');
43
+ return text;
44
+ }
34
45
  async getContentRegion(element) {
35
46
  let contentHeightString;
36
47
  if (this._legacy) {
@@ -41,13 +52,7 @@ class HelperAndroid {
41
52
  const elementId = await this._getElementId(element);
42
53
  if (!elementId)
43
54
  return null;
44
- await this._input.type(`offset;${elementId};0;0;0`);
45
- if (this._action)
46
- await this._action.type('1');
47
- else
48
- await this._input.click();
49
- contentHeightString = await this._input.getText();
50
- await this._input.type('');
55
+ contentHeightString = await this._command(`offset;${elementId};0;0;0`);
51
56
  }
52
57
  const region = await this._spec.getElementRegion(this._input.driver.target, element.target);
53
58
  const contentHeight = Number(contentHeightString);
@@ -55,19 +60,24 @@ class HelperAndroid {
55
60
  ? { x: region.x, y: region.y, width: region.width, height: contentHeight }
56
61
  : null;
57
62
  }
63
+ async getTouchPadding() {
64
+ if (this._legacy)
65
+ return null;
66
+ const touchPaddingString = await this._command(`getTouchPadding;0;0;0;0`);
67
+ const touchPadding = Number(touchPaddingString);
68
+ if (!touchPadding || Number.isNaN(touchPadding))
69
+ return null;
70
+ return touchPadding;
71
+ }
58
72
  async getRegion(element) {
59
73
  if (this._legacy)
60
74
  return null;
61
75
  const elementId = await this._getElementId(element);
62
76
  if (!elementId)
63
77
  return null;
64
- await this._input.type(`getRect;${elementId};0;0`);
65
- if (this._action)
66
- await this._action.type('1');
67
- else
68
- await this._input.click();
69
- const regionString = await this._input.getText();
70
- await this._input.type('');
78
+ const regionString = await this._command(`getRect;${elementId};0;0`);
79
+ if (!regionString)
80
+ return null;
71
81
  const [, x, y, height, width] = regionString.match(/\[(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?);(-?\d+(?:\.\d+)?)\]/);
72
82
  const region = { x: Number(x), y: Number(y), width: Number(width), height: Number(height) };
73
83
  if (Number.isNaN(region.x + region.y + region.width + region.height))
@@ -80,12 +90,7 @@ class HelperAndroid {
80
90
  const elementId = await this._getElementId(element);
81
91
  if (!elementId)
82
92
  return null;
83
- await this._input.type(`moveToTop;${elementId};0;-1`);
84
- if (this._action)
85
- await this._action.type('1');
86
- else
87
- await this._input.click();
88
- await this._input.type('');
93
+ await this._command(`moveToTop;${elementId};0;-1`);
89
94
  }
90
95
  async scrollBy(element, offset) {
91
96
  if (this._legacy)
@@ -93,27 +98,7 @@ class HelperAndroid {
93
98
  const elementId = await this._getElementId(element);
94
99
  if (!elementId)
95
100
  return null;
96
- await this._input.type(`scroll;${elementId};${offset.y};0;0`);
97
- if (this._action)
98
- await this._action.type('1');
99
- else
100
- await this._input.click();
101
- await this._input.type('');
102
- }
103
- async getTouchPadding() {
104
- if (this._legacy)
105
- return null;
106
- await this._input.type(`getTouchPadding;0;0;0;0`);
107
- if (this._action)
108
- await this._action.type('1');
109
- else
110
- await this._input.click();
111
- const touchPaddingString = await this._input.getText();
112
- await this._input.type('');
113
- const touchPadding = Number(touchPaddingString);
114
- if (Number.isNaN(touchPadding))
115
- return null;
116
- return touchPadding;
101
+ await this._command(`scroll;${elementId};${offset.y};0;0`);
117
102
  }
118
103
  }
119
104
  exports.HelperAndroid = HelperAndroid;
@@ -23,8 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.withFastCache = exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = void 0;
26
+ exports.withFastCache = exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = exports.isSimpleCommonSelector = void 0;
27
27
  const utils = __importStar(require("@applitools/utils"));
28
+ function isSimpleCommonSelector(selector) {
29
+ return (utils.types.isPlainObject(selector) &&
30
+ utils.types.has(selector, 'selector') &&
31
+ utils.types.isString(selector.selector));
32
+ }
33
+ exports.isSimpleCommonSelector = isSimpleCommonSelector;
28
34
  function isCommonSelector(spec, selector) {
29
35
  return (utils.types.isPlainObject(selector) &&
30
36
  utils.types.has(selector, 'selector') &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.9.16",
3
+ "version": "1.9.19",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -79,8 +79,8 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@applitools/logger": "1.1.15",
82
- "@applitools/snippets": "2.4.4",
83
- "@applitools/types": "1.5.6",
82
+ "@applitools/snippets": "2.4.5",
83
+ "@applitools/types": "1.5.7",
84
84
  "@applitools/utils": "1.3.10"
85
85
  },
86
86
  "devDependencies": {
@@ -21,10 +21,11 @@ export declare class HelperAndroid<TDriver, TContext, TElement, TSelector> {
21
21
  legacy: boolean;
22
22
  logger?: any;
23
23
  });
24
- _getElementId(element: Element<TDriver, TContext, TElement, TSelector>): Promise<string>;
24
+ private _getElementId;
25
+ private _command;
25
26
  getContentRegion(element: Element<TDriver, TContext, TElement, TSelector>): Promise<types.Region>;
27
+ getTouchPadding(): Promise<number>;
26
28
  getRegion(element: Element<TDriver, TContext, TElement, TSelector>): Promise<types.Region>;
27
29
  scrollToTop(element: Element<TDriver, TContext, TElement, TSelector>): Promise<void>;
28
30
  scrollBy(element: Element<TDriver, TContext, TElement, TSelector>, offset: types.Location): Promise<void>;
29
- getTouchPadding(): Promise<number>;
30
31
  }
@@ -5,6 +5,7 @@ declare type CommonSelector<TSelector = never> = {
5
5
  shadow?: CommonSelector<TSelector> | TSelector | string;
6
6
  frame?: CommonSelector<TSelector> | TSelector | string;
7
7
  };
8
+ export declare function isSimpleCommonSelector(selector: any): selector is CommonSelector;
8
9
  export declare function isCommonSelector<TSelector>(spec: Pick<types.SpecDriver<unknown, unknown, unknown, TSelector>, 'isSelector'>, selector: any): selector is CommonSelector<TSelector>;
9
10
  export declare function isSelector<TSelector>(spec: Pick<types.SpecDriver<unknown, unknown, unknown, TSelector>, 'isSelector'>, selector: any): selector is types.Selector<TSelector>;
10
11
  export declare function transformSelector<TSelector>(spec: Pick<types.SpecDriver<unknown, unknown, unknown, TSelector>, 'isSelector' | 'transformSelector'>, selector: types.Selector<TSelector>, environment?: {