@applitools/driver 1.9.35 → 1.10.1
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 +87 -2
- package/package.json +3 -3
- package/types/driver.d.ts +9 -0
package/dist/driver.js
CHANGED
|
@@ -117,10 +117,14 @@ class Driver {
|
|
|
117
117
|
}
|
|
118
118
|
get isNative() {
|
|
119
119
|
var _a, _b;
|
|
120
|
-
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isNative) !== null && _b !== void 0 ? _b : false;
|
|
120
|
+
return (_b = (!this.isWebView && ((_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isNative))) !== null && _b !== void 0 ? _b : false;
|
|
121
|
+
}
|
|
122
|
+
get isWebView() {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isWebView) !== null && _b !== void 0 ? _b : false;
|
|
121
125
|
}
|
|
122
126
|
get isWeb() {
|
|
123
|
-
return !this.isNative;
|
|
127
|
+
return this.isWebView || !this.isNative;
|
|
124
128
|
}
|
|
125
129
|
get isMobile() {
|
|
126
130
|
var _a, _b;
|
|
@@ -156,6 +160,8 @@ class Driver {
|
|
|
156
160
|
if (this.isMobile) {
|
|
157
161
|
this._driverInfo.orientation =
|
|
158
162
|
(_g = (await this.getOrientation().catch(() => undefined))) !== null && _g !== void 0 ? _g : this._driverInfo.orientation;
|
|
163
|
+
const world = this.isMobile && (await this.getCurrentWorld());
|
|
164
|
+
this._driverInfo.isWebView = !!(world === null || world === void 0 ? void 0 : world.isWebView);
|
|
159
165
|
}
|
|
160
166
|
if (this.isWeb) {
|
|
161
167
|
(_h = (_6 = this._driverInfo).pixelRatio) !== null && _h !== void 0 ? _h : (_6.pixelRatio = await this.execute(snippets.getPixelRatio));
|
|
@@ -271,6 +277,85 @@ class Driver {
|
|
|
271
277
|
this._logger.log('Combined driver info', this._driverInfo);
|
|
272
278
|
return this;
|
|
273
279
|
}
|
|
280
|
+
// begin world
|
|
281
|
+
//
|
|
282
|
+
// About the concept of a "World":
|
|
283
|
+
//
|
|
284
|
+
// Since "context" is an overloaded term from frames, we have decided to use
|
|
285
|
+
// the concept of a "world" when switching between mobile app contexts (e.g., native and webview(s))
|
|
286
|
+
//
|
|
287
|
+
// Notes:
|
|
288
|
+
// - two new functions need to be added to a spec driver for this to work (`getCurrentWorld` and `switchWorld`)
|
|
289
|
+
// - you can see a reference implementation of this in spec-driver-webdriverio
|
|
290
|
+
// - if a world id is provided it will be used for switching
|
|
291
|
+
// - if a world id is not provided, the first non-native world will be used
|
|
292
|
+
// (regardless of which world the driver is currently switched into)
|
|
293
|
+
// - before switching, the current world context is stored so it can switched back to later
|
|
294
|
+
// (with the `restoreState` option)
|
|
295
|
+
// - the native app world can be switched to (with the `goHome` option)
|
|
296
|
+
async switchWorld(options) {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
if ((options === null || options === void 0 ? void 0 : options.restoreState) && !this._previousWorld)
|
|
299
|
+
return;
|
|
300
|
+
if (!this._spec.getCurrentWorld || !this._spec.switchWorld) {
|
|
301
|
+
this._logger.warn('world switching not implemented in the spec driver, skipping');
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
this._logger.log('switchWorld called with', options ? options : 'no options');
|
|
305
|
+
const { id, home, next } = await this.getCurrentWorld();
|
|
306
|
+
if (!this._previousWorld) {
|
|
307
|
+
this._logger.log('storing current world id for future restoration', id);
|
|
308
|
+
this._previousWorld = id;
|
|
309
|
+
}
|
|
310
|
+
const providedTarget = (options === null || options === void 0 ? void 0 : options.restoreState)
|
|
311
|
+
? this._previousWorld
|
|
312
|
+
: (options === null || options === void 0 ? void 0 : options.goHome)
|
|
313
|
+
? home
|
|
314
|
+
: (options === null || options === void 0 ? void 0 : options.id)
|
|
315
|
+
? options.id
|
|
316
|
+
: next;
|
|
317
|
+
this._logger.log('switching world with', providedTarget ? providedTarget : 'no id');
|
|
318
|
+
try {
|
|
319
|
+
await ((_b = (_a = this._spec).switchWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, providedTarget));
|
|
320
|
+
await this.init();
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
throw new Error(`Unable to switch worlds, the original error was: ${error.message}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async getWorlds(attempt = 1) {
|
|
327
|
+
var _a, _b;
|
|
328
|
+
if (!this._spec.getWorlds)
|
|
329
|
+
return;
|
|
330
|
+
this._logger.log('attempting to find worlds');
|
|
331
|
+
await utils.general.sleep(500);
|
|
332
|
+
const worlds = await ((_b = (_a = this._spec).getWorlds) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
333
|
+
if (!worlds[1]) {
|
|
334
|
+
if (attempt > 5) {
|
|
335
|
+
this._logger.warn(`just one world found - ${worlds}. done looking.`);
|
|
336
|
+
return worlds;
|
|
337
|
+
}
|
|
338
|
+
this._logger.log(`just one world found, retrying to see if there are others (attempt #${attempt})`);
|
|
339
|
+
await this.getWorlds(attempt + 1);
|
|
340
|
+
}
|
|
341
|
+
this._logger.log(`worlds found - ${worlds}`);
|
|
342
|
+
return worlds;
|
|
343
|
+
}
|
|
344
|
+
async getCurrentWorld() {
|
|
345
|
+
var _a, _b;
|
|
346
|
+
if (!this._spec.getCurrentWorld)
|
|
347
|
+
return;
|
|
348
|
+
const [origin, next] = await this.getWorlds();
|
|
349
|
+
const currentWorld = await ((_b = (_a = this._spec).getCurrentWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
350
|
+
return {
|
|
351
|
+
id: currentWorld,
|
|
352
|
+
home: origin,
|
|
353
|
+
next,
|
|
354
|
+
isNative: currentWorld === origin,
|
|
355
|
+
isWebView: currentWorld !== origin,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
// end world
|
|
274
359
|
async refreshContexts() {
|
|
275
360
|
if (this.isNative)
|
|
276
361
|
return this.currentContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/driver",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Applitools universal framework wrapper",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"applitools",
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@applitools/logger": "1.1.
|
|
90
|
+
"@applitools/logger": "1.1.24",
|
|
91
91
|
"@applitools/snippets": "2.4.5",
|
|
92
|
-
"@applitools/types": "1.5.
|
|
92
|
+
"@applitools/types": "1.5.17",
|
|
93
93
|
"@applitools/utils": "1.3.12",
|
|
94
94
|
"semver": "7.3.7"
|
|
95
95
|
},
|
package/types/driver.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class Driver<TDriver, TContext, TElement, TSelector> {
|
|
|
19
19
|
private _logger;
|
|
20
20
|
private _customConfig;
|
|
21
21
|
private _helper?;
|
|
22
|
+
private _previousWorld;
|
|
22
23
|
protected readonly _spec: types.SpecDriver<TDriver, TContext, TElement, TSelector>;
|
|
23
24
|
constructor(options: DriverOptions<TDriver, TContext, TElement, TSelector>);
|
|
24
25
|
get target(): TDriver;
|
|
@@ -41,6 +42,7 @@ export declare class Driver<TDriver, TContext, TElement, TSelector> {
|
|
|
41
42
|
get statusBarSize(): number;
|
|
42
43
|
get navigationBarSize(): number;
|
|
43
44
|
get isNative(): boolean;
|
|
45
|
+
get isWebView(): boolean;
|
|
44
46
|
get isWeb(): boolean;
|
|
45
47
|
get isMobile(): boolean;
|
|
46
48
|
get isIOS(): boolean;
|
|
@@ -49,6 +51,13 @@ export declare class Driver<TDriver, TContext, TElement, TSelector> {
|
|
|
49
51
|
get isEdgeLegacy(): boolean;
|
|
50
52
|
updateCurrentContext(context: Context<TDriver, TContext, TElement, TSelector>): void;
|
|
51
53
|
init(): Promise<this>;
|
|
54
|
+
switchWorld(options?: {
|
|
55
|
+
id?: string;
|
|
56
|
+
restoreState?: boolean;
|
|
57
|
+
goHome?: boolean;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
getWorlds(attempt?: number): Promise<string[]>;
|
|
60
|
+
getCurrentWorld(): Promise<types.WorldInfo>;
|
|
52
61
|
refreshContexts(): Promise<Context<TDriver, TContext, TElement, TSelector>>;
|
|
53
62
|
switchTo(context: Context<TDriver, TContext, TElement, TSelector>): Promise<Context<TDriver, TContext, TElement, TSelector>>;
|
|
54
63
|
switchToMainContext(): Promise<Context<TDriver, TContext, TElement, TSelector>>;
|