@applitools/core 1.1.0 → 1.1.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.
@@ -51,7 +51,6 @@ async function takeScreenshot({ driver, settings, logger, }) {
51
51
  },
52
52
  debug: settings.debugImages,
53
53
  logger,
54
- webview: settings.webview,
55
54
  });
56
55
  }
57
56
  exports.takeScreenshot = takeScreenshot;
package/dist/check.js CHANGED
@@ -22,13 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.makeCheck = void 0;
30
27
  const utils = __importStar(require("@applitools/utils"));
31
- const chalk_1 = __importDefault(require("chalk"));
32
28
  function makeCheck({ eyes, logger: defaultLogger, }) {
33
29
  return async function check({ target, settings = {}, config, logger = defaultLogger, } = {}) {
34
30
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
@@ -52,9 +48,6 @@ function makeCheck({ eyes, logger: defaultLogger, }) {
52
48
  (_p = (_u = settings.lazyLoad).maxAmountToScroll) !== null && _p !== void 0 ? _p : (_u.maxAmountToScroll = 15000);
53
49
  }
54
50
  (_q = settings.waitBetweenStitches) !== null && _q !== void 0 ? _q : (settings.waitBetweenStitches = utils.types.isObject(settings.lazyLoad) ? settings.lazyLoad.waitingTime : 100);
55
- if (settings.matchLevel === 'Content') {
56
- logger.console.log(chalk_1.default.yellow(`The "Content" match level value has been deprecated, use "IgnoreColors" instead.`));
57
- }
58
51
  const results = await eyes.check({ target: target, settings, logger });
59
52
  return results;
60
53
  };
File without changes
@@ -0,0 +1,60 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateSelectors = void 0;
27
+ const snippets = __importStar(require("@applitools/snippets"));
28
+ const utils = __importStar(require("@applitools/utils"));
29
+ async function generateSelectors({ context, elementReferences, }) {
30
+ const mapping = {
31
+ elements: [],
32
+ ids: [],
33
+ };
34
+ for (const elementReference of elementReferences) {
35
+ const elements = await context.elements(elementReference);
36
+ mapping.elements.push(elements);
37
+ mapping.ids.push(Array(elements.length).fill(utils.general.guid()));
38
+ }
39
+ const generatedSelectors = await context.execute(snippets.addElementIds, [mapping.elements.flat(), mapping.ids.flat()]);
40
+ let offset = 0;
41
+ const selectors = mapping.elements.map(elements => {
42
+ if (elements.length === 0)
43
+ return null;
44
+ const generatedSelector = generatedSelectors[offset].reduce((selector, value) => {
45
+ return selector ? { ...selector, shadow: { type: 'css', selector: value } } : { type: 'css', selector: value };
46
+ }, null);
47
+ offset += elements.length;
48
+ return { generatedSelector, originalSelector: elements[0].commonSelector };
49
+ });
50
+ return {
51
+ selectors,
52
+ cleanupGeneratedSelectors,
53
+ };
54
+ async function cleanupGeneratedSelectors() {
55
+ if (!mapping.elements.length)
56
+ return;
57
+ await context.execute(snippets.cleanupElementIds, [mapping.elements]);
58
+ }
59
+ }
60
+ exports.generateSelectors = generateSelectors;
@@ -31,8 +31,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.takeDomSnapshots = void 0;
33
33
  const take_dom_snapshot_1 = require("./take-dom-snapshot");
34
- const utils = __importStar(require("@applitools/utils"));
35
34
  const chalk_1 = __importDefault(require("chalk"));
35
+ const utils = __importStar(require("@applitools/utils"));
36
36
  __exportStar(require("./take-dom-snapshot"), exports);
37
37
  async function takeDomSnapshots({ driver, settings, hooks, provides, logger, }) {
38
38
  var _a, _b, _c, _d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "homepage": "https://applitools.com",
5
5
  "bugs": {
6
6
  "url": "https://github.com/applitools/eyes.sdk.javascript1/issues"
@@ -57,17 +57,17 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
- "@applitools/core-base": "1.0.6",
60
+ "@applitools/core-base": "1.0.7",
61
61
  "@applitools/dom-capture": "11.1.2",
62
- "@applitools/dom-snapshot": "4.6.2",
63
- "@applitools/driver": "1.10.3",
64
- "@applitools/logger": "1.1.24",
65
- "@applitools/nml-client": "1.3.0",
66
- "@applitools/req": "1.1.8",
67
- "@applitools/screenshoter": "3.6.0",
62
+ "@applitools/dom-snapshot": "4.6.3",
63
+ "@applitools/driver": "1.10.4",
64
+ "@applitools/logger": "1.1.25",
65
+ "@applitools/nml-client": "1.3.1",
66
+ "@applitools/req": "1.1.9",
67
+ "@applitools/screenshoter": "3.6.2",
68
68
  "@applitools/snippets": "2.4.5",
69
- "@applitools/types": "1.5.17",
70
- "@applitools/ufg-client": "1.0.6",
69
+ "@applitools/types": "1.5.18",
70
+ "@applitools/ufg-client": "1.0.7",
71
71
  "@applitools/utils": "1.3.12",
72
72
  "abort-controller": "3.0.0",
73
73
  "throat": "6.0.1"
@@ -75,9 +75,9 @@
75
75
  "devDependencies": {
76
76
  "@applitools/bongo": "^2.2.0",
77
77
  "@applitools/sdk-fake-eyes-server": "^2.1.3",
78
- "@applitools/spec-driver-puppeteer": "^1.1.13",
79
- "@applitools/spec-driver-selenium": "^1.4.0",
80
- "@applitools/spec-driver-webdriverio": "^1.3.0",
78
+ "@applitools/spec-driver-puppeteer": "^1.1.14",
79
+ "@applitools/spec-driver-selenium": "^1.4.1",
80
+ "@applitools/spec-driver-webdriverio": "^1.3.1",
81
81
  "@applitools/test-server": "^1.1.5",
82
82
  "@applitools/test-utils": "^1.5.1",
83
83
  "@types/mocha": "^9.1.1",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { Proxy } from '@applitools/types';
3
+ import { Request } from 'node-fetch';
4
+ import { Req, Options } from './req';
5
+ import { Logger } from '@applitools/logger';
6
+ export declare type ReqEyesConfig = {
7
+ serverUrl: string;
8
+ apiKey: string;
9
+ proxy?: Proxy;
10
+ agentId?: string;
11
+ connectionTimeout?: number;
12
+ removeSession?: boolean;
13
+ };
14
+ export declare type ReqEyesOptions = Options & {
15
+ name: string;
16
+ expected?: number | number[];
17
+ };
18
+ export declare type ReqEyes = Req & ((input: string | URL | Request, options?: ReqEyesOptions) => ReturnType<Req>);
19
+ export declare function makeReqEyes({ config, logger }: {
20
+ config: ReqEyesConfig;
21
+ logger?: Logger;
22
+ }): ReqEyes;
@@ -0,0 +1,172 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import globalFetch, { Request, Response } from 'node-fetch';
4
+ declare const stop: unique symbol;
5
+ export declare type Options = {
6
+ /**
7
+ * Providing this value will allow usage of relative urls for input
8
+ * @example 'http://localhost:2107/api/'
9
+ */
10
+ baseUrl?: string;
11
+ /**
12
+ * Uppercase method name. This will override method provided in `Request` object
13
+ * @example 'GET'
14
+ */
15
+ method?: string;
16
+ /**
17
+ * Query parameters to add to the url, all undefined params won't be added.
18
+ * It won't override the whole `search` part of the url, but instead merge with it
19
+ * @example {string: 'value', number: 21, boolean: true, noop: undefined}
20
+ */
21
+ query?: Record<string, string | boolean | number | undefined>;
22
+ /**
23
+ * Headers to send in the request, all undefined headers won't be sent.
24
+ * This will merge with headers provided in `Request` object
25
+ * @example {'x-my-header': 'value', 'x-noop-header': undefined}
26
+ */
27
+ headers?: Record<string, string | undefined>;
28
+ /**
29
+ * Body of the request, plain objects will be transformed to JSON strings
30
+ * @example {data: true}
31
+ * @example Buffer.from('S3lyeWxv', 'base64')
32
+ */
33
+ body?: NodeJS.ReadableStream | ArrayBufferView | string | Record<string, any>;
34
+ /**
35
+ * Proxy settings for the request. Auth credentials specified in the object will override ones specified in url
36
+ * @example {url: 'http://localhost:2107', username: 'kyrylo', password: 'pass'}
37
+ */
38
+ proxy?: {
39
+ url: string;
40
+ username: string;
41
+ password: string;
42
+ };
43
+ /**
44
+ * Connection timeout in ms
45
+ * @example 7000
46
+ */
47
+ timeout?: number;
48
+ /**
49
+ * Retry settings for the request. If specified as an array the retries are applied in the order
50
+ * @see Retry
51
+ * @example {limit: 5, statuses: [500, 501], codes: ['ECONRESET'], timeout: 1000}
52
+ */
53
+ retry?: Retry | Retry[];
54
+ /**
55
+ * Hooks of the request
56
+ * @see Hooks
57
+ */
58
+ hooks?: Hooks | Hooks[];
59
+ fetch?: typeof globalFetch;
60
+ };
61
+ export declare type Retry = {
62
+ /**
63
+ * Max number of attempts for specified condition
64
+ */
65
+ limit?: number;
66
+ /**
67
+ * Timeout before retrying the request. If specified as an array each element specifies the timeout for specific attempt,
68
+ * and the last one will be default for all next attempts
69
+ * @example [1000, 1000, 5000, 10_000]
70
+ */
71
+ timeout?: number | number[];
72
+ /**
73
+ * Status codes of the response to retry on.
74
+ * @example [500]
75
+ */
76
+ statuses?: number[];
77
+ /**
78
+ * Error codes of the request to retry on.
79
+ * @example ['ECONRESET']
80
+ */
81
+ codes?: string[];
82
+ /**
83
+ * Number of the current attempt for specified condition
84
+ * @internal
85
+ */
86
+ attempt?: number;
87
+ };
88
+ export declare type Hooks = {
89
+ /**
90
+ * Hook that will be executed before sending the request, after all, modifications of the `Request` object are already passed
91
+ * @example
92
+ * ```
93
+ * {
94
+ * beforeRequest({request}) {
95
+ * request.headers.set('Expires', 'Tue, 24 Aug 2022 00:00:00 GMT')
96
+ * }
97
+ * }
98
+ * ```
99
+ */
100
+ beforeRequest?(options: {
101
+ request: Request;
102
+ options: Options;
103
+ }): Request | void | Promise<Request | void>;
104
+ /**
105
+ * Hook that will be executed before retrying the request. If this hook will return {@link req.stop}
106
+ * it will prevent request from retrying and execution of other hooks
107
+ * @example
108
+ * ```
109
+ * {
110
+ * async beforeRetry({request, response, attempt}) {
111
+ * const data = await response?.json()
112
+ * if (data.error) return req.stop
113
+ * request.headers.set('x-attempt', attempt)
114
+ * }
115
+ * }
116
+ * ```
117
+ */
118
+ beforeRetry?(options: {
119
+ request: Request;
120
+ attempt: number;
121
+ response?: Response;
122
+ error?: Error;
123
+ options: Options;
124
+ }): Request | typeof stop | void | Promise<Request | void | typeof stop>;
125
+ /**
126
+ * Hook that will be executed after getting the final response of the request (after all of the retries)
127
+ * @example
128
+ * ```
129
+ * {
130
+ * async afterResponse({request, response, options}) {
131
+ * if (!response.ok) return req(request, options)
132
+ * }
133
+ * }
134
+ * ```
135
+ */
136
+ afterResponse?(options: {
137
+ request: Request;
138
+ response: Response;
139
+ options: Options;
140
+ }): Response | void | Promise<Response | void>;
141
+ /**
142
+ * Hook that will be executed after request will throw an error
143
+ * @example
144
+ * ```
145
+ * {
146
+ * async afterError({request, error}) {
147
+ * error.request = request
148
+ * }
149
+ * }
150
+ * ```
151
+ */
152
+ afterError?(options: {
153
+ request: Request;
154
+ error: Error;
155
+ options: Options;
156
+ }): Error | void | Promise<Error | void>;
157
+ };
158
+ /**
159
+ * Helper function that will properly merge two {@link Options} objects
160
+ */
161
+ export declare function mergeOptions(baseOption: Options, options: Options): Options;
162
+ /**
163
+ * Helper function that will create {@link req} function with predefined options
164
+ * @example const req = makeReq({baseUrl: 'http://localhost:2107'})
165
+ */
166
+ export declare function makeReq(baseOption?: Options): typeof req;
167
+ export declare function req(input: string | URL | Request, options?: Options): Promise<Response>;
168
+ export declare namespace req {
169
+ var stop: unique symbol;
170
+ }
171
+ export declare type Req = typeof req;
172
+ export default req;
@@ -0,0 +1,73 @@
1
+ import type { Region, TextRegion, Batch } from '@applitools/types';
2
+ import type { Target, Core, Eyes, ServerSettings, CheckSettings, LocateSettings, LocateTextSettings, ExtractTextSettings, CloseSettings, DeleteTestSettings, CloseBatchSettings, CheckResult, TestResult, OpenSettings } from '@applitools/types/types/core-base';
3
+ import { type Logger } from '@applitools/logger';
4
+ import { type ReqEyes } from './req-eyes';
5
+ interface AccountInfo {
6
+ renderUrl: string;
7
+ renderToken: string;
8
+ uploadUrl: string;
9
+ maxImageHeight: number;
10
+ maxImageArea: number;
11
+ }
12
+ interface Test {
13
+ testId: string;
14
+ batchId: string;
15
+ baselineId: string;
16
+ sessionId: string;
17
+ resultsUrl: string;
18
+ isNew: boolean;
19
+ }
20
+ export interface CoreRequests extends Core {
21
+ openEyes(options: {
22
+ settings: OpenSettings;
23
+ }): Promise<EyesRequests>;
24
+ getAccountInfo(options: {
25
+ settings: ServerSettings;
26
+ }): Promise<AccountInfo>;
27
+ getBatch(options: {
28
+ settings: ServerSettings & {
29
+ batchId: string;
30
+ };
31
+ }): Promise<Batch>;
32
+ closeBatch(options: {
33
+ settings: CloseBatchSettings;
34
+ }): Promise<void>;
35
+ deleteTest(options: {
36
+ settings: DeleteTestSettings;
37
+ }): Promise<void>;
38
+ }
39
+ export interface EyesRequests extends Eyes {
40
+ check(options: {
41
+ target: Target;
42
+ settings?: CheckSettings;
43
+ }): Promise<CheckResult[]>;
44
+ checkAndClose(options: {
45
+ target: Target;
46
+ settings?: CheckSettings;
47
+ }): Promise<TestResult[]>;
48
+ locate<TLocator extends string>(options: {
49
+ target: Target;
50
+ settings: LocateSettings<TLocator>;
51
+ }): Promise<Record<TLocator, Region[]>>;
52
+ locateText<TPattern extends string>(options: {
53
+ target: Target;
54
+ settings: LocateTextSettings<TPattern>;
55
+ }): Promise<Record<TPattern, TextRegion[]>>;
56
+ extractText(options: {
57
+ target: Target;
58
+ settings: ExtractTextSettings;
59
+ }): Promise<string[]>;
60
+ close(options: {
61
+ settings: CloseSettings;
62
+ }): Promise<TestResult[]>;
63
+ abort(): Promise<TestResult[]>;
64
+ }
65
+ export declare function makeCoreCommands({ logger }: {
66
+ logger?: Logger;
67
+ }): CoreRequests;
68
+ export declare function makeEyesCommands({ test, req, logger }: {
69
+ test: Test;
70
+ req: ReqEyes;
71
+ logger?: Logger;
72
+ }): EyesRequests;
73
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { Selector } from '@applitools/types';
2
+ import { type Context } from '@applitools/driver';
3
+ export declare function generateSelectors<TElement, TSelector>({ context, elementReferences, }: {
4
+ context: Context<unknown, unknown, TElement, TSelector>;
5
+ elementReferences: (TElement | Selector<TSelector>)[];
6
+ }): Promise<{
7
+ selectors: {
8
+ generatedSelector: Selector;
9
+ originalSelector: Selector;
10
+ }[];
11
+ cleanupGeneratedSelectors(): Promise<void>;
12
+ }>;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.takeNativeAppSnapshot = exports.getBrokerURL = void 0;
4
- const nml_client_1 = require("@applitools/nml-client");
5
- async function getBrokerURL(driver) {
6
- if (!driver.isIOS)
7
- return false;
8
- try {
9
- const element = await driver.element({
10
- type: 'xpath',
11
- selector: '//XCUIElementTypeOther[@name="Applitools_View"]',
12
- });
13
- const result = JSON.parse(await element.getText());
14
- return result.nextPath;
15
- }
16
- catch (error) {
17
- return false;
18
- }
19
- }
20
- exports.getBrokerURL = getBrokerURL;
21
- async function takeNativeAppSnapshot(options) {
22
- const nmlSnapshot = await (0, nml_client_1.takeSnapshot)(options.driver);
23
- const snapshot = {
24
- platformName: nmlSnapshot.resourceMap.metadata.platformName,
25
- vhsHash: nmlSnapshot.resourceMap.vhs,
26
- vhsCompatibilityParams: undefined,
27
- };
28
- if (options.driver.isIOS) {
29
- snapshot.vhsCompatibilityParams = {
30
- UIKitLinkTimeVersionNumber: nmlSnapshot.metadata.UIKitLinkTimeVersionNumber,
31
- UIKitRunTimeVersionNumber: nmlSnapshot.metadata.UIKitRunTimeVersionNumber,
32
- };
33
- }
34
- return { snapshots: snapshot };
35
- }
36
- exports.takeNativeAppSnapshot = takeNativeAppSnapshot;
@@ -1,5 +0,0 @@
1
- export declare function getBrokerURL(driver: any): Promise<any>;
2
- export declare function takeNativeAppSnapshot(options: {
3
- driver: any;
4
- logger: any;
5
- }): Promise<any>;