@applitools/nml-client 1.1.0 → 1.2.0
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/client.js +58 -23
- package/dist/req-broker.js +95 -0
- package/package.json +6 -4
- package/types/client.d.ts +25 -11
- package/types/req-broker.d.ts +22 -0
- package/dist/broker.js +0 -38
- package/types/broker.d.ts +0 -35
package/dist/client.js
CHANGED
|
@@ -23,32 +23,67 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
26
|
+
exports.takeSnapshots = exports.takeScreenshot = void 0;
|
|
27
|
+
const logger_1 = require("@applitools/logger");
|
|
28
|
+
const req_broker_1 = require("./req-broker");
|
|
28
29
|
const utils = __importStar(require("@applitools/utils"));
|
|
29
|
-
async function takeScreenshot(url,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
name:
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
async function takeScreenshot({ url, settings, logger, }) {
|
|
31
|
+
var _a;
|
|
32
|
+
logger = (_a = logger === null || logger === void 0 ? void 0 : logger.extend({ label: 'nml client' })) !== null && _a !== void 0 ? _a : (0, logger_1.makeLogger)({ label: 'nml client' });
|
|
33
|
+
const req = (0, req_broker_1.makeReqBroker)({ config: settings, logger });
|
|
34
|
+
const payload = {
|
|
35
|
+
name: settings.name,
|
|
36
|
+
screenshotMode: settings.fully ? 'FULL_RESIZE' : 'VIEWPORT',
|
|
37
|
+
scrollRootElement: settings.scrollRootElement,
|
|
38
|
+
hideCaret: settings.hideCaret,
|
|
39
|
+
waitBeforeCapture: settings.waitBeforeCapture,
|
|
40
|
+
overlap: settings.overlap,
|
|
41
|
+
selectorsToFindRegionsFor: [],
|
|
37
42
|
};
|
|
38
|
-
const
|
|
39
|
-
|
|
43
|
+
const response = await req(url, {
|
|
44
|
+
name: 'TAKE_SCREENSHOT',
|
|
45
|
+
body: {
|
|
46
|
+
protocolVersion: '1.0',
|
|
47
|
+
name: 'TAKE_SCREENSHOT',
|
|
48
|
+
key: utils.general.guid(),
|
|
49
|
+
payload,
|
|
50
|
+
},
|
|
51
|
+
logger,
|
|
52
|
+
});
|
|
53
|
+
const result = await response.json();
|
|
54
|
+
return result.payload;
|
|
40
55
|
}
|
|
41
56
|
exports.takeScreenshot = takeScreenshot;
|
|
42
|
-
async function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
key: utils.general.guid(),
|
|
49
|
-
payload: options && options.settings,
|
|
57
|
+
async function takeSnapshots({ url, settings, logger, }) {
|
|
58
|
+
var _a;
|
|
59
|
+
logger = (_a = logger === null || logger === void 0 ? void 0 : logger.extend({ label: 'nml client' })) !== null && _a !== void 0 ? _a : (0, logger_1.makeLogger)({ label: 'nml client' });
|
|
60
|
+
const req = (0, req_broker_1.makeReqBroker)({ config: settings, logger });
|
|
61
|
+
const payload = {
|
|
62
|
+
waitBeforeCapture: settings.waitBeforeCapture,
|
|
50
63
|
};
|
|
51
|
-
const
|
|
52
|
-
|
|
64
|
+
const response = await req(url, {
|
|
65
|
+
name: 'TAKE_SNAPSHOT',
|
|
66
|
+
body: {
|
|
67
|
+
protocolVersion: '1.0',
|
|
68
|
+
name: 'TAKE_SNAPSHOT',
|
|
69
|
+
key: utils.general.guid(),
|
|
70
|
+
payload,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const snapshot = await response.json().then(({ payload }) => {
|
|
74
|
+
const { resourceMap, metadata } = payload.result;
|
|
75
|
+
const platformName = resourceMap.metadata.platformName;
|
|
76
|
+
return {
|
|
77
|
+
platformName,
|
|
78
|
+
vhsHash: resourceMap.vhs,
|
|
79
|
+
vhsCompatibilityParams: platformName === 'ios'
|
|
80
|
+
? {
|
|
81
|
+
UIKitLinkTimeVersionNumber: metadata.UIKitLinkTimeVersionNumber,
|
|
82
|
+
UIKitRunTimeVersionNumber: metadata.UIKitRunTimeVersionNumber,
|
|
83
|
+
}
|
|
84
|
+
: undefined,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
return Array(settings.renderers.length).fill(snapshot);
|
|
53
88
|
}
|
|
54
|
-
exports.
|
|
89
|
+
exports.takeSnapshots = takeSnapshots;
|
|
@@ -0,0 +1,95 @@
|
|
|
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.makeReqBroker = void 0;
|
|
27
|
+
const req_1 = __importStar(require("@applitools/req"));
|
|
28
|
+
function makeReqBroker({ config, logger }) {
|
|
29
|
+
return (0, req_1.makeReq)({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
'User-Agent': config.agentId,
|
|
34
|
+
},
|
|
35
|
+
proxy: config.proxy,
|
|
36
|
+
timeout: 300000 /* 5min */,
|
|
37
|
+
retry: {
|
|
38
|
+
limit: 5,
|
|
39
|
+
timeout: 200,
|
|
40
|
+
codes: ['ECONNRESET', 'ECONNABORTED', 'ETIMEDOUT', 'ENOTFOUND', 'EAI_AGAIN'],
|
|
41
|
+
},
|
|
42
|
+
hooks: [handleLogs({ logger }), handleLongRequests({ req: req_1.default }), handleUnexpectedResponse()],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.makeReqBroker = makeReqBroker;
|
|
46
|
+
function handleLogs({ logger: defaultLogger } = {}) {
|
|
47
|
+
return {
|
|
48
|
+
beforeRequest({ request, options }) {
|
|
49
|
+
var _a;
|
|
50
|
+
const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : defaultLogger;
|
|
51
|
+
logger === null || logger === void 0 ? void 0 : logger.log(`Broker request "${options.name}" will be sent to the address "[${request.method}]${request.url}" with body`, options.body);
|
|
52
|
+
},
|
|
53
|
+
async afterResponse({ request, response, options }) {
|
|
54
|
+
var _a;
|
|
55
|
+
const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : defaultLogger;
|
|
56
|
+
logger === null || logger === void 0 ? void 0 : logger.log(`Broker request "${options.name}" that was sent to the address "[${request.method}]${request.url}" respond with ${response.statusText}(${response.status})`, response.status !== 200 ? `and body ${JSON.stringify(await response.clone().text())}` : '');
|
|
57
|
+
},
|
|
58
|
+
afterError({ request, error, options }) {
|
|
59
|
+
var _a;
|
|
60
|
+
const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : defaultLogger;
|
|
61
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`Broker request "${options.name}" that was sent to the address "[${request.method}]${request.url}" failed with error`, error);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function handleLongRequests({ req }) {
|
|
66
|
+
return {
|
|
67
|
+
async afterResponse({ request, response, options }) {
|
|
68
|
+
if (response.status === 200) {
|
|
69
|
+
return req(request.url + '-response', {
|
|
70
|
+
proxy: options.proxy,
|
|
71
|
+
retry: { statuses: [404] },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function handleUnexpectedResponse() {
|
|
78
|
+
return {
|
|
79
|
+
async afterResponse({ response }) {
|
|
80
|
+
var _a;
|
|
81
|
+
if (response.status !== 200) {
|
|
82
|
+
throw new Error(`Something went wrong when communicating with the mobile application, please try running your test again (error code: ${response.status})`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const body = await response.text();
|
|
86
|
+
const result = JSON.parse(body);
|
|
87
|
+
if ((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.error) {
|
|
88
|
+
const error = result.payload.error;
|
|
89
|
+
throw new Error(`There was a problem when interacting with the mobile application. The provided error message was "${error.message}" and had a stack trace of "${error.stack}"`);
|
|
90
|
+
}
|
|
91
|
+
return new req_1.Response(body, response);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/nml-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Client to integrate the SDKs to the Native Mobile Library (NML)",
|
|
5
5
|
"homepage": "https://applitools.com",
|
|
6
6
|
"bugs": {
|
|
@@ -46,13 +46,15 @@
|
|
|
46
46
|
"postversion": "bongo postversion --skip-release-notification"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@applitools/
|
|
50
|
-
"@applitools/
|
|
49
|
+
"@applitools/logger": "1.1.17",
|
|
50
|
+
"@applitools/req": "1.1.2",
|
|
51
|
+
"@applitools/types": "1.5.10",
|
|
52
|
+
"@applitools/utils": "1.3.11"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@applitools/bongo": "^2.2.0",
|
|
54
56
|
"@applitools/scripts": "^1.1.0",
|
|
55
|
-
"@applitools/spec-driver-selenium": "^1.3.
|
|
57
|
+
"@applitools/spec-driver-selenium": "^1.3.19",
|
|
56
58
|
"@applitools/test-server": "^1.1.4",
|
|
57
59
|
"@applitools/test-utils": "^1.5.1",
|
|
58
60
|
"@types/mocha": "^9.1.1",
|
package/types/client.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { Selector, Renderer } from '@applitools/types';
|
|
2
|
+
import type { Screenshot, ScreenshotSettings as ClassicScreenshotSettings } from '@applitools/types/classic';
|
|
3
|
+
import type { AndroidVHS, IOSVHS } from '@applitools/types/ufg';
|
|
4
|
+
import { type Logger } from '@applitools/logger';
|
|
5
|
+
import { type ReqBrokerConfig } from './req-broker';
|
|
6
|
+
export declare type ScreenshotSettings = ReqBrokerConfig & ClassicScreenshotSettings<never, never> & {
|
|
7
|
+
name?: string;
|
|
8
|
+
selectorsToFindRegionsFor?: Selector[];
|
|
9
|
+
};
|
|
10
|
+
export declare type SnapshotSettings = ReqBrokerConfig & {
|
|
11
|
+
name?: string;
|
|
12
|
+
renderers: Renderer[];
|
|
13
|
+
resourceSeparation?: boolean;
|
|
14
|
+
waitBeforeCapture?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function takeScreenshot({ url, settings, logger, }: {
|
|
17
|
+
url: string;
|
|
18
|
+
settings: ScreenshotSettings;
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
}): Promise<Screenshot>;
|
|
21
|
+
export declare function takeSnapshots({ url, settings, logger, }: {
|
|
22
|
+
url: string;
|
|
23
|
+
settings: SnapshotSettings;
|
|
24
|
+
logger?: Logger;
|
|
25
|
+
}): Promise<IOSVHS[] | AndroidVHS[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Proxy } from '@applitools/types';
|
|
2
|
+
import { type Logger } from '@applitools/logger';
|
|
3
|
+
import { type Req, type Options } from '@applitools/req';
|
|
4
|
+
export declare type ReqBrokerConfig = {
|
|
5
|
+
proxy?: Proxy;
|
|
6
|
+
agentId?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type ReqBrokerOptions = Options & {
|
|
9
|
+
name: string;
|
|
10
|
+
body: {
|
|
11
|
+
protocolVersion: '1.0';
|
|
12
|
+
name: string;
|
|
13
|
+
key: string;
|
|
14
|
+
payload: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
};
|
|
18
|
+
export declare type ReqBroker = Req<ReqBrokerOptions>;
|
|
19
|
+
export declare function makeReqBroker({ config, logger }: {
|
|
20
|
+
config: ReqBrokerConfig;
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
}): Req<ReqBrokerOptions>;
|
package/dist/broker.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.broker = exports.publishMessageRequest = void 0;
|
|
4
|
-
const req_1 = require("@applitools/req");
|
|
5
|
-
async function publishMessageRequest(options) {
|
|
6
|
-
const response = await (0, req_1.req)(options.url, {
|
|
7
|
-
method: 'POST',
|
|
8
|
-
body: options.payload,
|
|
9
|
-
headers: { 'Content-Type': 'application/json' },
|
|
10
|
-
proxy: options.proxy,
|
|
11
|
-
hooks: {
|
|
12
|
-
afterResponse: async (response) => {
|
|
13
|
-
if (response.response.status != 200)
|
|
14
|
-
return;
|
|
15
|
-
return (0, req_1.req)(options.url + '-response', {
|
|
16
|
-
retry: [{ statuses: [404] }],
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
if (response.status !== 200) {
|
|
22
|
-
throw new Error(`something went wrong when communicating with the mobile application, please try running your test again (error code: ${response.status})`);
|
|
23
|
-
}
|
|
24
|
-
return response;
|
|
25
|
-
}
|
|
26
|
-
exports.publishMessageRequest = publishMessageRequest;
|
|
27
|
-
async function broker(url, request, options) {
|
|
28
|
-
const response = await publishMessageRequest({
|
|
29
|
-
url,
|
|
30
|
-
payload: request,
|
|
31
|
-
...options,
|
|
32
|
-
});
|
|
33
|
-
const { payload } = await response.json();
|
|
34
|
-
if (!payload || (payload && payload.error))
|
|
35
|
-
throw new Error(`There was a problem when interacting with the mobile application. The provided error message was "${payload.error.message}" and had a stack trace of "${payload.error.stack}"`);
|
|
36
|
-
return payload.result;
|
|
37
|
-
}
|
|
38
|
-
exports.broker = broker;
|
package/types/broker.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare function publishMessageRequest(options: {
|
|
2
|
-
url: string;
|
|
3
|
-
payload: any;
|
|
4
|
-
proxy?: any;
|
|
5
|
-
}): Promise<any>;
|
|
6
|
-
declare type CommonSelector = {
|
|
7
|
-
type: string;
|
|
8
|
-
selector: string;
|
|
9
|
-
};
|
|
10
|
-
export declare type ScreenshotSettings = {
|
|
11
|
-
name?: string;
|
|
12
|
-
screenshotMode?: 'FULL_RESIZE' | 'FULL_SCROLL' | 'VIEWPORT' | 'FULL_REGION';
|
|
13
|
-
scrollRootElement?: CommonSelector;
|
|
14
|
-
selectorsToFindRegionsFor?: Array<CommonSelector>;
|
|
15
|
-
hideCaret?: boolean;
|
|
16
|
-
waitBeforeCapture?: number;
|
|
17
|
-
overlap?: {
|
|
18
|
-
top: number;
|
|
19
|
-
bottom: number;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export declare type SnapshotSettings = {
|
|
23
|
-
name?: string;
|
|
24
|
-
deviceList?: any;
|
|
25
|
-
resourceSeparation?: boolean;
|
|
26
|
-
waitBeforeCapture?: number;
|
|
27
|
-
};
|
|
28
|
-
export interface BrokerRequest {
|
|
29
|
-
protocolVersion: '1.0';
|
|
30
|
-
name: 'TAKE_SCREENSHOT' | 'TAKE_SNAPSHOT';
|
|
31
|
-
key: string;
|
|
32
|
-
payload: ScreenshotSettings | SnapshotSettings;
|
|
33
|
-
}
|
|
34
|
-
export declare function broker(url: string, request: BrokerRequest, options?: any): Promise<any>;
|
|
35
|
-
export {};
|