@applitools/driver 1.20.5 → 1.21.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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.21.1](https://github.com/Applitools-Dev/sdk/compare/js/driver@1.21.0...js/driver@1.21.1) (2025-04-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * executePoll error logging FLD-2870 ([#2890](https://github.com/Applitools-Dev/sdk/issues/2890)) ([a8ff720](https://github.com/Applitools-Dev/sdk/commit/a8ff720efafacabe2023282748a6d8a0f1b3ff73))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * @applitools/snippets bumped to 2.6.5
14
+ #### Performance Improvements
15
+
16
+ * cachify http agent ([#2466](https://github.com/Applitools-Dev/sdk/issues/2466)) ([bc2f4a1](https://github.com/Applitools-Dev/sdk/commit/bc2f4a1fae3c379f061c9199edf4c5257769fb44))
17
+
18
+ ## [1.21.0](https://github.com/Applitools-Dev/sdk/compare/js/driver@1.20.5...js/driver@1.21.0) (2025-03-30)
19
+
20
+
21
+ ### Features
22
+
23
+ * allow sending callback functions to waitBeforeCapture ([#2780](https://github.com/Applitools-Dev/sdk/issues/2780)) ([4caa2e8](https://github.com/Applitools-Dev/sdk/commit/4caa2e8ae055d3dd48164eeceaa4c691eeadcdd4))
24
+
25
+
26
+ ### Dependencies
27
+
28
+ * @applitools/utils bumped to 1.8.0
29
+ #### Features
30
+
31
+ * allow sending callback functions to waitBeforeCapture ([#2780](https://github.com/Applitools-Dev/sdk/issues/2780)) ([4caa2e8](https://github.com/Applitools-Dev/sdk/commit/4caa2e8ae055d3dd48164eeceaa4c691eeadcdd4))
32
+ * @applitools/logger bumped to 2.1.2
33
+
34
+
3
35
  ## [1.20.5](https://github.com/Applitools-Dev/sdk/compare/js/driver@1.20.4...js/driver@1.20.5) (2025-02-26)
4
36
 
5
37
 
package/dist/context.js CHANGED
@@ -362,7 +362,15 @@ class Context {
362
362
  let chunks = '';
363
363
  while (!isExecutionTimedOut) {
364
364
  if (response.status === 'ERROR') {
365
- throw new Error(`Error during execute poll script: '${response.error}'`);
365
+ let errorMessage = response.error;
366
+ try {
367
+ errorMessage = JSON.stringify(errorMessage);
368
+ }
369
+ catch (err) {
370
+ errorMessage = `Error during execute poll script: '${errorMessage}'. Addtionaly, the error is not serializable - ${err}`;
371
+ }
372
+ this.logger.error(`Error during execute poll script: '${errorMessage}'`);
373
+ throw new Error(`Error during execute poll script: '${errorMessage}'`);
366
374
  }
367
375
  else if (response.status === 'SUCCESS') {
368
376
  return response.value;
@@ -570,8 +578,5 @@ class Context {
570
578
  this._state.region = await this.getRegion();
571
579
  this._state.clientRegion = await this.getClientRegion();
572
580
  }
573
- async preserveScrollingRegion() {
574
- this._state.scrollingRegion = await this.getScrollingRegion();
575
- }
576
581
  }
577
582
  exports.Context = Context;
package/dist/driver.js CHANGED
@@ -884,6 +884,18 @@ class Driver {
884
884
  async execute(script, arg) {
885
885
  return this.currentContext.execute(script, arg);
886
886
  }
887
+ async executeUserFunction(func) {
888
+ var _a, _b;
889
+ if (await ((_b = (_a = this._spec).isUserFunction) === null || _b === void 0 ? void 0 : _b.call(_a, func))) {
890
+ return this._spec.executeUserFunction(func);
891
+ }
892
+ else if (typeof func === 'function') {
893
+ return func();
894
+ }
895
+ else {
896
+ throw new Error(`User function is not supported (${JSON.stringify(func)})`);
897
+ }
898
+ }
887
899
  async visit(url) {
888
900
  var _a, _b;
889
901
  await ((_b = (_a = this._spec).visit) === null || _b === void 0 ? void 0 : _b.call(_a, this.target, url));
@@ -280,6 +280,18 @@ class MockDriver {
280
280
  let result = this._scripts.get(String(script));
281
281
  if (!result) {
282
282
  const name = Object.keys(WELL_KNOWN_SCRIPTS).find(name => WELL_KNOWN_SCRIPTS[name](script));
283
+ if (utils.types.isFunction(script)) {
284
+ try {
285
+ return JSON.stringify(await script(...args));
286
+ }
287
+ catch (e) {
288
+ if (script.throwing) {
289
+ throw e;
290
+ }
291
+ else
292
+ return null;
293
+ }
294
+ }
283
295
  if (!name)
284
296
  return null;
285
297
  result = this._scripts.get(name);
@@ -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.getCapabilities = exports.performAction = exports.getElementAttribute = exports.getElementRegion = exports.getCurrentWorld = 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.toSimpleCommonSelector = exports.toSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
26
+ exports.executeUserFunction = exports.isUserFunction = exports.getCapabilities = exports.performAction = exports.getElementAttribute = exports.getElementRegion = exports.getCurrentWorld = 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.toSimpleCommonSelector = exports.toSelector = 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';
@@ -157,3 +157,11 @@ async function getCapabilities(driver) {
157
157
  return driver.capabilities;
158
158
  }
159
159
  exports.getCapabilities = getCapabilities;
160
+ async function isUserFunction(_ref) {
161
+ return false;
162
+ }
163
+ exports.isUserFunction = isUserFunction;
164
+ async function executeUserFunction(_userFunction) {
165
+ throw new Error(`executeUserFunction is not supported in FakeDriver. userFunction: ${_userFunction}`);
166
+ }
167
+ exports.executeUserFunction = executeUserFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/driver",
3
- "version": "1.20.5",
3
+ "version": "1.21.1",
4
4
  "description": "Applitools universal framework wrapper",
5
5
  "keywords": [
6
6
  "applitools",
@@ -73,9 +73,9 @@
73
73
  "test": "run --top-level mocha './test/**/*.spec.ts'"
74
74
  },
75
75
  "dependencies": {
76
- "@applitools/logger": "2.1.1",
77
- "@applitools/snippets": "2.6.4",
78
- "@applitools/utils": "1.7.8",
76
+ "@applitools/logger": "2.1.2",
77
+ "@applitools/snippets": "2.6.5",
78
+ "@applitools/utils": "1.8.0",
79
79
  "semver": "7.6.2"
80
80
  },
81
81
  "devDependencies": {
@@ -81,6 +81,5 @@ export declare class Context<T extends SpecType> {
81
81
  getCookies(): Promise<Cookie[]>;
82
82
  private preserveInnerOffset;
83
83
  private preserveContextRegions;
84
- private preserveScrollingRegion;
85
84
  }
86
85
  export {};
package/types/driver.d.ts CHANGED
@@ -102,6 +102,7 @@ export declare class Driver<T extends SpecType> {
102
102
  elements(selector: Selector<T>): Promise<Element<T>[]>;
103
103
  waitFor(selector: Selector<T>, options?: WaitOptions): Promise<Element<T> | null>;
104
104
  execute(script: ((arg: any) => any) | string, arg?: any): Promise<any>;
105
+ executeUserFunction<T>(func: SpecType['userFunction'] | (() => T)): Promise<any>;
105
106
  visit(url: string): Promise<void>;
106
107
  }
107
108
  export declare function isDriverInstance<T extends SpecType>(driver: any): driver is Driver<T>;
@@ -40,4 +40,6 @@ export declare function getElementRegion(_driver: Driver, element: Element): Pro
40
40
  export declare function getElementAttribute(_driver: Driver, element: Element, attr: string): Promise<string>;
41
41
  export declare function performAction(_driver: Driver, _steps: any[]): Promise<void>;
42
42
  export declare function getCapabilities(driver: Driver): Promise<Record<string, any>>;
43
+ export declare function isUserFunction(_ref: any): Promise<boolean>;
44
+ export declare function executeUserFunction(_userFunction: any): Promise<void>;
43
45
  export {};
@@ -1,12 +1,13 @@
1
1
  import type { Size, Region } from '@applitools/utils';
2
2
  import type { DriverInfo, Capabilities, ScreenOrientation, Cookie } from './types';
3
3
  import { type CommonSelector } from './selector';
4
- export type SpecType<TDriver = unknown, TContext = unknown, TElement = unknown, TSelector = unknown, TSecondary extends SpecType = SpecType<unknown, unknown, unknown, unknown, never>> = {
4
+ export type SpecType<TDriver = unknown, TContext = unknown, TElement = unknown, TSelector = unknown, TSecondary extends SpecType = SpecType<unknown, unknown, unknown, unknown, never>, UserFunction = unknown> = {
5
5
  driver: TDriver;
6
6
  context: TContext;
7
7
  element: TElement;
8
8
  selector: TSelector;
9
9
  secondary: TSecondary;
10
+ userFunction: UserFunction;
10
11
  };
11
12
  export interface SpecDriver<T extends SpecType> {
12
13
  /**
@@ -82,6 +83,8 @@ export interface SpecDriver<T extends SpecType> {
82
83
  * Executes given script in the given contexts with given argument.
83
84
  */
84
85
  executeScript(context: T['context'], script: ((arg?: any) => any) | string, arg?: any): Promise<any>;
86
+ isUserFunction?(ref: any): Promise<boolean>;
87
+ executeUserFunction?(userFunction: T['userFunction']): Promise<any>;
85
88
  findElement(context: T['context'], selector: T['selector'], parent?: T['element']): Promise<T['element'] | null>;
86
89
  findElements(context: T['context'], selector: T['selector'], parent?: T['element']): Promise<T['element'][]>;
87
90
  waitForSelector?(context: T['context'], selector: T['selector'], parent?: T['element'], options?: WaitOptions): Promise<T['element'] | null>;