@applitools/driver 1.11.25 → 1.11.27

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
@@ -31,15 +31,15 @@ const helper_android_1 = require("./helper-android");
31
31
  const user_agent_1 = require("./user-agent");
32
32
  const user_agent_data_1 = require("./user-agent-data");
33
33
  const capabilities_1 = require("./capabilities");
34
- const snippets = __importStar(require("@applitools/snippets"));
35
- const utils = __importStar(require("@applitools/utils"));
36
34
  const specUtils = __importStar(require("./spec-utils"));
35
+ const utils = __importStar(require("@applitools/utils"));
36
+ const snippets = require('@applitools/snippets');
37
37
  // eslint-disable-next-line
38
38
  class Driver {
39
39
  constructor(options) {
40
40
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
41
- if (options.driver instanceof Driver)
42
- return options.driver;
41
+ this._driverInfo = {};
42
+ this._customConfig = {};
43
43
  this._customConfig = (_a = options.customConfig) !== null && _a !== void 0 ? _a : {};
44
44
  this._spec = options.spec;
45
45
  this._logger = (_c = (_b = options.logger) === null || _b === void 0 ? void 0 : _b.extend({ label: 'driver' })) !== null && _c !== void 0 ? _c : (0, logger_1.makeLogger)({ label: 'driver' });
@@ -135,50 +135,52 @@ class Driver {
135
135
  }
136
136
  get isIOS() {
137
137
  var _a, _b;
138
- return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isIOS) !== null && _b !== void 0 ? _b : /iOS/i.test(this.platformName);
138
+ return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isIOS) !== null && _b !== void 0 ? _b : (!!this.platformName && /iOS/i.test(this.platformName));
139
139
  }
140
140
  get isAndroid() {
141
141
  var _a, _b;
142
- return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isAndroid) !== null && _b !== void 0 ? _b : /Android/i.test(this.platformName);
142
+ return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isAndroid) !== null && _b !== void 0 ? _b : (!!this.platformName && /Android/i.test(this.platformName));
143
143
  }
144
144
  get isMac() {
145
145
  var _a, _b;
146
- return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isMac) !== null && _b !== void 0 ? _b : /mac\s?OS/i.test(this.platformName);
146
+ return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isMac) !== null && _b !== void 0 ? _b : (!!this.platformName && /mac\s?OS/i.test(this.platformName));
147
147
  }
148
148
  get isWindows() {
149
149
  var _a, _b;
150
- return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isWindows) !== null && _b !== void 0 ? _b : /Windows/i.test(this.platformName);
150
+ return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isWindows) !== null && _b !== void 0 ? _b : (!!this.platformName && /Windows/i.test(this.platformName));
151
151
  }
152
152
  get isChromium() {
153
153
  var _a, _b;
154
- return ((_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isChromium) !== null && _b !== void 0 ? _b : (/(chrome)/i.test(this.browserName) || (/edge/i.test(this.browserName) && Number(this.browserVersion) > 44)));
154
+ return ((_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isChromium) !== null && _b !== void 0 ? _b : (!!this.browserName &&
155
+ (/(chrome)/i.test(this.browserName) || (/edge/i.test(this.browserName) && Number(this.browserVersion) > 44))));
155
156
  }
156
157
  get isIE() {
157
- return /(internet explorer|ie)/i.test(this.browserName);
158
+ return !!this.browserName && /(internet explorer|ie)/i.test(this.browserName);
158
159
  }
159
160
  get isEdgeLegacy() {
160
- return /edge/i.test(this.browserName) && Number(this.browserVersion) <= 44;
161
+ return !!this.browserName && /edge/i.test(this.browserName) && Number(this.browserVersion) <= 44;
162
+ }
163
+ get isECClient() {
164
+ var _a;
165
+ return !!((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isECClient);
166
+ }
167
+ get isEC() {
168
+ return this.isECClient || (!!this.remoteHostname && /exec-wus.applitools.com/.test(this.remoteHostname));
161
169
  }
162
170
  get sessionId() {
163
171
  var _a;
164
172
  return (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.sessionId;
165
173
  }
166
- get isExecutionGridClient() {
174
+ get remoteHostname() {
167
175
  var _a;
168
- return !!((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isExecutionGridClient);
169
- }
170
- get isExecutionGrid() {
171
- var _a, _b;
172
- if (this.isExecutionGridClient)
173
- return true;
174
- return /exec-wus.applitools.com/.test((_b = (_a = this._spec) === null || _a === void 0 ? void 0 : _a.extractHostName) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
176
+ return (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.remoteHostname;
175
177
  }
176
178
  updateCurrentContext(context) {
177
179
  this._currentContext = context;
178
180
  }
179
181
  async init() {
180
- 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, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
181
- var _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34;
182
+ 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, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22;
183
+ var _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39;
182
184
  // NOTE: this is here because saucelabs does not provide right capabilities for the first call
183
185
  await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
184
186
  const capabilities = await ((_d = (_c = this._spec).getCapabilities) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
@@ -186,26 +188,27 @@ class Driver {
186
188
  const capabilitiesInfo = capabilities ? (0, capabilities_1.parseCapabilities)(capabilities) : undefined;
187
189
  const driverInfo = await ((_f = (_e = this._spec).getDriverInfo) === null || _f === void 0 ? void 0 : _f.call(_e, this.target));
188
190
  this._driverInfo = { ...capabilitiesInfo, ...driverInfo };
191
+ (_g = (_23 = this._driverInfo).remoteHostname) !== null && _g !== void 0 ? _g : (_23.remoteHostname = (_k = (_j = (_h = this._spec).extractHostName) === null || _j === void 0 ? void 0 : _j.call(_h, this.target)) !== null && _k !== void 0 ? _k : undefined);
189
192
  if (this.isMobile) {
190
193
  this._driverInfo.orientation =
191
- (_g = (await this.getOrientation().catch(() => undefined))) !== null && _g !== void 0 ? _g : this._driverInfo.orientation;
194
+ (_l = (await this.getOrientation().catch(() => undefined))) !== null && _l !== void 0 ? _l : this._driverInfo.orientation;
192
195
  const world = await this.getCurrentWorld();
193
196
  this._driverInfo.isWebView = !!(world === null || world === void 0 ? void 0 : world.isWebView);
194
197
  }
195
198
  if (this.isWeb) {
196
199
  const browserInfo = await this.currentContext.executePoll(snippets.getBrowserInfo);
197
- (_h = (_19 = this._driverInfo).userAgent) !== null && _h !== void 0 ? _h : (_19.userAgent = browserInfo.userAgent);
198
- (_j = (_20 = this._driverInfo).pixelRatio) !== null && _j !== void 0 ? _j : (_20.pixelRatio = browserInfo.pixelRatio);
199
- (_k = (_21 = this._driverInfo).viewportScale) !== null && _k !== void 0 ? _k : (_21.viewportScale = browserInfo.viewportScale);
200
+ (_m = (_24 = this._driverInfo).userAgent) !== null && _m !== void 0 ? _m : (_24.userAgent = browserInfo.userAgent);
201
+ (_o = (_25 = this._driverInfo).pixelRatio) !== null && _o !== void 0 ? _o : (_25.pixelRatio = browserInfo.pixelRatio);
202
+ (_p = (_26 = this._driverInfo).viewportScale) !== null && _p !== void 0 ? _p : (_26.viewportScale = browserInfo.viewportScale);
200
203
  if (browserInfo.userAgentData) {
201
- (_l = (_22 = this._driverInfo).isMobile) !== null && _l !== void 0 ? _l : (_22.isMobile = this._driverInfo.isMobile);
202
- (_m = (_23 = this._driverInfo).isChromium) !== null && _m !== void 0 ? _m : (_23.isChromium = this._driverInfo.isChromium);
204
+ (_q = (_27 = this._driverInfo).isMobile) !== null && _q !== void 0 ? _q : (_27.isMobile = this._driverInfo.isMobile);
205
+ (_r = (_28 = this._driverInfo).isChromium) !== null && _r !== void 0 ? _r : (_28.isChromium = this._driverInfo.isChromium);
203
206
  if (this.isChromium) {
204
207
  if (this.isWindows && Number.parseInt(this.browserVersion) >= 107) {
205
- this._driverInfo.platformVersion = (_o = browserInfo.platformVersion) !== null && _o !== void 0 ? _o : this._driverInfo.platformVersion;
208
+ this._driverInfo.platformVersion = (_s = browserInfo.platformVersion) !== null && _s !== void 0 ? _s : this._driverInfo.platformVersion;
206
209
  }
207
210
  else if (this.isMac && Number.parseInt(this.browserVersion) >= 90) {
208
- this._driverInfo.platformVersion = (_p = browserInfo.platformVersion) !== null && _p !== void 0 ? _p : this._driverInfo.platformVersion;
211
+ this._driverInfo.platformVersion = (_t = browserInfo.platformVersion) !== null && _t !== void 0 ? _t : this._driverInfo.platformVersion;
209
212
  }
210
213
  }
211
214
  }
@@ -213,34 +216,35 @@ class Driver {
213
216
  const userAgentInfo = (0, user_agent_1.parseUserAgent)(this._driverInfo.userAgent);
214
217
  const userAgentDataInfo = browserInfo.userAgentData && (0, user_agent_data_1.parseUserAgentData)(browserInfo.userAgentData);
215
218
  this._driverInfo.browserName =
216
- (_r = (_q = userAgentInfo.browserName) !== null && _q !== void 0 ? _q : userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.browserName) !== null && _r !== void 0 ? _r : this._driverInfo.browserName;
219
+ (_v = (_u = userAgentInfo.browserName) !== null && _u !== void 0 ? _u : userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.browserName) !== null && _v !== void 0 ? _v : this._driverInfo.browserName;
217
220
  this._driverInfo.browserVersion =
218
- (_t = (_s = userAgentInfo.browserVersion) !== null && _s !== void 0 ? _s : userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.browserVersion) !== null && _t !== void 0 ? _t : this._driverInfo.browserVersion;
219
- (_u = (_24 = this._driverInfo).isMobile) !== null && _u !== void 0 ? _u : (_24.isMobile = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isMobile);
220
- (_v = (_25 = this._driverInfo).isChromium) !== null && _v !== void 0 ? _v : (_25.isChromium = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isChromium);
221
+ (_x = (_w = userAgentInfo.browserVersion) !== null && _w !== void 0 ? _w : userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.browserVersion) !== null && _x !== void 0 ? _x : this._driverInfo.browserVersion;
222
+ (_y = (_29 = this._driverInfo).isMobile) !== null && _y !== void 0 ? _y : (_29.isMobile = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isMobile);
223
+ (_z = (_30 = this._driverInfo).isChromium) !== null && _z !== void 0 ? _z : (_30.isChromium = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isChromium);
221
224
  if (this._driverInfo.isMobile) {
222
- (_w = (_26 = this._driverInfo).platformName) !== null && _w !== void 0 ? _w : (_26.platformName = (_x = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _x !== void 0 ? _x : userAgentInfo.platformName);
223
- (_y = (_27 = this._driverInfo).platformVersion) !== null && _y !== void 0 ? _y : (_27.platformVersion = (_z = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _z !== void 0 ? _z : userAgentInfo.platformVersion);
225
+ (_0 = (_31 = this._driverInfo).platformName) !== null && _0 !== void 0 ? _0 : (_31.platformName = (_1 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _1 !== void 0 ? _1 : userAgentInfo.platformName);
226
+ (_2 = (_32 = this._driverInfo).platformVersion) !== null && _2 !== void 0 ? _2 : (_32.platformVersion = (_3 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _3 !== void 0 ? _3 : userAgentInfo.platformVersion);
224
227
  }
225
228
  else {
226
229
  this._driverInfo.platformName =
227
- (_1 = (_0 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _0 !== void 0 ? _0 : userAgentInfo.platformName) !== null && _1 !== void 0 ? _1 : this._driverInfo.platformName;
230
+ (_5 = (_4 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _4 !== void 0 ? _4 : userAgentInfo.platformName) !== null && _5 !== void 0 ? _5 : this._driverInfo.platformName;
228
231
  this._driverInfo.platformVersion =
229
- (_3 = (_2 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _2 !== void 0 ? _2 : userAgentInfo.platformVersion) !== null && _3 !== void 0 ? _3 : this._driverInfo.platformVersion;
232
+ (_7 = (_6 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _6 !== void 0 ? _6 : userAgentInfo.platformVersion) !== null && _7 !== void 0 ? _7 : this._driverInfo.platformVersion;
230
233
  }
231
234
  }
232
235
  if (!this.isMobile && (this.isAndroid || this.isIOS)) {
233
236
  this._driverInfo.isMobile = true;
234
237
  this._driverInfo.isEmulation = this._driverInfo.isChrome;
235
238
  }
236
- (_4 = (_28 = this._driverInfo).features) !== null && _4 !== void 0 ? _4 : (_28.features = {});
237
- (_5 = (_29 = this._driverInfo.features).allCookies) !== null && _5 !== void 0 ? _5 : (_29.allCookies = this._driverInfo.isChrome || (/chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile));
239
+ (_8 = (_33 = this._driverInfo).features) !== null && _8 !== void 0 ? _8 : (_33.features = {});
240
+ (_9 = (_34 = this._driverInfo.features).allCookies) !== null && _9 !== void 0 ? _9 : (_34.allCookies = this._driverInfo.isChrome ||
241
+ (!!this._driverInfo.browserName && /chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile));
238
242
  }
239
243
  else {
240
244
  // this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
241
245
  let windowSize = await this._spec.getWindowSize(this.target);
242
- (_6 = (_30 = this._driverInfo).displaySize) !== null && _6 !== void 0 ? _6 : (_30.displaySize = windowSize);
243
- if (((_7 = this.orientation) === null || _7 === void 0 ? void 0 : _7.startsWith('landscape')) &&
246
+ (_10 = (_35 = this._driverInfo).displaySize) !== null && _10 !== void 0 ? _10 : (_35.displaySize = windowSize);
247
+ if (((_11 = this.orientation) === null || _11 === void 0 ? void 0 : _11.startsWith('landscape')) &&
244
248
  this._driverInfo.displaySize.height > this._driverInfo.displaySize.width) {
245
249
  this._driverInfo.displaySize = {
246
250
  width: this._driverInfo.displaySize.height,
@@ -249,14 +253,14 @@ class Driver {
249
253
  }
250
254
  if (this.isAndroid) {
251
255
  // bar sizes could be extracted only on android
252
- const systemBars = await ((_9 = (_8 = this._spec).getSystemBars) === null || _9 === void 0 ? void 0 : _9.call(_8, this.target).catch(() => null));
256
+ const systemBars = await ((_13 = (_12 = this._spec).getSystemBars) === null || _13 === void 0 ? void 0 : _13.call(_12, this.target).catch(() => null));
253
257
  const { statusBar, navigationBar } = systemBars !== null && systemBars !== void 0 ? systemBars : {};
254
258
  if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
255
259
  this._logger.log('Driver status bar', statusBar);
256
260
  const statusBarSize = statusBar.height;
257
261
  // when status bar is overlapping content on android it returns status bar height equal to display height
258
262
  if (statusBarSize < this._driverInfo.displaySize.height) {
259
- this._driverInfo.statusBarSize = Math.max((_10 = this._driverInfo.statusBarSize) !== null && _10 !== void 0 ? _10 : 0, statusBarSize);
263
+ this._driverInfo.statusBarSize = Math.max((_14 = this._driverInfo.statusBarSize) !== null && _14 !== void 0 ? _14 : 0, statusBarSize);
260
264
  }
261
265
  }
262
266
  if (navigationBar === null || navigationBar === void 0 ? void 0 : navigationBar.visible) {
@@ -265,28 +269,28 @@ class Driver {
265
269
  if (navigationBar.x > 0)
266
270
  this._driverInfo.orientation = 'landscape-secondary';
267
271
  // navigation bar size could be its height or width depending on screen orientation
268
- const navigationBarSize = navigationBar[((_11 = this.orientation) === null || _11 === void 0 ? void 0 : _11.startsWith('landscape')) ? 'width' : 'height'];
272
+ const navigationBarSize = navigationBar[((_15 = this.orientation) === null || _15 === void 0 ? void 0 : _15.startsWith('landscape')) ? 'width' : 'height'];
269
273
  // when navigation bar is invisible on android it returns navigation bar size equal to display size
270
274
  if (navigationBarSize <
271
- this._driverInfo.displaySize[((_12 = this.orientation) === null || _12 === void 0 ? void 0 : _12.startsWith('landscape')) ? 'width' : 'height']) {
272
- this._driverInfo.navigationBarSize = Math.max((_13 = this._driverInfo.navigationBarSize) !== null && _13 !== void 0 ? _13 : 0, navigationBarSize);
275
+ this._driverInfo.displaySize[((_16 = this.orientation) === null || _16 === void 0 ? void 0 : _16.startsWith('landscape')) ? 'width' : 'height']) {
276
+ this._driverInfo.navigationBarSize = Math.max((_17 = this._driverInfo.navigationBarSize) !== null && _17 !== void 0 ? _17 : 0, navigationBarSize);
273
277
  }
274
278
  else {
275
279
  this._driverInfo.navigationBarSize = 0;
276
280
  }
277
281
  }
278
282
  // bar sizes have to be scaled on android
279
- (_31 = this._driverInfo).statusBarSize && (_31.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio);
280
- (_32 = this._driverInfo).navigationBarSize && (_32.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio);
283
+ (_36 = this._driverInfo).statusBarSize && (_36.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio);
284
+ (_37 = this._driverInfo).navigationBarSize && (_37.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio);
281
285
  windowSize = utils.geometry.scale(windowSize, 1 / this.pixelRatio);
282
- (_33 = this._driverInfo).displaySize && (_33.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
286
+ (_38 = this._driverInfo).displaySize && (_38.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
283
287
  }
284
288
  if (this.isIOS) {
285
- if ((_14 = this.orientation) === null || _14 === void 0 ? void 0 : _14.startsWith('landscape'))
289
+ if ((_18 = this.orientation) === null || _18 === void 0 ? void 0 : _18.startsWith('landscape'))
286
290
  this._driverInfo.statusBarSize = 0;
287
291
  }
288
292
  // calculate viewport location
289
- (_15 = (_34 = this._driverInfo).viewportLocation) !== null && _15 !== void 0 ? _15 : (_34.viewportLocation = {
293
+ (_19 = (_39 = this._driverInfo).viewportLocation) !== null && _19 !== void 0 ? _19 : (_39.viewportLocation = {
290
294
  x: this.orientation === 'landscape' ? this.navigationBarSize : 0,
291
295
  y: this.statusBarSize,
292
296
  });
@@ -295,21 +299,27 @@ class Driver {
295
299
  this._driverInfo.viewportSize = { ...this._driverInfo.displaySize };
296
300
  this._driverInfo.viewportSize.height -= this.statusBarSize;
297
301
  if (this.isAndroid) {
298
- this._driverInfo.viewportSize[((_16 = this.orientation) === null || _16 === void 0 ? void 0 : _16.startsWith('landscape')) ? 'width' : 'height'] -=
302
+ this._driverInfo.viewportSize[((_20 = this.orientation) === null || _20 === void 0 ? void 0 : _20.startsWith('landscape')) ? 'width' : 'height'] -=
299
303
  this.navigationBarSize;
300
304
  }
301
305
  }
302
306
  // calculate safe area
303
307
  if (this.isIOS && !this._driverInfo.safeArea) {
304
308
  this._driverInfo.safeArea = { x: 0, y: 0, ...this._driverInfo.displaySize };
305
- const topElement = await this.element({ type: '-ios class chain', selector: '**/XCUIElementTypeNavigationBar' });
309
+ const topElement = await this.element({
310
+ type: '-ios class chain',
311
+ selector: '**/XCUIElementTypeNavigationBar',
312
+ });
306
313
  if (topElement) {
307
314
  const topRegion = await this._spec.getElementRegion(this.target, topElement.target);
308
315
  const topOffset = topRegion.y + topRegion.height;
309
316
  this._driverInfo.safeArea.y = topOffset;
310
317
  this._driverInfo.safeArea.height -= topOffset;
311
318
  }
312
- const bottomElement = await this.element({ type: '-ios class chain', selector: '**/XCUIElementTypeTabBar' });
319
+ const bottomElement = await this.element({
320
+ type: '-ios class chain',
321
+ selector: '**/XCUIElementTypeTabBar',
322
+ });
313
323
  if (bottomElement) {
314
324
  const bottomRegion = await this._spec.getElementRegion(this.target, bottomElement.target);
315
325
  const bottomOffset = bottomRegion.height;
@@ -318,12 +328,12 @@ class Driver {
318
328
  }
319
329
  // TODO: if user opts into NML, skip initializing the helpers
320
330
  // init helper lib
321
- if (!((_17 = this._customConfig) === null || _17 === void 0 ? void 0 : _17.disableHelper)) {
331
+ if (!((_21 = this._customConfig) === null || _21 === void 0 ? void 0 : _21.disableHelper)) {
322
332
  this._helper = this.isIOS
323
333
  ? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this, logger: this._logger })
324
334
  : await helper_android_1.HelperAndroid.make({ spec: this._spec, driver: this, logger: this._logger });
325
335
  }
326
- this._logger.log(`Helper set to ${(_18 = this._helper) === null || _18 === void 0 ? void 0 : _18.name}`);
336
+ this._logger.log(`Helper set to ${(_22 = this._helper) === null || _22 === void 0 ? void 0 : _22.name}`);
327
337
  }
328
338
  this._logger.log('Combined driver info', this._driverInfo);
329
339
  return this;
@@ -377,7 +387,7 @@ class Driver {
377
387
  async getWorlds(attempt = 1) {
378
388
  var _a, _b;
379
389
  if (!this._spec.getWorlds)
380
- return;
390
+ return [];
381
391
  this._logger.log('attempting to find worlds');
382
392
  await utils.general.sleep(500);
383
393
  const worlds = await ((_b = (_a = this._spec).getWorlds) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
@@ -395,7 +405,7 @@ class Driver {
395
405
  async getCurrentWorld() {
396
406
  var _a, _b;
397
407
  if (!this._spec.getCurrentWorld)
398
- return;
408
+ return undefined;
399
409
  const [origin, next] = await this.getWorlds();
400
410
  const currentWorld = await ((_b = (_a = this._spec).getCurrentWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
401
411
  const result = {
@@ -410,9 +420,9 @@ class Driver {
410
420
  }
411
421
  // end world
412
422
  async getSessionMetadata() {
413
- var _a;
414
- if (this.isExecutionGridClient)
415
- return await ((_a = this._spec) === null || _a === void 0 ? void 0 : _a.getSessionMetadata(this.target));
423
+ var _a, _b;
424
+ if (this.isECClient)
425
+ return await ((_b = (_a = this._spec).getSessionMetadata) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
416
426
  }
417
427
  async refreshContexts() {
418
428
  if (this.isNative)
@@ -446,7 +456,10 @@ class Driver {
446
456
  }
447
457
  async function getChildContextsInfo(context) {
448
458
  const framesInfo = await spec.executeScript(context, snippets.getChildFramesInfo);
449
- return framesInfo.map(([contextElement, isCORS]) => ({ contextElement, isCORS }));
459
+ return framesInfo.map(([contextElement, isCORS]) => ({
460
+ contextElement,
461
+ isCORS,
462
+ }));
450
463
  }
451
464
  async function isEqualElements(context, element1, element2) {
452
465
  return spec.executeScript(context, snippets.isEqualElements, [element1, element2]).catch(() => false);
@@ -467,6 +480,7 @@ class Driver {
467
480
  if (isWantedContext)
468
481
  return childContextInfo.contextElement;
469
482
  }
483
+ return null;
470
484
  }
471
485
  async function findContextPath(context, contextInfo, contextPath = []) {
472
486
  const contentDocument = await spec.findElement(context, transformSelector('html'));
@@ -488,8 +502,7 @@ class Driver {
488
502
  }
489
503
  async switchTo(context) {
490
504
  if (await this.currentContext.equals(context)) {
491
- this._currentContext = context;
492
- return;
505
+ return (this._currentContext = context);
493
506
  }
494
507
  const currentPath = this.currentContext.path;
495
508
  const requiredPath = context.path;
@@ -583,10 +596,14 @@ class Driver {
583
596
  if (this.isAndroid) {
584
597
  normalizedRegion = utils.geometry.scale(normalizedRegion, 1 / this.pixelRatio);
585
598
  }
586
- if (this.isIOS && utils.geometry.isIntersected(normalizedRegion, this._driverInfo.safeArea)) {
599
+ if (this.isIOS &&
600
+ this._driverInfo.safeArea &&
601
+ utils.geometry.isIntersected(normalizedRegion, this._driverInfo.safeArea)) {
587
602
  normalizedRegion = utils.geometry.intersect(normalizedRegion, this._driverInfo.safeArea);
588
603
  }
589
- normalizedRegion = utils.geometry.offsetNegative(normalizedRegion, this._driverInfo.viewportLocation);
604
+ if (this._driverInfo.viewportLocation) {
605
+ normalizedRegion = utils.geometry.offsetNegative(normalizedRegion, this._driverInfo.viewportLocation);
606
+ }
590
607
  if (normalizedRegion.y < 0) {
591
608
  normalizedRegion.height += normalizedRegion.y;
592
609
  normalizedRegion.y = 0;
@@ -603,6 +620,9 @@ class Driver {
603
620
  async elements(selector) {
604
621
  return this.currentContext.elements(selector);
605
622
  }
623
+ async waitFor(selector, options) {
624
+ return this.currentContext.waitFor(selector, options);
625
+ }
606
626
  async execute(script, arg) {
607
627
  return this.currentContext.execute(script, arg);
608
628
  }
@@ -690,7 +710,7 @@ class Driver {
690
710
  async getDisplaySize() {
691
711
  var _a, _b;
692
712
  if (this.isWeb && !this.isMobile)
693
- return;
713
+ return undefined;
694
714
  if ((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.displaySize) {
695
715
  this._logger.log('Extracting display size from native driver using cached value');
696
716
  return this._driverInfo.displaySize;
@@ -705,8 +725,7 @@ class Driver {
705
725
  }
706
726
  async getOrientation() {
707
727
  if (this.isWeb && !this.isMobile)
708
- return;
709
- let orientation;
728
+ return undefined;
710
729
  if (this.isAndroid) {
711
730
  this._logger.log('Extracting device orientation using adb command on android');
712
731
  const rotation = await this.execute('mobile:shell', {
@@ -714,65 +733,73 @@ class Driver {
714
733
  })
715
734
  .then(r => { var _a; return (_a = r === null || r === void 0 ? void 0 : r.trim) === null || _a === void 0 ? void 0 : _a.call(r); })
716
735
  .catch(() => null);
717
- if (rotation === 'ROTATION_0' || rotation === '0')
718
- orientation = 'portrait';
719
- else if (rotation === 'ROTATION_90' || rotation === '3')
720
- orientation = 'landscape-secondary';
721
- else if (rotation === 'ROTATION_180' || rotation === '2')
722
- orientation = 'portrait-secondary';
723
- else if (rotation === 'ROTATION_270' || rotation === '1')
724
- orientation = 'landscape';
725
- }
726
- if (!orientation) {
727
- this._logger.log('Extracting device orientation');
728
- orientation = await this._spec.getOrientation(this.target);
736
+ if (rotation) {
737
+ let orientation = undefined;
738
+ if (rotation === 'ROTATION_0' || rotation === '0')
739
+ orientation = 'portrait';
740
+ else if (rotation === 'ROTATION_90' || rotation === '3')
741
+ orientation = 'landscape-secondary';
742
+ else if (rotation === 'ROTATION_180' || rotation === '2')
743
+ orientation = 'portrait-secondary';
744
+ else if (rotation === 'ROTATION_270' || rotation === '1')
745
+ orientation = 'landscape';
746
+ this._logger.log('Extracted device orientation:', orientation);
747
+ return orientation;
748
+ }
729
749
  }
750
+ this._logger.log('Extracting device orientation');
751
+ const orientation = await this._spec.getOrientation(this.target);
730
752
  this._logger.log('Extracted device orientation:', orientation);
731
753
  return orientation;
732
754
  }
733
755
  async setOrientation(orientation) {
734
756
  if (this.isWeb && !this.isMobile)
735
- return;
757
+ return undefined;
736
758
  this._logger.log('Set device orientation:', orientation);
737
759
  await this._spec.setOrientation(this.target, orientation);
738
760
  }
739
761
  async getCookies() {
740
- var _a, _b, _c;
741
- if (this.isNative || !this.features.allCookies)
762
+ var _a, _b, _c, _d, _e;
763
+ var _f;
764
+ if (this.isNative || !((_a = this.features) === null || _a === void 0 ? void 0 : _a.allCookies))
742
765
  return [];
743
766
  try {
744
- return (_c = (await ((_b = (_a = this._spec).getCookies) === null || _b === void 0 ? void 0 : _b.call(_a, this.target)))) !== null && _c !== void 0 ? _c : [];
767
+ return (_d = (await ((_c = (_b = this._spec).getCookies) === null || _c === void 0 ? void 0 : _c.call(_b, this.target)))) !== null && _d !== void 0 ? _d : [];
745
768
  }
746
769
  catch (error) {
770
+ (_e = (_f = this._driverInfo).features) !== null && _e !== void 0 ? _e : (_f.features = {});
747
771
  this._driverInfo.features.allCookies = false;
748
772
  throw error;
749
773
  }
750
774
  }
751
775
  async getTitle() {
752
776
  if (this.isNative)
753
- return null;
777
+ return undefined;
754
778
  const title = await this._spec.getTitle(this.target);
755
779
  this._logger.log('Extracted title:', title);
756
780
  return title;
757
781
  }
758
782
  async getUrl() {
759
783
  if (this.isNative)
760
- return null;
784
+ return undefined;
761
785
  const url = await this._spec.getUrl(this.target);
762
786
  this._logger.log('Extracted url:', url);
763
787
  return url;
764
788
  }
765
789
  async visit(url) {
766
- await this._spec.visit(this.target, url);
790
+ var _a, _b;
791
+ await ((_b = (_a = this._spec).visit) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, url));
767
792
  }
768
793
  }
769
794
  exports.Driver = Driver;
770
795
  function isDriver(driver, spec) {
771
- return driver instanceof Driver || (spec === null || spec === void 0 ? void 0 : spec.isDriver(driver));
796
+ return driver instanceof Driver || !!(spec === null || spec === void 0 ? void 0 : spec.isDriver(driver));
772
797
  }
773
798
  exports.isDriver = isDriver;
774
799
  async function makeDriver(options) {
775
- const driver = new Driver(options);
800
+ const driver = options.driver instanceof Driver
801
+ ? options.driver
802
+ : new Driver(options);
776
803
  await driver.init();
777
804
  await driver.refreshContexts();
778
805
  return driver;
package/dist/element.js CHANGED
@@ -23,26 +23,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Element = void 0;
26
+ exports.isElementReference = exports.Element = void 0;
27
27
  const utils = __importStar(require("@applitools/utils"));
28
28
  const specUtils = __importStar(require("./spec-utils"));
29
29
  const snippets = require('@applitools/snippets');
30
30
  class Element {
31
31
  constructor(options) {
32
- var _a, _b, _c, _d, _e, _f;
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
33
33
  this._state = {};
34
- if (options.element instanceof Element)
35
- return options.element;
36
34
  this._spec = options.spec;
37
- if (options.context)
38
- this._context = options.context;
39
- if (options.logger)
40
- this._logger = options.logger;
41
- this._target = (_c = (_b = (_a = this._spec).transformElement) === null || _b === void 0 ? void 0 : _b.call(_a, options.element)) !== null && _c !== void 0 ? _c : options.element;
42
- if (this._spec.isElement(this._target)) {
43
- // Some frameworks contains information about the selector inside an element
44
- this._selector = (_d = options.selector) !== null && _d !== void 0 ? _d : (_f = (_e = this._spec).extractSelector) === null || _f === void 0 ? void 0 : _f.call(_e, options.element);
45
- this._index = options.index;
35
+ this._context = options.context;
36
+ this._logger = options.logger;
37
+ if (utils.types.has(options, 'element')) {
38
+ this._target = (_c = (_b = (_a = this._spec).transformElement) === null || _b === void 0 ? void 0 : _b.call(_a, options.element)) !== null && _c !== void 0 ? _c : options.element;
39
+ if (this._spec.isElement(this._target)) {
40
+ // Some frameworks contains information about the selector inside an element
41
+ this._selector = (_d = options.selector) !== null && _d !== void 0 ? _d : (_f = (_e = this._spec).extractSelector) === null || _f === void 0 ? void 0 : _f.call(_e, options.element);
42
+ this._index = options.index;
43
+ }
46
44
  }
47
45
  else if (specUtils.isSelector(this._spec, options.selector)) {
48
46
  this._selector = options.selector;
@@ -54,11 +52,14 @@ class Element {
54
52
  this._commonSelector = this._selector;
55
53
  }
56
54
  else if (this._selector && this._spec.untransformSelector) {
57
- this._commonSelector = this._spec.untransformSelector(this._spec.transformSelector(this._selector));
55
+ this._commonSelector = this._spec.untransformSelector((_j = (_h = (_g = this._spec).transformSelector) === null || _h === void 0 ? void 0 : _h.call(_g, this._selector)) !== null && _j !== void 0 ? _j : this._selector);
58
56
  }
59
57
  else if (utils.types.isString(this._selector)) {
60
58
  this._commonSelector = { selector: this._selector };
61
59
  }
60
+ else {
61
+ this._commonSelector = null;
62
+ }
62
63
  }
63
64
  get target() {
64
65
  return this._target;
@@ -79,9 +80,11 @@ class Element {
79
80
  return this.context.driver;
80
81
  }
81
82
  get isRef() {
82
- return this.context.isRef || !this.target;
83
+ var _a;
84
+ return ((_a = this.context) === null || _a === void 0 ? void 0 : _a.isRef) || !this.target;
83
85
  }
84
86
  async equals(element) {
87
+ var _a, _b, _c;
85
88
  if (this.isRef)
86
89
  return false;
87
90
  element = element instanceof Element ? element.target : element;
@@ -91,7 +94,7 @@ class Element {
91
94
  .catch(() => false);
92
95
  }
93
96
  else {
94
- return this._spec.isEqualElements(this.context.target, this.target, element);
97
+ return (_c = (_b = (_a = this._spec).isEqualElements) === null || _b === void 0 ? void 0 : _b.call(_a, this.context.target, this.target, element)) !== null && _c !== void 0 ? _c : false;
95
98
  }
96
99
  }
97
100
  async contains(innerElement) {
@@ -132,8 +135,8 @@ class Element {
132
135
  if (!element)
133
136
  throw new Error(`Cannot find element with selector ${JSON.stringify(this._selector)}`);
134
137
  this._target = element.target;
135
- return this;
136
138
  }
139
+ return this;
137
140
  }
138
141
  async getRegion() {
139
142
  const region = await this.withRefresh(async () => {
@@ -172,12 +175,12 @@ class Element {
172
175
  async getContentRegion(options = {}) {
173
176
  var _a, _b, _c;
174
177
  if (!this.driver.isNative)
175
- return;
178
+ return null;
176
179
  this._logger.log('Extracting content region of native element with selector', this.selector);
177
180
  let contentRegion = await ((_a = this.driver.helper) === null || _a === void 0 ? void 0 : _a.getContentRegion(this, options));
178
181
  this._logger.log('Extracted content region using helper library', contentRegion);
179
182
  if (!contentRegion || !this.driver.isAndroid) {
180
- let attrContentRegion;
183
+ let attrContentRegion = null;
181
184
  try {
182
185
  const size = JSON.parse(await this.getAttribute('contentSize'));
183
186
  attrContentRegion = {
@@ -228,9 +231,6 @@ class Element {
228
231
  }
229
232
  return contentRegion !== null && contentRegion !== void 0 ? contentRegion : (await this._spec.getElementRegion(this.driver.target, this.target));
230
233
  }
231
- async getContentSizeIOS() {
232
- return this._spec.getElementRegion(this.driver.target, this.target);
233
- }
234
234
  async getContentSize(options = {}) {
235
235
  if (this._state.contentSize)
236
236
  return this._state.contentSize;
@@ -599,11 +599,14 @@ class Element {
599
599
  }
600
600
  }
601
601
  async click() {
602
- await this._spec.click(this.context.target, this.target);
602
+ var _a, _b;
603
+ this._logger.log(`Clicking on the element with selector`, this.selector);
604
+ await ((_b = (_a = this._spec).click) === null || _b === void 0 ? void 0 : _b.call(_a, this.context.target, this.target));
603
605
  }
604
606
  async type(value) {
605
- this._logger.log(`Typing text "${value}" in element with selector`, this.selector);
606
- await this._spec.setElementText(this.context.target, this.target, value);
607
+ var _a, _b;
608
+ this._logger.log(`Typing text "${value}" in the element with selector`, this.selector);
609
+ await ((_b = (_a = this._spec).setElementText) === null || _b === void 0 ? void 0 : _b.call(_a, this.context.target, this.target, value));
607
610
  }
608
611
  async preserveState() {
609
612
  const scrollOffset = await this.getScrollOffset();
@@ -622,8 +625,8 @@ class Element {
622
625
  if (state.transforms)
623
626
  await this.context.execute(snippets.setElementStyleProperties, [this, state.transforms]);
624
627
  if (state === this._state) {
625
- this._state.scrollOffset = null;
626
- this._state.transforms = null;
628
+ this._state.scrollOffset = undefined;
629
+ this._state.transforms = undefined;
627
630
  }
628
631
  }
629
632
  async hideScrollbars() {
@@ -690,3 +693,7 @@ class Element {
690
693
  }
691
694
  }
692
695
  exports.Element = Element;
696
+ function isElementReference(reference, spec) {
697
+ return !!spec && (spec.isElement(reference) || specUtils.isSelector(spec, reference));
698
+ }
699
+ exports.isElementReference = isElementReference;