@applitools/driver 1.11.37 → 1.11.38
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/capabilities.js +34 -27
- package/dist/context.js +15 -9
- package/dist/driver.js +394 -430
- package/dist/element.js +68 -44
- package/dist/fake/mock-driver.js +9 -12
- package/dist/fake/spec-driver.js +1 -1
- package/dist/user-agent.js +51 -12
- package/package.json +3 -3
- package/types/capabilities.d.ts +3 -4
- package/types/driver.d.ts +35 -51
- package/types/fake/mock-driver.d.ts +1 -1
- package/types/fake/spec-driver.d.ts +1 -1
- package/types/spec-driver.d.ts +3 -39
- package/types/types.d.ts +61 -0
- package/types/user-agent.d.ts +2 -12
- package/dist/user-agent-data.js +0 -33
- package/types/user-agent-data.d.ts +0 -13
package/dist/element.js
CHANGED
|
@@ -88,7 +88,8 @@ class Element {
|
|
|
88
88
|
if (this.isRef)
|
|
89
89
|
return false;
|
|
90
90
|
element = element instanceof Element ? element.target : element;
|
|
91
|
-
|
|
91
|
+
const environment = await this.driver.getEnvironment();
|
|
92
|
+
if (environment.isWeb) {
|
|
92
93
|
return this._spec
|
|
93
94
|
.executeScript(this.context.target, snippets.isEqualElements, [this.target, element])
|
|
94
95
|
.catch(() => false);
|
|
@@ -102,7 +103,8 @@ class Element {
|
|
|
102
103
|
var _a, _b;
|
|
103
104
|
var _c;
|
|
104
105
|
innerElement = innerElement instanceof Element ? innerElement.target : innerElement;
|
|
105
|
-
|
|
106
|
+
const environment = await this.driver.getEnvironment();
|
|
107
|
+
if (environment.isWeb) {
|
|
106
108
|
this._logger.log('Checking if web element with selector', this.selector, 'contains element', innerElement);
|
|
107
109
|
return false; // TODO implement a snipped for web
|
|
108
110
|
}
|
|
@@ -140,7 +142,8 @@ class Element {
|
|
|
140
142
|
}
|
|
141
143
|
async getRegion() {
|
|
142
144
|
const region = await this.withRefresh(async () => {
|
|
143
|
-
|
|
145
|
+
const environment = await this.driver.getEnvironment();
|
|
146
|
+
if (environment.isWeb) {
|
|
144
147
|
this._logger.log('Extracting region of web element with selector', this.selector);
|
|
145
148
|
return this.context.execute(snippets.getElementRect, [this, false]);
|
|
146
149
|
}
|
|
@@ -161,7 +164,8 @@ class Element {
|
|
|
161
164
|
}
|
|
162
165
|
async getClientRegion() {
|
|
163
166
|
const region = await this.withRefresh(async () => {
|
|
164
|
-
|
|
167
|
+
const environment = await this.driver.getEnvironment();
|
|
168
|
+
if (environment.isWeb) {
|
|
165
169
|
this._logger.log('Extracting region of web element with selector', this.selector);
|
|
166
170
|
return this.context.execute(snippets.getElementRect, [this, true]);
|
|
167
171
|
}
|
|
@@ -174,13 +178,14 @@ class Element {
|
|
|
174
178
|
}
|
|
175
179
|
async getContentRegion(options = {}) {
|
|
176
180
|
var _a, _b;
|
|
177
|
-
|
|
181
|
+
const environment = await this.driver.getEnvironment();
|
|
182
|
+
if (!environment.isNative)
|
|
178
183
|
return null;
|
|
179
184
|
this._logger.log('Extracting content region of native element with selector', this.selector);
|
|
180
185
|
const helper = await this.driver.getHelper();
|
|
181
186
|
let contentRegion = await (helper === null || helper === void 0 ? void 0 : helper.getContentRegion(this, options));
|
|
182
187
|
this._logger.log('Extracted content region using helper library', contentRegion);
|
|
183
|
-
if (!contentRegion || !
|
|
188
|
+
if (!contentRegion || !environment.isAndroid) {
|
|
184
189
|
let attrContentRegion = null;
|
|
185
190
|
try {
|
|
186
191
|
const size = JSON.parse(await this.getAttribute('contentSize'));
|
|
@@ -188,7 +193,7 @@ class Element {
|
|
|
188
193
|
x: size.left,
|
|
189
194
|
y: size.top,
|
|
190
195
|
width: size.width,
|
|
191
|
-
height:
|
|
196
|
+
height: environment.isIOS
|
|
192
197
|
? Math.max(size.height, size.scrollableOffset)
|
|
193
198
|
: size.height + size.scrollableOffset,
|
|
194
199
|
};
|
|
@@ -198,7 +203,7 @@ class Element {
|
|
|
198
203
|
}
|
|
199
204
|
this._logger.log('Extracted content region using attribute', attrContentRegion);
|
|
200
205
|
// ios workaround
|
|
201
|
-
if (!attrContentRegion &&
|
|
206
|
+
if (!attrContentRegion && environment.isIOS) {
|
|
202
207
|
try {
|
|
203
208
|
const type = await this.getAttribute('type');
|
|
204
209
|
if (type === 'XCUIElementTypeScrollView') {
|
|
@@ -236,7 +241,8 @@ class Element {
|
|
|
236
241
|
if (this._state.contentSize)
|
|
237
242
|
return this._state.contentSize;
|
|
238
243
|
const size = await this.withRefresh(async () => {
|
|
239
|
-
|
|
244
|
+
const environment = await this.driver.getEnvironment();
|
|
245
|
+
if (environment.isWeb) {
|
|
240
246
|
this._logger.log('Extracting content size of web element with selector', this.selector);
|
|
241
247
|
return this.context.execute(snippets.getElementContentSize, [this]);
|
|
242
248
|
}
|
|
@@ -245,11 +251,12 @@ class Element {
|
|
|
245
251
|
try {
|
|
246
252
|
const contentRegion = await this.getContentRegion(options);
|
|
247
253
|
this._state.contentSize = utils.geometry.size(contentRegion);
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
const viewport = await this.driver.getViewport();
|
|
255
|
+
if (environment.isAndroid) {
|
|
256
|
+
this._state.contentSize = utils.geometry.scale(this._state.contentSize, 1 / viewport.pixelRatio);
|
|
250
257
|
}
|
|
251
|
-
if (contentRegion.y <
|
|
252
|
-
this._state.contentSize.height -=
|
|
258
|
+
if (contentRegion.y < viewport.statusBarSize) {
|
|
259
|
+
this._state.contentSize.height -= viewport.statusBarSize - contentRegion.y;
|
|
253
260
|
}
|
|
254
261
|
return this._state.contentSize;
|
|
255
262
|
}
|
|
@@ -266,7 +273,8 @@ class Element {
|
|
|
266
273
|
async isPager() {
|
|
267
274
|
this._logger.log('Check if element with selector', this.selector, 'is scrollable by pages');
|
|
268
275
|
const isPager = await this.withRefresh(async () => {
|
|
269
|
-
|
|
276
|
+
const environment = await this.driver.getEnvironment();
|
|
277
|
+
if (environment.isAndroid) {
|
|
270
278
|
const className = await this.getAttribute('className');
|
|
271
279
|
return ['androidx.viewpager.widget.ViewPager'].includes(className);
|
|
272
280
|
}
|
|
@@ -280,14 +288,15 @@ class Element {
|
|
|
280
288
|
async isScrollable() {
|
|
281
289
|
this._logger.log('Check if element with selector', this.selector, 'is scrollable');
|
|
282
290
|
const isScrollable = await this.withRefresh(async () => {
|
|
283
|
-
|
|
291
|
+
const environment = await this.driver.getEnvironment();
|
|
292
|
+
if (environment.isWeb) {
|
|
284
293
|
return this.context.execute(snippets.isElementScrollable, [this]);
|
|
285
294
|
}
|
|
286
|
-
else if (
|
|
295
|
+
else if (environment.isAndroid) {
|
|
287
296
|
const data = JSON.parse(await this.getAttribute('scrollable'));
|
|
288
297
|
return Boolean(data) || false;
|
|
289
298
|
}
|
|
290
|
-
else if (
|
|
299
|
+
else if (environment.isIOS) {
|
|
291
300
|
const type = await this.getAttribute('type');
|
|
292
301
|
return ['XCUIElementTypeScrollView', 'XCUIElementTypeTable', 'XCUIElementTypeCollectionView'].includes(type);
|
|
293
302
|
}
|
|
@@ -298,7 +307,8 @@ class Element {
|
|
|
298
307
|
async isRoot() {
|
|
299
308
|
// TODO replace with snippet
|
|
300
309
|
return this.withRefresh(async () => {
|
|
301
|
-
|
|
310
|
+
const environment = await this.driver.getEnvironment();
|
|
311
|
+
if (environment.isWeb) {
|
|
302
312
|
const rootElement = await this.context.element({ type: 'css', selector: 'html' });
|
|
303
313
|
return this.equals(rootElement);
|
|
304
314
|
}
|
|
@@ -308,7 +318,8 @@ class Element {
|
|
|
308
318
|
});
|
|
309
319
|
}
|
|
310
320
|
async getShadowRoot() {
|
|
311
|
-
|
|
321
|
+
const environment = await this.driver.getEnvironment();
|
|
322
|
+
if (!environment.isWeb)
|
|
312
323
|
return null;
|
|
313
324
|
return this._spec.executeScript(this.context.target, snippets.getShadowRoot, [this.target]);
|
|
314
325
|
}
|
|
@@ -316,11 +327,12 @@ class Element {
|
|
|
316
327
|
var _a;
|
|
317
328
|
var _b;
|
|
318
329
|
if (this._state.touchPadding == null) {
|
|
319
|
-
|
|
330
|
+
const environment = await this.driver.getEnvironment();
|
|
331
|
+
if (environment.isWeb)
|
|
320
332
|
this._state.touchPadding = 0;
|
|
321
|
-
else if (
|
|
333
|
+
else if (environment.isIOS)
|
|
322
334
|
this._state.touchPadding = 10;
|
|
323
|
-
else if (
|
|
335
|
+
else if (environment.isAndroid) {
|
|
324
336
|
const helper = await this.driver.getHelper();
|
|
325
337
|
if ((helper === null || helper === void 0 ? void 0 : helper.name) === 'android') {
|
|
326
338
|
this._state.touchPadding = await helper.getTouchPadding();
|
|
@@ -342,7 +354,8 @@ class Element {
|
|
|
342
354
|
}
|
|
343
355
|
async getText() {
|
|
344
356
|
const text = await this.withRefresh(async () => {
|
|
345
|
-
|
|
357
|
+
const environment = await this.driver.getEnvironment();
|
|
358
|
+
if (environment.isWeb) {
|
|
346
359
|
return '';
|
|
347
360
|
}
|
|
348
361
|
else {
|
|
@@ -364,7 +377,8 @@ class Element {
|
|
|
364
377
|
const value = await this.withRefresh(async () => {
|
|
365
378
|
var _a;
|
|
366
379
|
var _b;
|
|
367
|
-
|
|
380
|
+
const environment = await this.driver.getEnvironment();
|
|
381
|
+
if (environment.isWeb) {
|
|
368
382
|
const properties = await this.context.execute(snippets.getElementProperties, [this, [name]]);
|
|
369
383
|
return properties[name];
|
|
370
384
|
}
|
|
@@ -380,7 +394,7 @@ class Element {
|
|
|
380
394
|
throw err;
|
|
381
395
|
}
|
|
382
396
|
finally {
|
|
383
|
-
if (
|
|
397
|
+
if (environment.isAndroid && name === 'contentSize') {
|
|
384
398
|
// android has a bug when after extracting 'contentSize' attribute the element is being scrolled by undetermined number of pixels
|
|
385
399
|
this._logger.log('Stabilizing android scroll offset');
|
|
386
400
|
const originalScrollOffset = await this.getScrollOffset();
|
|
@@ -394,7 +408,8 @@ class Element {
|
|
|
394
408
|
return value;
|
|
395
409
|
}
|
|
396
410
|
async setAttribute(name, value) {
|
|
397
|
-
|
|
411
|
+
const environment = await this.driver.getEnvironment();
|
|
412
|
+
if (environment.isWeb) {
|
|
398
413
|
await this.context.execute(snippets.setElementAttributes, [this, { [name]: value }]);
|
|
399
414
|
}
|
|
400
415
|
}
|
|
@@ -402,10 +417,11 @@ class Element {
|
|
|
402
417
|
return this.withRefresh(async () => {
|
|
403
418
|
this._logger.log(`Scrolling to offset (${offset.x}, ${offset.y}) element with selector`, this.selector);
|
|
404
419
|
offset = utils.geometry.round({ x: Math.max(offset.x, 0), y: Math.max(offset.y, 0) });
|
|
405
|
-
|
|
420
|
+
const environment = await this.driver.getEnvironment();
|
|
421
|
+
if (environment.isWeb) {
|
|
406
422
|
let actualOffset = await this.context.execute(snippets.scrollTo, [this, offset]);
|
|
407
423
|
// iOS has an issue when scroll offset is read immediately after it is been set it will always return the exact value that was set
|
|
408
|
-
if (
|
|
424
|
+
if (environment.isIOS)
|
|
409
425
|
actualOffset = await this.getScrollOffset();
|
|
410
426
|
return actualOffset;
|
|
411
427
|
}
|
|
@@ -413,7 +429,7 @@ class Element {
|
|
|
413
429
|
const currentScrollOffset = await this.getScrollOffset();
|
|
414
430
|
if (!(options === null || options === void 0 ? void 0 : options.force) && utils.geometry.equals(offset, currentScrollOffset))
|
|
415
431
|
return currentScrollOffset;
|
|
416
|
-
if (utils.geometry.equals(offset, { x: 0, y: 0 }) &&
|
|
432
|
+
if (utils.geometry.equals(offset, { x: 0, y: 0 }) && environment.isAndroid) {
|
|
417
433
|
const helper = await this.driver.getHelper();
|
|
418
434
|
if ((helper === null || helper === void 0 ? void 0 : helper.name) === 'android') {
|
|
419
435
|
await helper.scrollToTop(this);
|
|
@@ -432,9 +448,10 @@ class Element {
|
|
|
432
448
|
let remainingOffset = utils.geometry.equals(requiredOffset, { x: 0, y: 0 })
|
|
433
449
|
? { x: -maxOffset.x, y: -maxOffset.y } // if it has to be scrolled to the very beginning, then scroll maximum amount of pixels
|
|
434
450
|
: utils.geometry.offsetNegative(requiredOffset, currentScrollOffset);
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
451
|
+
if (environment.isAndroid) {
|
|
452
|
+
const viewport = await this.driver.getViewport();
|
|
453
|
+
remainingOffset = utils.geometry.round(utils.geometry.scale(remainingOffset, viewport.pixelRatio));
|
|
454
|
+
effectiveRegion = utils.geometry.round(utils.geometry.scale(effectiveRegion, viewport.pixelRatio));
|
|
438
455
|
}
|
|
439
456
|
const isPager = await this.isPager();
|
|
440
457
|
const touchPadding = await this.getTouchPadding();
|
|
@@ -463,7 +480,7 @@ class Element {
|
|
|
463
480
|
{ action: 'release' },
|
|
464
481
|
]);
|
|
465
482
|
}
|
|
466
|
-
else if (
|
|
483
|
+
else if (environment.isAndroid) {
|
|
467
484
|
actions.push([
|
|
468
485
|
// move through scrolling gap (actual scrolling will be triggered only after that)
|
|
469
486
|
{ action: 'press', y: yTrack, x: xStart - xGap },
|
|
@@ -477,7 +494,7 @@ class Element {
|
|
|
477
494
|
{ action: 'release' },
|
|
478
495
|
]);
|
|
479
496
|
}
|
|
480
|
-
else if (
|
|
497
|
+
else if (environment.isIOS) {
|
|
481
498
|
actions.push([
|
|
482
499
|
// move through scrolling gap (actual scrolling will be triggered only after that)
|
|
483
500
|
{ action: 'press', y: yTrack, x: xStart - xGap },
|
|
@@ -518,7 +535,7 @@ class Element {
|
|
|
518
535
|
{ action: 'release' },
|
|
519
536
|
]);
|
|
520
537
|
}
|
|
521
|
-
else if (
|
|
538
|
+
else if (environment.isAndroid) {
|
|
522
539
|
actions.push([
|
|
523
540
|
// move through scrolling gap (actual scrolling will be triggered only after that)
|
|
524
541
|
{ action: 'press', x: xTrack, y: yStart - yGap },
|
|
@@ -532,7 +549,7 @@ class Element {
|
|
|
532
549
|
{ action: 'release' },
|
|
533
550
|
]);
|
|
534
551
|
}
|
|
535
|
-
else if (
|
|
552
|
+
else if (environment.isIOS) {
|
|
536
553
|
actions.push([
|
|
537
554
|
// move through scrolling gap (actual scrolling will be triggered only after that)
|
|
538
555
|
{ action: 'press', x: xTrack, y: yStart - yGap },
|
|
@@ -551,7 +568,7 @@ class Element {
|
|
|
551
568
|
}
|
|
552
569
|
// ios actions should be executed one-by-one sequentially, otherwise the result isn't stable
|
|
553
570
|
// pages should be scrolled one-by-one as well
|
|
554
|
-
if (isPager ||
|
|
571
|
+
if (isPager || environment.isIOS) {
|
|
555
572
|
for (const action of actions) {
|
|
556
573
|
await this._spec.performAction(this.driver.target, action);
|
|
557
574
|
}
|
|
@@ -570,7 +587,8 @@ class Element {
|
|
|
570
587
|
}
|
|
571
588
|
async translateTo(offset) {
|
|
572
589
|
offset = { x: Math.round(offset.x), y: Math.round(offset.y) };
|
|
573
|
-
|
|
590
|
+
const environment = await this.driver.getEnvironment();
|
|
591
|
+
if (environment.isWeb) {
|
|
574
592
|
return this.withRefresh(async () => this.context.execute(snippets.translateTo, [this, offset]));
|
|
575
593
|
}
|
|
576
594
|
else {
|
|
@@ -579,7 +597,8 @@ class Element {
|
|
|
579
597
|
}
|
|
580
598
|
async getScrollOffset() {
|
|
581
599
|
var _a;
|
|
582
|
-
|
|
600
|
+
const environment = await this.driver.getEnvironment();
|
|
601
|
+
if (environment.isWeb) {
|
|
583
602
|
return this.withRefresh(() => this.context.execute(snippets.getElementScrollOffset, [this]));
|
|
584
603
|
}
|
|
585
604
|
else {
|
|
@@ -587,7 +606,8 @@ class Element {
|
|
|
587
606
|
}
|
|
588
607
|
}
|
|
589
608
|
async getTranslateOffset() {
|
|
590
|
-
|
|
609
|
+
const environment = await this.driver.getEnvironment();
|
|
610
|
+
if (environment.isWeb) {
|
|
591
611
|
return this.withRefresh(() => this.context.execute(snippets.getElementTranslateOffset, [this]));
|
|
592
612
|
}
|
|
593
613
|
else {
|
|
@@ -595,7 +615,8 @@ class Element {
|
|
|
595
615
|
}
|
|
596
616
|
}
|
|
597
617
|
async getInnerOffset() {
|
|
598
|
-
|
|
618
|
+
const environment = await this.driver.getEnvironment();
|
|
619
|
+
if (environment.isWeb) {
|
|
599
620
|
return this.withRefresh(() => this.context.execute(snippets.getElementInnerOffset, [this]));
|
|
600
621
|
}
|
|
601
622
|
else {
|
|
@@ -614,7 +635,8 @@ class Element {
|
|
|
614
635
|
}
|
|
615
636
|
async preserveState() {
|
|
616
637
|
const scrollOffset = await this.getScrollOffset();
|
|
617
|
-
const
|
|
638
|
+
const environment = await this.driver.getEnvironment();
|
|
639
|
+
const transforms = environment.isWeb
|
|
618
640
|
? await this.context.execute(snippets.getElementStyleProperties, [this, ['transform', '-webkit-transform']])
|
|
619
641
|
: null;
|
|
620
642
|
if (!utils.types.has(this._state, ['scrollOffset', 'transforms'])) {
|
|
@@ -634,7 +656,8 @@ class Element {
|
|
|
634
656
|
}
|
|
635
657
|
}
|
|
636
658
|
async hideScrollbars() {
|
|
637
|
-
|
|
659
|
+
const environment = await this.driver.getEnvironment();
|
|
660
|
+
if (environment.isNative)
|
|
638
661
|
return;
|
|
639
662
|
if (this._originalOverflow)
|
|
640
663
|
return;
|
|
@@ -644,7 +667,8 @@ class Element {
|
|
|
644
667
|
});
|
|
645
668
|
}
|
|
646
669
|
async restoreScrollbars() {
|
|
647
|
-
|
|
670
|
+
const environment = await this.driver.getEnvironment();
|
|
671
|
+
if (environment.isNative)
|
|
648
672
|
return;
|
|
649
673
|
if (!this._originalOverflow)
|
|
650
674
|
return;
|
package/dist/fake/mock-driver.js
CHANGED
|
@@ -120,17 +120,14 @@ class MockDriver {
|
|
|
120
120
|
this.mockScript(snippets.getShadowRoot, ([element]) => {
|
|
121
121
|
return element;
|
|
122
122
|
});
|
|
123
|
-
this.mockScript(snippets.
|
|
123
|
+
this.mockScript(snippets.getUserAgent, () => {
|
|
124
124
|
return JSON.stringify({
|
|
125
125
|
status: 'SUCCESS',
|
|
126
|
-
value:
|
|
127
|
-
userAgent: this._ua !== undefined ? this._ua : this.info.isMobile ? DEFAULT_MOBILE_UA : DEFAULT_DESKTOP_UA,
|
|
128
|
-
pixelRatio: 1,
|
|
129
|
-
},
|
|
126
|
+
value: this._ua !== undefined ? this._ua : this.environment.isMobile ? DEFAULT_MOBILE_UA : DEFAULT_DESKTOP_UA,
|
|
130
127
|
});
|
|
131
128
|
});
|
|
132
|
-
this.mockScript(snippets.
|
|
133
|
-
return { width: this._window.rect.width, height: this._window.rect.height };
|
|
129
|
+
this.mockScript(snippets.getViewport, () => {
|
|
130
|
+
return { viewportSize: { width: this._window.rect.width, height: this._window.rect.height }, pixelRation: 1 };
|
|
134
131
|
});
|
|
135
132
|
this.mockScript(snippets.getElementXpath, ([element]) => {
|
|
136
133
|
if (element.xpath)
|
|
@@ -254,7 +251,7 @@ class MockDriver {
|
|
|
254
251
|
return;
|
|
255
252
|
this[name] = method;
|
|
256
253
|
}
|
|
257
|
-
get
|
|
254
|
+
get environment() {
|
|
258
255
|
return {
|
|
259
256
|
isMobile: this._device ? Boolean(this._device.isMobile) : false,
|
|
260
257
|
isNative: this._device ? Boolean(this._device.isNative) : false,
|
|
@@ -266,7 +263,7 @@ class MockDriver {
|
|
|
266
263
|
};
|
|
267
264
|
}
|
|
268
265
|
async executeScript(script, args = []) {
|
|
269
|
-
if (this.
|
|
266
|
+
if (this.environment.isNative)
|
|
270
267
|
throw new Error("Native context doesn't support this method");
|
|
271
268
|
let result = this._scripts.get(String(script));
|
|
272
269
|
if (!result) {
|
|
@@ -327,17 +324,17 @@ class MockDriver {
|
|
|
327
324
|
Object.assign(this._window.rect, rect);
|
|
328
325
|
}
|
|
329
326
|
async getUrl() {
|
|
330
|
-
if (this.
|
|
327
|
+
if (this.environment.isNative)
|
|
331
328
|
throw new Error("Native context doesn't support this method");
|
|
332
329
|
return this._window.url;
|
|
333
330
|
}
|
|
334
331
|
async getTitle() {
|
|
335
|
-
if (this.
|
|
332
|
+
if (this.environment.isNative)
|
|
336
333
|
throw new Error("Native context doesn't support this method");
|
|
337
334
|
return this._window.title;
|
|
338
335
|
}
|
|
339
336
|
async visit(url) {
|
|
340
|
-
if (this.
|
|
337
|
+
if (this.environment.isNative)
|
|
341
338
|
throw new Error("Native context doesn't support this method");
|
|
342
339
|
this._window.url = url;
|
|
343
340
|
}
|
package/dist/fake/spec-driver.js
CHANGED
|
@@ -106,7 +106,7 @@ async function takeScreenshot(driver) {
|
|
|
106
106
|
}
|
|
107
107
|
exports.takeScreenshot = takeScreenshot;
|
|
108
108
|
async function getDriverInfo(driver) {
|
|
109
|
-
return driver.
|
|
109
|
+
return { environment: driver.environment };
|
|
110
110
|
}
|
|
111
111
|
exports.getDriverInfo = getDriverInfo;
|
|
112
112
|
async function getWindowSize(driver) {
|
package/dist/user-agent.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.extractUserAgentEnvironment = void 0;
|
|
27
27
|
const utils = __importStar(require("@applitools/utils"));
|
|
28
28
|
const MAJOR_MINOR = '(\\d+)(?:[_.](\\d+))?';
|
|
29
29
|
const PLATFORM_REGEXES = [
|
|
@@ -52,16 +52,35 @@ const BROWSER_REGEXPES = [
|
|
|
52
52
|
];
|
|
53
53
|
const HIDDEN_IE_REGEX = new RegExp(`(?:rv:${MAJOR_MINOR}\\) like Gecko)`);
|
|
54
54
|
const BROWSER_VERSION_REGEX = new RegExp(`(?:Version/${MAJOR_MINOR})`);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const WINDOWS_VERSIONS = {
|
|
56
|
+
'0.1.0': '7',
|
|
57
|
+
'0.2.0': '8',
|
|
58
|
+
'0.3.0': '8.1',
|
|
59
|
+
'10.0.0': '10',
|
|
60
|
+
'15.0.0': '11',
|
|
61
|
+
};
|
|
62
|
+
function extractUserAgentEnvironment(userAgent) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
let userAgentLegacy, userAgentObject;
|
|
65
|
+
if (utils.types.isString(userAgent)) {
|
|
66
|
+
userAgentLegacy = userAgent.trim();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
userAgentLegacy = userAgent.legacy.trim();
|
|
70
|
+
userAgentObject = userAgent;
|
|
71
|
+
}
|
|
72
|
+
const userAgentLegacyEnvironment = {
|
|
73
|
+
...extractUserAgentLegacyPlatform(userAgentLegacy),
|
|
74
|
+
...extractUserAgentLegacyBrowser(userAgentLegacy),
|
|
61
75
|
};
|
|
76
|
+
const userAgentEnvironment = userAgentObject && extractUserAgentObjectEnvironment(userAgentObject);
|
|
77
|
+
const environment = { ...userAgentLegacyEnvironment, ...userAgentEnvironment };
|
|
78
|
+
environment.browserName = (_a = userAgentLegacyEnvironment.browserName) !== null && _a !== void 0 ? _a : userAgentEnvironment === null || userAgentEnvironment === void 0 ? void 0 : userAgentEnvironment.browserName;
|
|
79
|
+
environment.browserVersion = (_b = userAgentLegacyEnvironment.browserVersion) !== null && _b !== void 0 ? _b : userAgentEnvironment === null || userAgentEnvironment === void 0 ? void 0 : userAgentEnvironment.browserVersion;
|
|
80
|
+
return environment;
|
|
62
81
|
}
|
|
63
|
-
exports.
|
|
64
|
-
function
|
|
82
|
+
exports.extractUserAgentEnvironment = extractUserAgentEnvironment;
|
|
83
|
+
function extractUserAgentLegacyPlatform(userAgent) {
|
|
65
84
|
const platformRegExp = PLATFORM_REGEXES.find(regexp => regexp.test(userAgent));
|
|
66
85
|
if (!platformRegExp)
|
|
67
86
|
return { platformName: 'Unknown' };
|
|
@@ -95,8 +114,7 @@ function parsePlatform(userAgent) {
|
|
|
95
114
|
return { platformName, platformVersion: platformMajorVersion };
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
|
-
|
|
99
|
-
function parseBrowser(userAgent) {
|
|
117
|
+
function extractUserAgentLegacyBrowser(userAgent) {
|
|
100
118
|
const browserRegExp = BROWSER_REGEXPES.find(regexp => regexp.test(userAgent));
|
|
101
119
|
if (!browserRegExp) {
|
|
102
120
|
if (HIDDEN_IE_REGEX.test(userAgent)) {
|
|
@@ -117,4 +135,25 @@ function parseBrowser(userAgent) {
|
|
|
117
135
|
}
|
|
118
136
|
return result;
|
|
119
137
|
}
|
|
120
|
-
|
|
138
|
+
function extractUserAgentObjectEnvironment(userAgent) {
|
|
139
|
+
var _a, _b, _c, _d;
|
|
140
|
+
const chromiumBrand = (_a = userAgent.brands) === null || _a === void 0 ? void 0 : _a.find(brand => /Chromium/i.test(brand.brand));
|
|
141
|
+
const browserBrand = (_c = (_b = userAgent.brands) === null || _b === void 0 ? void 0 : _b.find(brand => brand !== chromiumBrand && !/Not.?A.?Brand/i.test(brand.brand))) !== null && _c !== void 0 ? _c : chromiumBrand;
|
|
142
|
+
const environment = {
|
|
143
|
+
browserName: browserBrand === null || browserBrand === void 0 ? void 0 : browserBrand.brand,
|
|
144
|
+
browserVersion: browserBrand === null || browserBrand === void 0 ? void 0 : browserBrand.version,
|
|
145
|
+
platformName: userAgent.platform || undefined,
|
|
146
|
+
platformVersion: userAgent.platformVersion || undefined,
|
|
147
|
+
deviceName: userAgent.model || undefined,
|
|
148
|
+
isMobile: userAgent.mobile,
|
|
149
|
+
isChromium: Boolean(chromiumBrand),
|
|
150
|
+
};
|
|
151
|
+
if (environment.platformName === 'Windows') {
|
|
152
|
+
environment.platformVersion = WINDOWS_VERSIONS[environment.platformVersion];
|
|
153
|
+
}
|
|
154
|
+
else if (environment.platformName === 'macOS') {
|
|
155
|
+
environment.platformName = 'Mac OS X';
|
|
156
|
+
environment.platformVersion = (_d = environment.platformVersion) === null || _d === void 0 ? void 0 : _d.split(/[._]/, 2).join('.');
|
|
157
|
+
}
|
|
158
|
+
return environment;
|
|
159
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/driver",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.38",
|
|
4
4
|
"description": "Applitools universal framework wrapper",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"applitools",
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@applitools/logger": "1.1.48",
|
|
85
|
-
"@applitools/snippets": "2.4.
|
|
85
|
+
"@applitools/snippets": "2.4.18",
|
|
86
86
|
"@applitools/utils": "1.3.32",
|
|
87
87
|
"semver": "7.3.7"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@applitools/bongo": "^3.0.
|
|
90
|
+
"@applitools/bongo": "^3.0.3",
|
|
91
91
|
"@types/node": "^12.20.55"
|
|
92
92
|
},
|
|
93
93
|
"engines": {
|
package/types/capabilities.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export {};
|
|
1
|
+
import type { Capabilities, Environment, Viewport } from './types';
|
|
2
|
+
export declare function extractCapabilitiesEnvironment(capabilities: Capabilities): Partial<Environment>;
|
|
3
|
+
export declare function extractCapabilitiesViewport(capabilities: Capabilities): Partial<Viewport>;
|