@applitools/driver 1.11.32 → 1.11.34
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 +80 -44
- package/dist/fake/spec-driver.js +6 -1
- package/package.json +1 -1
- package/types/driver.d.ts +5 -10
- package/types/fake/spec-driver.d.ts +2 -1
package/dist/driver.js
CHANGED
|
@@ -39,6 +39,7 @@ class Driver {
|
|
|
39
39
|
constructor(options) {
|
|
40
40
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
41
41
|
this._driverInfo = {};
|
|
42
|
+
this._state = {};
|
|
42
43
|
this._customConfig = {};
|
|
43
44
|
this._customConfig = (_a = options.customConfig) !== null && _a !== void 0 ? _a : {};
|
|
44
45
|
this._spec = options.spec;
|
|
@@ -182,7 +183,7 @@ class Driver {
|
|
|
182
183
|
await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
183
184
|
const capabilities = await ((_d = (_c = this._spec).getCapabilities) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
|
|
184
185
|
this._logger.log('Driver capabilities', capabilities);
|
|
185
|
-
const capabilitiesInfo = capabilities
|
|
186
|
+
const capabilitiesInfo = capabilities && (0, capabilities_1.parseCapabilities)(capabilities);
|
|
186
187
|
const driverInfo = await ((_f = (_e = this._spec).getDriverInfo) === null || _f === void 0 ? void 0 : _f.call(_e, this.target));
|
|
187
188
|
this._driverInfo = { ...capabilitiesInfo, ...driverInfo };
|
|
188
189
|
(_g = (_19 = this._driverInfo).remoteHostname) !== null && _g !== void 0 ? _g : (_19.remoteHostname = (_k = (_j = (_h = this._spec).extractHostName) === null || _j === void 0 ? void 0 : _j.call(_h, this.target)) !== null && _k !== void 0 ? _k : undefined);
|
|
@@ -190,7 +191,10 @@ class Driver {
|
|
|
190
191
|
this._driverInfo.orientation =
|
|
191
192
|
(_l = (await this.getOrientation().catch(() => undefined))) !== null && _l !== void 0 ? _l : this._driverInfo.orientation;
|
|
192
193
|
const world = await this.getCurrentWorld();
|
|
193
|
-
|
|
194
|
+
if (world) {
|
|
195
|
+
const [home] = (await this.getWorlds());
|
|
196
|
+
this._driverInfo.isWebView = world !== home;
|
|
197
|
+
}
|
|
194
198
|
}
|
|
195
199
|
if (this.isWeb) {
|
|
196
200
|
const browserInfo = await this.currentContext.executePoll(snippets.getBrowserInfo);
|
|
@@ -335,6 +339,34 @@ class Driver {
|
|
|
335
339
|
this._logger.log(`Returning helper for of type ${(_c = (_b = this._helper) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : null}`);
|
|
336
340
|
return this._helper;
|
|
337
341
|
}
|
|
342
|
+
async extractBrokerUrl() {
|
|
343
|
+
if (this._state.brokerUrl)
|
|
344
|
+
return this._state.brokerUrl;
|
|
345
|
+
if (!this.isNative)
|
|
346
|
+
return null;
|
|
347
|
+
this._logger.log('Broker url extraction is started');
|
|
348
|
+
const element = await this.element({ type: 'accessibility id', selector: 'Applitools_View' });
|
|
349
|
+
if (!element)
|
|
350
|
+
return null;
|
|
351
|
+
try {
|
|
352
|
+
let result;
|
|
353
|
+
do {
|
|
354
|
+
result = JSON.parse(await element.getText());
|
|
355
|
+
if (result.nextPath) {
|
|
356
|
+
this._logger.log('Broker url was extraction finished successfully with value', result.nextPath);
|
|
357
|
+
this._state.brokerUrl = result.nextPath;
|
|
358
|
+
return this._state.brokerUrl;
|
|
359
|
+
}
|
|
360
|
+
await utils.general.sleep(1000);
|
|
361
|
+
} while (!result.error);
|
|
362
|
+
this._logger.error('Broker url extraction has failed with error', result.error);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
this._logger.error('Broker url extraction has failed with error', error);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
338
370
|
// begin world
|
|
339
371
|
//
|
|
340
372
|
// About the concept of a "World":
|
|
@@ -353,69 +385,73 @@ class Driver {
|
|
|
353
385
|
// - the native app world can be switched to (with the `goHome` option)
|
|
354
386
|
async switchWorld(options) {
|
|
355
387
|
var _a, _b;
|
|
356
|
-
if ((options === null || options === void 0 ? void 0 : options.restoreState) && !this.
|
|
388
|
+
if ((options === null || options === void 0 ? void 0 : options.restoreState) && !this._state.world)
|
|
357
389
|
return;
|
|
358
390
|
if (!this._spec.getCurrentWorld || !this._spec.switchWorld) {
|
|
359
391
|
this._logger.warn('world switching not implemented in the spec driver, skipping');
|
|
360
392
|
return;
|
|
361
393
|
}
|
|
362
394
|
this._logger.log('switchWorld called with', options ? options : 'no options');
|
|
363
|
-
const
|
|
364
|
-
if (!this.
|
|
365
|
-
this._logger.log('storing current world id for future restoration',
|
|
366
|
-
this.
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
395
|
+
const current = (await this.getCurrentWorld());
|
|
396
|
+
if (!this._state.world) {
|
|
397
|
+
this._logger.log('storing current world id for future restoration', current);
|
|
398
|
+
this._state.world = current;
|
|
399
|
+
}
|
|
400
|
+
let world;
|
|
401
|
+
if (options === null || options === void 0 ? void 0 : options.id)
|
|
402
|
+
world = options.id;
|
|
403
|
+
else if (options === null || options === void 0 ? void 0 : options.restoreState)
|
|
404
|
+
world = this._state.world;
|
|
405
|
+
else {
|
|
406
|
+
const [home, next] = (await this.getWorlds());
|
|
407
|
+
if (options === null || options === void 0 ? void 0 : options.goHome)
|
|
408
|
+
world = home;
|
|
409
|
+
else
|
|
410
|
+
world = next;
|
|
411
|
+
}
|
|
412
|
+
this._logger.log('switching world with', world);
|
|
376
413
|
try {
|
|
377
|
-
await ((_b = (_a = this._spec).switchWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target,
|
|
414
|
+
await ((_b = (_a = this._spec).switchWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, world));
|
|
378
415
|
await this.init();
|
|
379
416
|
}
|
|
380
417
|
catch (error) {
|
|
381
418
|
throw new Error(`Unable to switch worlds, the original error was: ${error.message}`);
|
|
382
419
|
}
|
|
383
420
|
}
|
|
384
|
-
async getWorlds(
|
|
385
|
-
var _a, _b;
|
|
421
|
+
async getWorlds() {
|
|
386
422
|
if (!this._spec.getWorlds)
|
|
387
|
-
return
|
|
388
|
-
this._logger.log('
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
423
|
+
return null;
|
|
424
|
+
this._logger.log('Extracting worlds');
|
|
425
|
+
try {
|
|
426
|
+
let worlds = [];
|
|
427
|
+
for (let attempt = 0; worlds.length <= 1 && attempt < 5; ++attempt) {
|
|
428
|
+
if (attempt > 0)
|
|
429
|
+
await utils.general.sleep(500);
|
|
430
|
+
worlds = await this._spec.getWorlds(this.target);
|
|
395
431
|
}
|
|
396
|
-
this._logger.log(
|
|
397
|
-
|
|
432
|
+
this._logger.log('Worlds were extracted', worlds);
|
|
433
|
+
return worlds;
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
this._logger.warn('Worlds were not extracted due to the error', error);
|
|
437
|
+
return null;
|
|
398
438
|
}
|
|
399
|
-
this._logger.log(`worlds found - ${worlds}`);
|
|
400
|
-
return worlds;
|
|
401
439
|
}
|
|
402
440
|
async getCurrentWorld() {
|
|
403
441
|
var _a, _b;
|
|
404
442
|
if (!this._spec.getCurrentWorld)
|
|
405
|
-
return
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
return result;
|
|
443
|
+
return null;
|
|
444
|
+
try {
|
|
445
|
+
this._logger.log('Extracting current world');
|
|
446
|
+
const current = await ((_b = (_a = this._spec).getCurrentWorld) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
|
|
447
|
+
this._logger.log('Current world was extracted', current);
|
|
448
|
+
return current;
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
this._logger.warn('Current world was not extracted due to the error', error);
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
417
454
|
}
|
|
418
|
-
// end world
|
|
419
455
|
async getSessionMetadata() {
|
|
420
456
|
var _a, _b;
|
|
421
457
|
if (this.isECClient)
|
package/dist/fake/spec-driver.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.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.untransformSelector = exports.transformSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
|
|
26
|
+
exports.visit = exports.getTitle = exports.getUrl = exports.getOrientation = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.getElementText = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.extractSelector = exports.untransformSelector = exports.transformSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
|
|
27
27
|
const utils = __importStar(require("@applitools/utils"));
|
|
28
28
|
function isDriver(driver) {
|
|
29
29
|
return driver && driver.constructor.name === 'MockDriver';
|
|
@@ -84,6 +84,11 @@ async function findElements(driver, selector, parent) {
|
|
|
84
84
|
return driver.findElements(selector, parent);
|
|
85
85
|
}
|
|
86
86
|
exports.findElements = findElements;
|
|
87
|
+
async function getElementText(_driver, element) {
|
|
88
|
+
var _a;
|
|
89
|
+
return (_a = element.attrs) === null || _a === void 0 ? void 0 : _a.text;
|
|
90
|
+
}
|
|
91
|
+
exports.getElementText = getElementText;
|
|
87
92
|
async function mainContext(driver) {
|
|
88
93
|
return driver.switchToFrame(null);
|
|
89
94
|
}
|
package/package.json
CHANGED
package/types/driver.d.ts
CHANGED
|
@@ -21,10 +21,10 @@ export declare class Driver<T extends SpecType> {
|
|
|
21
21
|
private _mainContext;
|
|
22
22
|
private _currentContext;
|
|
23
23
|
private _driverInfo;
|
|
24
|
+
private _helper?;
|
|
25
|
+
private _state;
|
|
24
26
|
private _logger;
|
|
25
27
|
private _customConfig;
|
|
26
|
-
private _helper?;
|
|
27
|
-
private _previousWorld?;
|
|
28
28
|
protected readonly _spec: SpecDriver<T>;
|
|
29
29
|
constructor(options: DriverOptions<T>);
|
|
30
30
|
get target(): T['driver'];
|
|
@@ -65,19 +65,14 @@ export declare class Driver<T extends SpecType> {
|
|
|
65
65
|
updateCurrentContext(context: Context<T>): void;
|
|
66
66
|
init(): Promise<this>;
|
|
67
67
|
getHelper(): Promise<HelperAndroid<T> | HelperIOS<T> | null>;
|
|
68
|
+
extractBrokerUrl(): Promise<string | null>;
|
|
68
69
|
switchWorld(options?: {
|
|
69
70
|
id?: string;
|
|
70
71
|
restoreState?: boolean;
|
|
71
72
|
goHome?: boolean;
|
|
72
73
|
}): Promise<void>;
|
|
73
|
-
getWorlds(
|
|
74
|
-
getCurrentWorld(): Promise<
|
|
75
|
-
id: string;
|
|
76
|
-
home: string;
|
|
77
|
-
next?: string;
|
|
78
|
-
isNative: boolean;
|
|
79
|
-
isWebView: boolean;
|
|
80
|
-
}>;
|
|
74
|
+
getWorlds(): Promise<string[] | null>;
|
|
75
|
+
getCurrentWorld(): Promise<string | null>;
|
|
81
76
|
getSessionMetadata(): Promise<any>;
|
|
82
77
|
refreshContexts(): Promise<Context<T>>;
|
|
83
78
|
switchTo(context: Context<T>): Promise<Context<T>>;
|
|
@@ -22,8 +22,9 @@ export declare function extractSelector(element: Element): any;
|
|
|
22
22
|
export declare function isStaleElementError(): boolean;
|
|
23
23
|
export declare function isEqualElements(_driver: Driver, element1: Element, element2: Element): Promise<boolean>;
|
|
24
24
|
export declare function executeScript(driver: Driver, script: ((arg: any) => any) | string, arg: any): Promise<any>;
|
|
25
|
-
export declare function findElement(driver: Driver, selector: Selector, parent?: Element): Promise<Element>;
|
|
25
|
+
export declare function findElement(driver: Driver, selector: Selector, parent?: Element): Promise<Element | null>;
|
|
26
26
|
export declare function findElements(driver: Driver, selector: Selector, parent?: Element): Promise<Element[]>;
|
|
27
|
+
export declare function getElementText(_driver: Driver, element: Element): Promise<string>;
|
|
27
28
|
export declare function mainContext(driver: Driver): Promise<Driver>;
|
|
28
29
|
export declare function parentContext(driver: Driver): Promise<Driver>;
|
|
29
30
|
export declare function childContext(driver: Driver, element: Element): Promise<Driver>;
|