@applitools/driver 1.11.33 → 1.11.35

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 CHANGED
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Context = void 0;
27
+ const selector_1 = require("./selector");
27
28
  const element_1 = require("./element");
28
29
  const utils = __importStar(require("@applitools/utils"));
29
30
  const specUtils = __importStar(require("./spec-utils"));
@@ -34,7 +35,7 @@ class Context {
34
35
  utils.types.isString(reference) ||
35
36
  reference instanceof element_1.Element ||
36
37
  this._spec.isElement(reference) ||
37
- specUtils.isSelector(this._spec, reference));
38
+ (0, selector_1.isSelector)(reference, this._spec));
38
39
  }
39
40
  constructor(options) {
40
41
  var _a, _b, _c, _d;
@@ -130,7 +131,7 @@ class Context {
130
131
  if (element)
131
132
  elements = [element];
132
133
  }
133
- if (specUtils.isObjectCommonSelector(this._spec, selector)) {
134
+ if ((0, selector_1.isObjectCommonSelector)(selector, this._spec)) {
134
135
  if (elements.length > 0) {
135
136
  if (selector.child) {
136
137
  elements = await elements.reduce((result, element) => {
@@ -178,14 +179,14 @@ class Context {
178
179
  }
179
180
  this._element = elements[this._reference];
180
181
  }
181
- else if (utils.types.isString(this._reference) || specUtils.isSelector(this._spec, this._reference)) {
182
+ else if (utils.types.isString(this._reference) || (0, selector_1.isSelector)(this._reference, this._spec)) {
182
183
  if (utils.types.isString(this._reference)) {
183
184
  this._logger.log('Getting context element by name or id', this._reference);
184
185
  this._element = await this.parent
185
186
  .element(`iframe[name="${this._reference}"], iframe#${this._reference}`)
186
187
  .catch(() => null);
187
188
  }
188
- if (!this._element && specUtils.isSelector(this._spec, this._reference)) {
189
+ if (!this._element && (0, selector_1.isSelector)(this._reference, this._spec)) {
189
190
  this._logger.log('Getting context element by selector', this._reference);
190
191
  this._element = await this.parent.element(this._reference);
191
192
  }
@@ -267,7 +268,7 @@ class Context {
267
268
  if (this._spec.isElement(elementOrSelector)) {
268
269
  return new element_1.Element({ spec: this._spec, context: this, element: elementOrSelector, logger: this._logger });
269
270
  }
270
- else if (!specUtils.isSelector(this._spec, elementOrSelector)) {
271
+ else if (!(0, selector_1.isSelector)(elementOrSelector, this._spec)) {
271
272
  throw new TypeError('Cannot find element using argument of unknown type!');
272
273
  }
273
274
  if (this.isRef) {
@@ -280,7 +281,7 @@ class Context {
280
281
  : null;
281
282
  }
282
283
  async elements(selectorOrElement) {
283
- if (specUtils.isSelector(this._spec, selectorOrElement)) {
284
+ if ((0, selector_1.isSelector)(selectorOrElement, this._spec)) {
284
285
  if (this.isRef) {
285
286
  return [new element_1.Element({ spec: this._spec, context: this, selector: selectorOrElement, logger: this._logger })];
286
287
  }
package/dist/driver.js CHANGED
@@ -183,19 +183,17 @@ class Driver {
183
183
  await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
184
184
  const capabilities = await ((_d = (_c = this._spec).getCapabilities) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
185
185
  this._logger.log('Driver capabilities', capabilities);
186
- const capabilitiesInfo = capabilities ? (0, capabilities_1.parseCapabilities)(capabilities) : undefined;
186
+ const capabilitiesInfo = capabilities && (0, capabilities_1.parseCapabilities)(capabilities);
187
187
  const driverInfo = await ((_f = (_e = this._spec).getDriverInfo) === null || _f === void 0 ? void 0 : _f.call(_e, this.target));
188
188
  this._driverInfo = { ...capabilitiesInfo, ...driverInfo };
189
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
190
  if (this.isMobile) {
191
191
  this._driverInfo.orientation =
192
192
  (_l = (await this.getOrientation().catch(() => undefined))) !== null && _l !== void 0 ? _l : this._driverInfo.orientation;
193
- if (this.isWeb) {
194
- const world = await this.getCurrentWorld();
195
- if (world) {
196
- const [home] = (await this.getWorlds());
197
- this._driverInfo.isWebView = world !== home;
198
- }
193
+ const world = await this.getCurrentWorld();
194
+ if (world) {
195
+ const [home] = (await this.getWorlds());
196
+ this._driverInfo.isWebView = world !== home;
199
197
  }
200
198
  }
201
199
  if (this.isWeb) {
@@ -342,22 +340,21 @@ class Driver {
342
340
  return this._helper;
343
341
  }
344
342
  async extractBrokerUrl() {
345
- if (this._state.brokerUrl)
346
- return this._state.brokerUrl;
343
+ var _a;
344
+ var _b;
347
345
  if (!this.isNative)
348
346
  return null;
349
347
  this._logger.log('Broker url extraction is started');
350
- const element = await this.element({ type: 'accessibility id', selector: 'Applitools_View' });
351
- if (!element)
348
+ (_a = (_b = this._state).nmlElement) !== null && _a !== void 0 ? _a : (_b.nmlElement = await this.element({ type: 'accessibility id', selector: 'Applitools_View' }));
349
+ if (!this._state.nmlElement)
352
350
  return null;
353
351
  try {
354
352
  let result;
355
353
  do {
356
- result = JSON.parse(await element.getText());
354
+ result = JSON.parse(await this._state.nmlElement.getText());
357
355
  if (result.nextPath) {
358
356
  this._logger.log('Broker url was extraction finished successfully with value', result.nextPath);
359
- this._state.brokerUrl = result.nextPath;
360
- return this._state.brokerUrl;
357
+ return result.nextPath;
361
358
  }
362
359
  await utils.general.sleep(1000);
363
360
  } while (!result.error);
@@ -365,12 +362,11 @@ class Driver {
365
362
  return null;
366
363
  }
367
364
  catch (error) {
368
- this._logger.error('Broker url extraction has failed with error', error);
369
- return null;
365
+ this._logger.error('Broker url extraction has failed with error and will be retried', error);
366
+ this._state.nmlElement = null;
367
+ return this.extractBrokerUrl();
370
368
  }
371
369
  }
372
- // begin world
373
- //
374
370
  // About the concept of a "World":
375
371
  //
376
372
  // Since "context" is an overloaded term from frames, we have decided to use
package/dist/element.js CHANGED
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.isElementReference = exports.Element = void 0;
27
+ const selector_1 = require("./selector");
27
28
  const utils = __importStar(require("@applitools/utils"));
28
- const specUtils = __importStar(require("./spec-utils"));
29
29
  const snippets = require('@applitools/snippets');
30
30
  class Element {
31
31
  constructor(options) {
@@ -42,13 +42,13 @@ class Element {
42
42
  this._index = options.index;
43
43
  }
44
44
  }
45
- else if (specUtils.isSelector(this._spec, options.selector)) {
45
+ else if ((0, selector_1.isSelector)(options.selector, this._spec)) {
46
46
  this._selector = options.selector;
47
47
  }
48
48
  else {
49
49
  throw new TypeError('Element constructor called with argument of unknown type!');
50
50
  }
51
- if (specUtils.isSimpleCommonSelector(this._selector) && !utils.types.isString(this._selector)) {
51
+ if ((0, selector_1.isSimpleCommonSelector)(this._selector) && !utils.types.isString(this._selector)) {
52
52
  this._commonSelector = this._selector;
53
53
  }
54
54
  else if (this._selector && this._spec.untransformSelector) {
@@ -698,6 +698,6 @@ class Element {
698
698
  }
699
699
  exports.Element = Element;
700
700
  function isElementReference(reference, spec) {
701
- return !!spec && (spec.isElement(reference) || specUtils.isSelector(spec, reference));
701
+ return !!spec && (spec.isElement(reference) || (0, selector_1.isSelector)(reference, spec));
702
702
  }
703
703
  exports.isElementReference = isElementReference;
@@ -206,6 +206,9 @@ class MockDriver {
206
206
  this.mockSelector(selector, element);
207
207
  return element;
208
208
  }
209
+ unmockElement(element) {
210
+ this.unmockSelector(element.selector, element);
211
+ }
209
212
  mockElements(nodes, { parentId = null, parentContextId = null, parentRootId = null } = {}) {
210
213
  for (const node of nodes) {
211
214
  const element = this.mockElement(node.selector, { ...node, parentId, parentContextId, parentRootId });
@@ -226,6 +229,15 @@ class MockDriver {
226
229
  }
227
230
  elements.push(element);
228
231
  }
232
+ unmockSelector(selector, element) {
233
+ const elements = this._elements.get(selector);
234
+ if (!elements)
235
+ return;
236
+ const index = elements.indexOf(element);
237
+ if (index < 0)
238
+ return;
239
+ elements.splice(index, 1);
240
+ }
229
241
  wrapMethod(name, wrapper) {
230
242
  if (!this[name] || name.startsWith('_') || !utils.types.isFunction(this[name]))
231
243
  return;
package/dist/selector.js CHANGED
@@ -1,2 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isSimpleCommonSelector = exports.isObjectCommonSelector = exports.isSelector = void 0;
27
+ const utils = __importStar(require("@applitools/utils"));
28
+ function isSelector(selector, spec) {
29
+ return (spec === null || spec === void 0 ? void 0 : spec.isSelector(selector)) || utils.types.isString(selector) || isObjectCommonSelector(selector, spec);
30
+ }
31
+ exports.isSelector = isSelector;
32
+ function isObjectCommonSelector(selector, spec) {
33
+ return (utils.types.isPlainObject(selector) &&
34
+ utils.types.has(selector, 'selector') &&
35
+ Object.keys(selector).every(key => ['selector', 'type', 'frame', 'shadow', 'child', 'fallback'].includes(key)) &&
36
+ (utils.types.isString(selector.selector) || !!(spec === null || spec === void 0 ? void 0 : spec.isSelector(selector.selector))));
37
+ }
38
+ exports.isObjectCommonSelector = isObjectCommonSelector;
39
+ function isSimpleCommonSelector(selector) {
40
+ return utils.types.isString(selector) || isObjectCommonSelector(selector);
41
+ }
42
+ exports.isSimpleCommonSelector = isSimpleCommonSelector;
@@ -1,48 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.withFastCache = exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isObjectCommonSelector = exports.isSimpleCommonSelector = void 0;
27
- const utils = __importStar(require("@applitools/utils"));
28
- function isSimpleCommonSelector(selector) {
29
- return utils.types.isString(selector) || isObjectCommonSelector(null, selector);
30
- }
31
- exports.isSimpleCommonSelector = isSimpleCommonSelector;
32
- function isObjectCommonSelector(spec, selector) {
33
- return (utils.types.isPlainObject(selector) &&
34
- utils.types.has(selector, 'selector') &&
35
- Object.keys(selector).every(key => ['selector', 'type', 'frame', 'shadow', 'child', 'fallback'].includes(key)) &&
36
- (utils.types.isString(selector.selector) || !!(spec === null || spec === void 0 ? void 0 : spec.isSelector(selector.selector))));
37
- }
38
- exports.isObjectCommonSelector = isObjectCommonSelector;
39
- function isSelector(spec, selector) {
40
- return spec.isSelector(selector) || utils.types.isString(selector) || isObjectCommonSelector(spec, selector);
41
- }
42
- exports.isSelector = isSelector;
3
+ exports.withFastCache = exports.splitSelector = exports.transformSelector = void 0;
4
+ const selector_1 = require("./selector");
43
5
  function transformSelector(spec, selector, environment) {
44
6
  var _a, _b;
45
- if ((environment === null || environment === void 0 ? void 0 : environment.isWeb) && isObjectCommonSelector(spec, selector)) {
7
+ if ((environment === null || environment === void 0 ? void 0 : environment.isWeb) && (0, selector_1.isObjectCommonSelector)(selector, spec)) {
46
8
  if (selector.type === 'id')
47
9
  selector = { type: 'css', selector: `#${selector.selector}` };
48
10
  else if (selector.type === 'name')
@@ -62,7 +24,7 @@ function splitSelector(spec, selector) {
62
24
  let elementSelector = activeSelector;
63
25
  const contextSelectors = [];
64
26
  while (targetSelector) {
65
- if (isObjectCommonSelector(spec, targetSelector)) {
27
+ if ((0, selector_1.isObjectCommonSelector)(targetSelector, spec)) {
66
28
  activeSelector.selector = targetSelector.selector;
67
29
  if (targetSelector.type)
68
30
  activeSelector.type = targetSelector.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.11.33",
3
+ "version": "1.11.35",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -1,9 +1,9 @@
1
1
  import type { Location, Size, Region } from '@applitools/utils';
2
2
  import type { Cookie } from './types';
3
+ import { type Logger } from '@applitools/logger';
3
4
  import { type SpecType, type SpecDriver, type WaitOptions } from './spec-driver';
4
5
  import { type Driver } from './driver';
5
6
  import { type Selector } from './selector';
6
- import { type Logger } from '@applitools/logger';
7
7
  import { Element, type ElementReference } from './element';
8
8
  export type ContextReference<T extends SpecType> = Element<T> | ElementReference<T> | string | number;
9
9
  export type NestedContextReference<T extends SpecType> = {
@@ -1,8 +1,8 @@
1
1
  import type { Location, Size, Region } from '@applitools/utils';
2
+ import { type Logger } from '@applitools/logger';
2
3
  import { type SpecType, type SpecDriver } from './spec-driver';
3
4
  import { type Context } from './context';
4
5
  import { type Selector, type CommonSelector } from './selector';
5
- import { type Logger } from '@applitools/logger';
6
6
  export type ElementReference<T extends SpecType> = T['element'] | Selector<T>;
7
7
  type ElementState = {
8
8
  contentSize?: Size;
@@ -2,12 +2,14 @@ export declare class MockDriver {
2
2
  constructor(options?: {});
3
3
  mockScript(scriptMatcher: any, resultGenerator: any): void;
4
4
  mockElement(selector: any, state: any): any;
5
+ unmockElement(element: any): void;
5
6
  mockElements(nodes: any, { parentId, parentContextId, parentRootId }?: {
6
7
  parentId?: null | undefined;
7
8
  parentContextId?: null | undefined;
8
9
  parentRootId?: null | undefined;
9
10
  }): void;
10
11
  mockSelector(selector: any, element: any): void;
12
+ unmockSelector(selector: any, element: any): void;
11
13
  wrapMethod<TName extends {
12
14
  [K in keyof MockDriver]: MockDriver[K] extends (...args: any[]) => any ? K : never;
13
15
  }[keyof MockDriver]>(name: TName, wrapper: (method: this[TName], thisArg: this, args: Parameters<this[TName]>) => ReturnType<this[TName]>): void;
@@ -1,4 +1,4 @@
1
- import { type SpecType } from './spec-driver';
1
+ import { type SpecType, type SpecDriver } from './spec-driver';
2
2
  export type Selector<T extends SpecType = never> = T['selector'] | CommonSelector<T['selector']>;
3
3
  export type CommonSelector<TSelector = never> = string | ComplexSelector<TSelector>;
4
4
  type ComplexSelector<TSelector> = {
@@ -9,4 +9,7 @@ type ComplexSelector<TSelector> = {
9
9
  frame?: TSelector | string | CommonSelector<TSelector>;
10
10
  fallback?: TSelector | string | CommonSelector<TSelector>;
11
11
  };
12
+ export declare function isSelector<T extends SpecType>(selector: any, spec?: Pick<SpecDriver<T>, 'isSelector'>): selector is Selector<T>;
13
+ export declare function isObjectCommonSelector<T extends SpecType>(selector: any, spec?: Pick<SpecDriver<T>, 'isSelector'>): selector is Exclude<CommonSelector<T['selector']>, string>;
14
+ export declare function isSimpleCommonSelector(selector: any): selector is CommonSelector;
12
15
  export {};
@@ -1,8 +1,5 @@
1
1
  import { type SpecType, type SpecDriver } from './spec-driver';
2
- import { type Selector, type CommonSelector } from './selector';
3
- export declare function isSimpleCommonSelector(selector: any): selector is CommonSelector;
4
- export declare function isObjectCommonSelector<T extends SpecType>(spec: Pick<SpecDriver<T>, 'isSelector'> | null, selector: any): selector is Exclude<CommonSelector<T['selector']>, string>;
5
- export declare function isSelector<T extends SpecType>(spec: Pick<SpecDriver<T>, 'isSelector'>, selector: any): selector is Selector<T>;
2
+ import { type Selector } from './selector';
6
3
  export declare function transformSelector<T extends SpecType>(spec: Pick<SpecDriver<T>, 'isSelector' | 'transformSelector'>, selector: Selector<T>, environment?: {
7
4
  isWeb?: boolean;
8
5
  isNative?: boolean;