@applitools/driver 1.11.9 → 1.11.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/element.js CHANGED
@@ -96,8 +96,8 @@ class Element {
96
96
  }
97
97
  async contains(innerElement) {
98
98
  const contains = await this.withRefresh(async () => {
99
- var _a, _b, _c, _d, _e;
100
- var _f;
99
+ var _a, _b;
100
+ var _c;
101
101
  innerElement = innerElement instanceof Element ? innerElement.target : innerElement;
102
102
  if (this.driver.isWeb) {
103
103
  this._logger.log('Checking if web element with selector', this.selector, 'contains element', innerElement);
@@ -111,19 +111,10 @@ class Element {
111
111
  if (await this.equals(innerElement))
112
112
  return false;
113
113
  // 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
114
- let contentRegion = await ((_b = this.driver.helper) === null || _b === void 0 ? void 0 : _b.getContentRegion(this));
115
- if (!contentRegion || !this.driver.isAndroid) {
116
- const nativeContentRegion = await this.getContentSizeFromAttribute();
117
- contentRegion = {
118
- x: nativeContentRegion.x,
119
- y: nativeContentRegion.y,
120
- width: Math.max((_c = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.width) !== null && _c !== void 0 ? _c : 0, nativeContentRegion.width),
121
- height: Math.max((_d = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.height) !== null && _d !== void 0 ? _d : 0, nativeContentRegion.height),
122
- };
123
- }
114
+ const contentRegion = await this.getContentRegion();
124
115
  const innerRegion = await this._spec.getElementRegion(this.driver.target, innerElement);
125
116
  const contains = utils.geometry.contains(contentRegion, innerRegion);
126
- (_e = (_f = this._state).containedElements) !== null && _e !== void 0 ? _e : (_f.containedElements = new Map());
117
+ (_b = (_c = this._state).containedElements) !== null && _b !== void 0 ? _b : (_c.containedElements = new Map());
127
118
  this._state.containedElements.set(innerElement, contains);
128
119
  return contains;
129
120
  }
@@ -178,44 +169,72 @@ class Element {
178
169
  this._logger.log('Extracted client region', region);
179
170
  return region;
180
171
  }
181
- async getContentSizeFromAttribute() {
182
- try {
183
- const data = await this.getAttribute('contentSize');
184
- const contentSize = JSON.parse(data);
185
- return {
186
- x: contentSize.left,
187
- y: contentSize.top,
188
- width: contentSize.width,
189
- height: this.driver.isIOS
190
- ? Math.max(contentSize.height, contentSize.scrollableOffset)
191
- : contentSize.height + contentSize.scrollableOffset,
192
- };
193
- }
194
- catch (err) {
195
- this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
196
- }
197
- if (this.driver.isIOS) {
198
- const type = await this.getAttribute('type');
199
- if (type === 'XCUIElementTypeScrollView') {
200
- const elementRegion = await this._spec.getElementRegion(this.driver.target, this.target);
201
- const [childElement] = await this.driver.elements({
202
- type: 'xpath',
203
- selector: '//XCUIElementTypeScrollView[1]/*', // We cannot be sure that our element is the first one
204
- });
205
- const childElementRegion = await this._spec.getElementRegion(this.driver.target, childElement.target);
206
- return {
207
- ...elementRegion,
208
- height: childElementRegion.y + childElementRegion.height - elementRegion.y,
172
+ async getContentRegion(options = {}) {
173
+ var _a, _b, _c;
174
+ if (!this.driver.isNative)
175
+ return;
176
+ this._logger.log('Extracting content region of native element with selector', this.selector);
177
+ let contentRegion = await ((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.getContentRegion(this, options));
178
+ this._logger.log('Extracted content region using helper library', contentRegion);
179
+ if (!contentRegion || !this.driver.isAndroid) {
180
+ let attrContentRegion;
181
+ try {
182
+ const size = JSON.parse(await this.getAttribute('contentSize'));
183
+ attrContentRegion = {
184
+ x: size.left,
185
+ y: size.top,
186
+ width: size.width,
187
+ height: this.driver.isIOS
188
+ ? Math.max(size.height, size.scrollableOffset)
189
+ : size.height + size.scrollableOffset,
190
+ };
191
+ }
192
+ catch (err) {
193
+ this._logger.warn(`Unable to get the attribute 'contentSize' due to the following error: '${err.message}'`);
194
+ }
195
+ this._logger.log('Extracted content region using attribute', attrContentRegion);
196
+ // ios workaround
197
+ if (!attrContentRegion && this.driver.isIOS) {
198
+ try {
199
+ const type = await this.getAttribute('type');
200
+ if (type === 'XCUIElementTypeScrollView') {
201
+ const [child] = await this.driver.elements({
202
+ type: 'xpath',
203
+ selector: '//XCUIElementTypeScrollView[1]/*', // We cannot be sure that our element is the first one
204
+ });
205
+ if (child) {
206
+ const region = await this._spec.getElementRegion(this.driver.target, this.target);
207
+ const childRegion = await this._spec.getElementRegion(this.driver.target, child.target);
208
+ attrContentRegion = {
209
+ ...region,
210
+ height: childRegion.y + childRegion.height - region.y,
211
+ };
212
+ }
213
+ }
214
+ }
215
+ catch (err) {
216
+ this._logger.warn(`Unable to calculate content region using iOS workaround due to the following error: '${err.message}'`);
217
+ }
218
+ this._logger.log('Extracted content region using iOS workaround', attrContentRegion);
219
+ }
220
+ if (attrContentRegion) {
221
+ contentRegion = {
222
+ x: attrContentRegion.x,
223
+ y: attrContentRegion.y,
224
+ width: Math.max((_b = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.width) !== null && _b !== void 0 ? _b : 0, attrContentRegion.width),
225
+ height: Math.max((_c = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.height) !== null && _c !== void 0 ? _c : 0, attrContentRegion.height),
209
226
  };
210
227
  }
211
228
  }
229
+ return contentRegion !== null && contentRegion !== void 0 ? contentRegion : (await this._spec.getElementRegion(this.driver.target, this.target));
230
+ }
231
+ async getContentSizeIOS() {
212
232
  return this._spec.getElementRegion(this.driver.target, this.target);
213
233
  }
214
234
  async getContentSize(options = {}) {
215
235
  if (this._state.contentSize)
216
236
  return this._state.contentSize;
217
237
  const size = await this.withRefresh(async () => {
218
- var _a, _b, _c;
219
238
  if (this.driver.isWeb) {
220
239
  this._logger.log('Extracting content size of web element with selector', this.selector);
221
240
  return this.context.execute(snippets.getElementContentSize, [this]);
@@ -223,19 +242,7 @@ class Element {
223
242
  else {
224
243
  this._logger.log('Extracting content size of native element with selector', this.selector);
225
244
  try {
226
- let contentRegion = await ((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.getContentRegion(this, options));
227
- this._logger.log('Extracted native content region using helper library', contentRegion);
228
- // on android extraction of this argument will perform non-deterministic touch action, so it is better to avoid it
229
- if (!contentRegion || !this.driver.isAndroid) {
230
- const attrContentRegion = await this.getContentSizeFromAttribute();
231
- this._logger.log('Extracted native content region using attribute', attrContentRegion);
232
- contentRegion = {
233
- x: attrContentRegion.x,
234
- y: attrContentRegion.y,
235
- width: Math.max((_b = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.width) !== null && _b !== void 0 ? _b : 0, attrContentRegion.width),
236
- height: Math.max((_c = contentRegion === null || contentRegion === void 0 ? void 0 : contentRegion.height) !== null && _c !== void 0 ? _c : 0, attrContentRegion.height),
237
- };
238
- }
245
+ const contentRegion = await this.getContentRegion(options);
239
246
  this._state.contentSize = utils.geometry.size(contentRegion);
240
247
  if (this.driver.isAndroid) {
241
248
  this._state.contentSize = utils.geometry.scale(this._state.contentSize, 1 / this.driver.pixelRatio);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.11.9",
3
+ "version": "1.11.11",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -88,7 +88,7 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@applitools/logger": "1.1.30",
91
- "@applitools/snippets": "2.4.8",
91
+ "@applitools/snippets": "2.4.9",
92
92
  "@applitools/utils": "1.3.16",
93
93
  "semver": "7.3.7"
94
94
  },
@@ -41,12 +41,14 @@ export declare class Element<TDriver, TContext, TElement, TSelector> {
41
41
  init(context: Context<TDriver, TContext, TElement, TSelector>): Promise<this>;
42
42
  getRegion(): Promise<Region>;
43
43
  getClientRegion(): Promise<Region>;
44
- getContentSizeFromAttribute(): Promise<{
45
- x: any;
46
- y: any;
47
- width: any;
48
- height: any;
49
- }>;
44
+ getContentRegion(options?: {
45
+ lazyLoad?: {
46
+ scrollLength?: number;
47
+ waitingTime?: number;
48
+ maxAmountToScroll?: number;
49
+ };
50
+ }): Promise<Region>;
51
+ getContentSizeIOS(): Promise<Region>;
50
52
  getContentSize(options?: {
51
53
  lazyLoad?: {
52
54
  scrollLength?: number;