@applitools/driver 1.11.26 → 1.11.28
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/context.js +35 -34
- package/dist/debug/check-spec-driver.js +4 -4
- package/dist/driver.js +107 -82
- package/dist/element.js +34 -27
- package/dist/fake/spec-driver.js +5 -4
- package/dist/helper-android.js +20 -20
- package/dist/helper-ios.js +9 -6
- package/dist/user-agent-data.js +2 -2
- package/package.json +8 -25
- package/types/capabilities.d.ts +1 -1
- package/types/context.d.ts +25 -29
- package/types/debug/check-spec-driver.d.ts +16 -1
- package/types/driver.d.ts +31 -22
- package/types/element.d.ts +27 -20
- package/types/fake/mock-driver.d.ts +8 -6
- package/types/fake/spec-driver.d.ts +5 -5
- package/types/helper-android.d.ts +7 -7
- package/types/helper-ios.d.ts +2 -2
- package/types/selector.d.ts +2 -2
- package/types/spec-driver.d.ts +2 -2
- package/types/spec-utils.d.ts +1 -1
- package/types/types.d.ts +2 -2
- package/types/user-agent-data.d.ts +1 -1
- package/types/user-agent.d.ts +2 -2
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
|
-
|
|
42
|
-
|
|
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,29 +135,30 @@ 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 : (
|
|
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;
|
|
161
162
|
}
|
|
162
163
|
get isECClient() {
|
|
163
164
|
var _a;
|
|
@@ -178,8 +179,8 @@ class Driver {
|
|
|
178
179
|
this._currentContext = context;
|
|
179
180
|
}
|
|
180
181
|
async init() {
|
|
181
|
-
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;
|
|
182
|
-
var
|
|
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;
|
|
183
184
|
// NOTE: this is here because saucelabs does not provide right capabilities for the first call
|
|
184
185
|
await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
185
186
|
const capabilities = await ((_d = (_c = this._spec).getCapabilities) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
|
|
@@ -187,27 +188,27 @@ class Driver {
|
|
|
187
188
|
const capabilitiesInfo = capabilities ? (0, capabilities_1.parseCapabilities)(capabilities) : undefined;
|
|
188
189
|
const driverInfo = await ((_f = (_e = this._spec).getDriverInfo) === null || _f === void 0 ? void 0 : _f.call(_e, this.target));
|
|
189
190
|
this._driverInfo = { ...capabilitiesInfo, ...driverInfo };
|
|
190
|
-
(_g = (
|
|
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);
|
|
191
192
|
if (this.isMobile) {
|
|
192
193
|
this._driverInfo.orientation =
|
|
193
|
-
(
|
|
194
|
+
(_l = (await this.getOrientation().catch(() => undefined))) !== null && _l !== void 0 ? _l : this._driverInfo.orientation;
|
|
194
195
|
const world = await this.getCurrentWorld();
|
|
195
196
|
this._driverInfo.isWebView = !!(world === null || world === void 0 ? void 0 : world.isWebView);
|
|
196
197
|
}
|
|
197
198
|
if (this.isWeb) {
|
|
198
199
|
const browserInfo = await this.currentContext.executePoll(snippets.getBrowserInfo);
|
|
199
|
-
(
|
|
200
|
-
(
|
|
201
|
-
(
|
|
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);
|
|
202
203
|
if (browserInfo.userAgentData) {
|
|
203
|
-
(
|
|
204
|
-
(
|
|
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);
|
|
205
206
|
if (this.isChromium) {
|
|
206
207
|
if (this.isWindows && Number.parseInt(this.browserVersion) >= 107) {
|
|
207
|
-
this._driverInfo.platformVersion = (
|
|
208
|
+
this._driverInfo.platformVersion = (_s = browserInfo.platformVersion) !== null && _s !== void 0 ? _s : this._driverInfo.platformVersion;
|
|
208
209
|
}
|
|
209
210
|
else if (this.isMac && Number.parseInt(this.browserVersion) >= 90) {
|
|
210
|
-
this._driverInfo.platformVersion = (
|
|
211
|
+
this._driverInfo.platformVersion = (_t = browserInfo.platformVersion) !== null && _t !== void 0 ? _t : this._driverInfo.platformVersion;
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
}
|
|
@@ -215,34 +216,35 @@ class Driver {
|
|
|
215
216
|
const userAgentInfo = (0, user_agent_1.parseUserAgent)(this._driverInfo.userAgent);
|
|
216
217
|
const userAgentDataInfo = browserInfo.userAgentData && (0, user_agent_data_1.parseUserAgentData)(browserInfo.userAgentData);
|
|
217
218
|
this._driverInfo.browserName =
|
|
218
|
-
(
|
|
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;
|
|
219
220
|
this._driverInfo.browserVersion =
|
|
220
|
-
(
|
|
221
|
-
(
|
|
222
|
-
(
|
|
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);
|
|
223
224
|
if (this._driverInfo.isMobile) {
|
|
224
|
-
(
|
|
225
|
-
(
|
|
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);
|
|
226
227
|
}
|
|
227
228
|
else {
|
|
228
229
|
this._driverInfo.platformName =
|
|
229
|
-
(
|
|
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;
|
|
230
231
|
this._driverInfo.platformVersion =
|
|
231
|
-
(
|
|
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;
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
if (!this.isMobile && (this.isAndroid || this.isIOS)) {
|
|
235
236
|
this._driverInfo.isMobile = true;
|
|
236
237
|
this._driverInfo.isEmulation = this._driverInfo.isChrome;
|
|
237
238
|
}
|
|
238
|
-
(
|
|
239
|
-
(
|
|
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));
|
|
240
242
|
}
|
|
241
243
|
else {
|
|
242
244
|
// this value always excludes the height of the navigation bar, and sometimes it also excludes the height of the status bar
|
|
243
245
|
let windowSize = await this._spec.getWindowSize(this.target);
|
|
244
|
-
(
|
|
245
|
-
if (((
|
|
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')) &&
|
|
246
248
|
this._driverInfo.displaySize.height > this._driverInfo.displaySize.width) {
|
|
247
249
|
this._driverInfo.displaySize = {
|
|
248
250
|
width: this._driverInfo.displaySize.height,
|
|
@@ -251,14 +253,14 @@ class Driver {
|
|
|
251
253
|
}
|
|
252
254
|
if (this.isAndroid) {
|
|
253
255
|
// bar sizes could be extracted only on android
|
|
254
|
-
const systemBars = await ((
|
|
256
|
+
const systemBars = await ((_13 = (_12 = this._spec).getSystemBars) === null || _13 === void 0 ? void 0 : _13.call(_12, this.target).catch(() => null));
|
|
255
257
|
const { statusBar, navigationBar } = systemBars !== null && systemBars !== void 0 ? systemBars : {};
|
|
256
258
|
if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) {
|
|
257
259
|
this._logger.log('Driver status bar', statusBar);
|
|
258
260
|
const statusBarSize = statusBar.height;
|
|
259
261
|
// when status bar is overlapping content on android it returns status bar height equal to display height
|
|
260
262
|
if (statusBarSize < this._driverInfo.displaySize.height) {
|
|
261
|
-
this._driverInfo.statusBarSize = Math.max((
|
|
263
|
+
this._driverInfo.statusBarSize = Math.max((_14 = this._driverInfo.statusBarSize) !== null && _14 !== void 0 ? _14 : 0, statusBarSize);
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
266
|
if (navigationBar === null || navigationBar === void 0 ? void 0 : navigationBar.visible) {
|
|
@@ -267,28 +269,28 @@ class Driver {
|
|
|
267
269
|
if (navigationBar.x > 0)
|
|
268
270
|
this._driverInfo.orientation = 'landscape-secondary';
|
|
269
271
|
// navigation bar size could be its height or width depending on screen orientation
|
|
270
|
-
const navigationBarSize = navigationBar[((
|
|
272
|
+
const navigationBarSize = navigationBar[((_15 = this.orientation) === null || _15 === void 0 ? void 0 : _15.startsWith('landscape')) ? 'width' : 'height'];
|
|
271
273
|
// when navigation bar is invisible on android it returns navigation bar size equal to display size
|
|
272
274
|
if (navigationBarSize <
|
|
273
|
-
this._driverInfo.displaySize[((
|
|
274
|
-
this._driverInfo.navigationBarSize = Math.max((
|
|
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);
|
|
275
277
|
}
|
|
276
278
|
else {
|
|
277
279
|
this._driverInfo.navigationBarSize = 0;
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
282
|
// bar sizes have to be scaled on android
|
|
281
|
-
(
|
|
282
|
-
(
|
|
283
|
+
(_36 = this._driverInfo).statusBarSize && (_36.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio);
|
|
284
|
+
(_37 = this._driverInfo).navigationBarSize && (_37.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio);
|
|
283
285
|
windowSize = utils.geometry.scale(windowSize, 1 / this.pixelRatio);
|
|
284
|
-
(
|
|
286
|
+
(_38 = this._driverInfo).displaySize && (_38.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio));
|
|
285
287
|
}
|
|
286
288
|
if (this.isIOS) {
|
|
287
|
-
if ((
|
|
289
|
+
if ((_18 = this.orientation) === null || _18 === void 0 ? void 0 : _18.startsWith('landscape'))
|
|
288
290
|
this._driverInfo.statusBarSize = 0;
|
|
289
291
|
}
|
|
290
292
|
// calculate viewport location
|
|
291
|
-
(
|
|
293
|
+
(_19 = (_39 = this._driverInfo).viewportLocation) !== null && _19 !== void 0 ? _19 : (_39.viewportLocation = {
|
|
292
294
|
x: this.orientation === 'landscape' ? this.navigationBarSize : 0,
|
|
293
295
|
y: this.statusBarSize,
|
|
294
296
|
});
|
|
@@ -297,21 +299,27 @@ class Driver {
|
|
|
297
299
|
this._driverInfo.viewportSize = { ...this._driverInfo.displaySize };
|
|
298
300
|
this._driverInfo.viewportSize.height -= this.statusBarSize;
|
|
299
301
|
if (this.isAndroid) {
|
|
300
|
-
this._driverInfo.viewportSize[((
|
|
302
|
+
this._driverInfo.viewportSize[((_20 = this.orientation) === null || _20 === void 0 ? void 0 : _20.startsWith('landscape')) ? 'width' : 'height'] -=
|
|
301
303
|
this.navigationBarSize;
|
|
302
304
|
}
|
|
303
305
|
}
|
|
304
306
|
// calculate safe area
|
|
305
307
|
if (this.isIOS && !this._driverInfo.safeArea) {
|
|
306
308
|
this._driverInfo.safeArea = { x: 0, y: 0, ...this._driverInfo.displaySize };
|
|
307
|
-
const topElement = await this.element({
|
|
309
|
+
const topElement = await this.element({
|
|
310
|
+
type: '-ios class chain',
|
|
311
|
+
selector: '**/XCUIElementTypeNavigationBar',
|
|
312
|
+
});
|
|
308
313
|
if (topElement) {
|
|
309
314
|
const topRegion = await this._spec.getElementRegion(this.target, topElement.target);
|
|
310
315
|
const topOffset = topRegion.y + topRegion.height;
|
|
311
316
|
this._driverInfo.safeArea.y = topOffset;
|
|
312
317
|
this._driverInfo.safeArea.height -= topOffset;
|
|
313
318
|
}
|
|
314
|
-
const bottomElement = await this.element({
|
|
319
|
+
const bottomElement = await this.element({
|
|
320
|
+
type: '-ios class chain',
|
|
321
|
+
selector: '**/XCUIElementTypeTabBar',
|
|
322
|
+
});
|
|
315
323
|
if (bottomElement) {
|
|
316
324
|
const bottomRegion = await this._spec.getElementRegion(this.target, bottomElement.target);
|
|
317
325
|
const bottomOffset = bottomRegion.height;
|
|
@@ -320,12 +328,12 @@ class Driver {
|
|
|
320
328
|
}
|
|
321
329
|
// TODO: if user opts into NML, skip initializing the helpers
|
|
322
330
|
// init helper lib
|
|
323
|
-
if (!((
|
|
331
|
+
if (!((_21 = this._customConfig) === null || _21 === void 0 ? void 0 : _21.disableHelper)) {
|
|
324
332
|
this._helper = this.isIOS
|
|
325
333
|
? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this, logger: this._logger })
|
|
326
334
|
: await helper_android_1.HelperAndroid.make({ spec: this._spec, driver: this, logger: this._logger });
|
|
327
335
|
}
|
|
328
|
-
this._logger.log(`Helper set to ${(
|
|
336
|
+
this._logger.log(`Helper set to ${(_22 = this._helper) === null || _22 === void 0 ? void 0 : _22.name}`);
|
|
329
337
|
}
|
|
330
338
|
this._logger.log('Combined driver info', this._driverInfo);
|
|
331
339
|
return this;
|
|
@@ -379,7 +387,7 @@ class Driver {
|
|
|
379
387
|
async getWorlds(attempt = 1) {
|
|
380
388
|
var _a, _b;
|
|
381
389
|
if (!this._spec.getWorlds)
|
|
382
|
-
return;
|
|
390
|
+
return [];
|
|
383
391
|
this._logger.log('attempting to find worlds');
|
|
384
392
|
await utils.general.sleep(500);
|
|
385
393
|
const worlds = await ((_b = (_a = this._spec).getWorlds) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
@@ -397,7 +405,7 @@ class Driver {
|
|
|
397
405
|
async getCurrentWorld() {
|
|
398
406
|
var _a, _b;
|
|
399
407
|
if (!this._spec.getCurrentWorld)
|
|
400
|
-
return;
|
|
408
|
+
return undefined;
|
|
401
409
|
const [origin, next] = await this.getWorlds();
|
|
402
410
|
const currentWorld = await ((_b = (_a = this._spec).getCurrentWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
403
411
|
const result = {
|
|
@@ -412,9 +420,9 @@ class Driver {
|
|
|
412
420
|
}
|
|
413
421
|
// end world
|
|
414
422
|
async getSessionMetadata() {
|
|
415
|
-
var _a;
|
|
423
|
+
var _a, _b;
|
|
416
424
|
if (this.isECClient)
|
|
417
|
-
return await ((_a = this._spec) === null ||
|
|
425
|
+
return await ((_b = (_a = this._spec).getSessionMetadata) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
418
426
|
}
|
|
419
427
|
async refreshContexts() {
|
|
420
428
|
if (this.isNative)
|
|
@@ -448,7 +456,10 @@ class Driver {
|
|
|
448
456
|
}
|
|
449
457
|
async function getChildContextsInfo(context) {
|
|
450
458
|
const framesInfo = await spec.executeScript(context, snippets.getChildFramesInfo);
|
|
451
|
-
return framesInfo.map(([contextElement, isCORS]) => ({
|
|
459
|
+
return framesInfo.map(([contextElement, isCORS]) => ({
|
|
460
|
+
contextElement,
|
|
461
|
+
isCORS,
|
|
462
|
+
}));
|
|
452
463
|
}
|
|
453
464
|
async function isEqualElements(context, element1, element2) {
|
|
454
465
|
return spec.executeScript(context, snippets.isEqualElements, [element1, element2]).catch(() => false);
|
|
@@ -469,6 +480,7 @@ class Driver {
|
|
|
469
480
|
if (isWantedContext)
|
|
470
481
|
return childContextInfo.contextElement;
|
|
471
482
|
}
|
|
483
|
+
return null;
|
|
472
484
|
}
|
|
473
485
|
async function findContextPath(context, contextInfo, contextPath = []) {
|
|
474
486
|
const contentDocument = await spec.findElement(context, transformSelector('html'));
|
|
@@ -490,8 +502,7 @@ class Driver {
|
|
|
490
502
|
}
|
|
491
503
|
async switchTo(context) {
|
|
492
504
|
if (await this.currentContext.equals(context)) {
|
|
493
|
-
this._currentContext = context;
|
|
494
|
-
return;
|
|
505
|
+
return (this._currentContext = context);
|
|
495
506
|
}
|
|
496
507
|
const currentPath = this.currentContext.path;
|
|
497
508
|
const requiredPath = context.path;
|
|
@@ -585,10 +596,14 @@ class Driver {
|
|
|
585
596
|
if (this.isAndroid) {
|
|
586
597
|
normalizedRegion = utils.geometry.scale(normalizedRegion, 1 / this.pixelRatio);
|
|
587
598
|
}
|
|
588
|
-
if (this.isIOS &&
|
|
599
|
+
if (this.isIOS &&
|
|
600
|
+
this._driverInfo.safeArea &&
|
|
601
|
+
utils.geometry.isIntersected(normalizedRegion, this._driverInfo.safeArea)) {
|
|
589
602
|
normalizedRegion = utils.geometry.intersect(normalizedRegion, this._driverInfo.safeArea);
|
|
590
603
|
}
|
|
591
|
-
|
|
604
|
+
if (this._driverInfo.viewportLocation) {
|
|
605
|
+
normalizedRegion = utils.geometry.offsetNegative(normalizedRegion, this._driverInfo.viewportLocation);
|
|
606
|
+
}
|
|
592
607
|
if (normalizedRegion.y < 0) {
|
|
593
608
|
normalizedRegion.height += normalizedRegion.y;
|
|
594
609
|
normalizedRegion.y = 0;
|
|
@@ -605,6 +620,9 @@ class Driver {
|
|
|
605
620
|
async elements(selector) {
|
|
606
621
|
return this.currentContext.elements(selector);
|
|
607
622
|
}
|
|
623
|
+
async waitFor(selector, options) {
|
|
624
|
+
return this.currentContext.waitFor(selector, options);
|
|
625
|
+
}
|
|
608
626
|
async execute(script, arg) {
|
|
609
627
|
return this.currentContext.execute(script, arg);
|
|
610
628
|
}
|
|
@@ -692,7 +710,7 @@ class Driver {
|
|
|
692
710
|
async getDisplaySize() {
|
|
693
711
|
var _a, _b;
|
|
694
712
|
if (this.isWeb && !this.isMobile)
|
|
695
|
-
return;
|
|
713
|
+
return undefined;
|
|
696
714
|
if ((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.displaySize) {
|
|
697
715
|
this._logger.log('Extracting display size from native driver using cached value');
|
|
698
716
|
return this._driverInfo.displaySize;
|
|
@@ -707,8 +725,7 @@ class Driver {
|
|
|
707
725
|
}
|
|
708
726
|
async getOrientation() {
|
|
709
727
|
if (this.isWeb && !this.isMobile)
|
|
710
|
-
return;
|
|
711
|
-
let orientation;
|
|
728
|
+
return undefined;
|
|
712
729
|
if (this.isAndroid) {
|
|
713
730
|
this._logger.log('Extracting device orientation using adb command on android');
|
|
714
731
|
const rotation = await this.execute('mobile:shell', {
|
|
@@ -716,65 +733,73 @@ class Driver {
|
|
|
716
733
|
})
|
|
717
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); })
|
|
718
735
|
.catch(() => null);
|
|
719
|
-
if (rotation
|
|
720
|
-
orientation =
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
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
|
+
}
|
|
731
749
|
}
|
|
750
|
+
this._logger.log('Extracting device orientation');
|
|
751
|
+
const orientation = await this._spec.getOrientation(this.target);
|
|
732
752
|
this._logger.log('Extracted device orientation:', orientation);
|
|
733
753
|
return orientation;
|
|
734
754
|
}
|
|
735
755
|
async setOrientation(orientation) {
|
|
736
756
|
if (this.isWeb && !this.isMobile)
|
|
737
|
-
return;
|
|
757
|
+
return undefined;
|
|
738
758
|
this._logger.log('Set device orientation:', orientation);
|
|
739
759
|
await this._spec.setOrientation(this.target, orientation);
|
|
740
760
|
}
|
|
741
761
|
async getCookies() {
|
|
742
|
-
var _a, _b, _c;
|
|
743
|
-
|
|
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))
|
|
744
765
|
return [];
|
|
745
766
|
try {
|
|
746
|
-
return (
|
|
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 : [];
|
|
747
768
|
}
|
|
748
769
|
catch (error) {
|
|
770
|
+
(_e = (_f = this._driverInfo).features) !== null && _e !== void 0 ? _e : (_f.features = {});
|
|
749
771
|
this._driverInfo.features.allCookies = false;
|
|
750
772
|
throw error;
|
|
751
773
|
}
|
|
752
774
|
}
|
|
753
775
|
async getTitle() {
|
|
754
776
|
if (this.isNative)
|
|
755
|
-
return
|
|
777
|
+
return undefined;
|
|
756
778
|
const title = await this._spec.getTitle(this.target);
|
|
757
779
|
this._logger.log('Extracted title:', title);
|
|
758
780
|
return title;
|
|
759
781
|
}
|
|
760
782
|
async getUrl() {
|
|
761
783
|
if (this.isNative)
|
|
762
|
-
return
|
|
784
|
+
return undefined;
|
|
763
785
|
const url = await this._spec.getUrl(this.target);
|
|
764
786
|
this._logger.log('Extracted url:', url);
|
|
765
787
|
return url;
|
|
766
788
|
}
|
|
767
789
|
async visit(url) {
|
|
768
|
-
|
|
790
|
+
var _a, _b;
|
|
791
|
+
await ((_b = (_a = this._spec).visit) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, url));
|
|
769
792
|
}
|
|
770
793
|
}
|
|
771
794
|
exports.Driver = Driver;
|
|
772
795
|
function isDriver(driver, spec) {
|
|
773
|
-
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));
|
|
774
797
|
}
|
|
775
798
|
exports.isDriver = isDriver;
|
|
776
799
|
async function makeDriver(options) {
|
|
777
|
-
const driver =
|
|
800
|
+
const driver = options.driver instanceof Driver
|
|
801
|
+
? options.driver
|
|
802
|
+
: new Driver(options);
|
|
778
803
|
await driver.init();
|
|
779
804
|
await driver.refreshContexts();
|
|
780
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
|
-
|
|
38
|
-
|
|
39
|
-
if (options
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
606
|
-
|
|
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 =
|
|
626
|
-
this._state.transforms =
|
|
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;
|
package/dist/fake/spec-driver.js
CHANGED
|
@@ -55,6 +55,7 @@ function untransformSelector(selector) {
|
|
|
55
55
|
else if (utils.types.has(selector, ['selector'])) {
|
|
56
56
|
return selector;
|
|
57
57
|
}
|
|
58
|
+
return null;
|
|
58
59
|
}
|
|
59
60
|
exports.untransformSelector = untransformSelector;
|
|
60
61
|
function extractSelector(element) {
|
|
@@ -116,14 +117,14 @@ async function getOrientation(_driver) {
|
|
|
116
117
|
}
|
|
117
118
|
exports.getOrientation = getOrientation;
|
|
118
119
|
async function getUrl(driver) {
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
120
|
+
if (driver._isNative)
|
|
121
|
+
return '';
|
|
121
122
|
return driver.getUrl();
|
|
122
123
|
}
|
|
123
124
|
exports.getUrl = getUrl;
|
|
124
125
|
async function getTitle(driver) {
|
|
125
|
-
if (
|
|
126
|
-
return
|
|
126
|
+
if (driver._isNative)
|
|
127
|
+
return '';
|
|
127
128
|
return driver.getTitle();
|
|
128
129
|
}
|
|
129
130
|
exports.getTitle = getTitle;
|