@mablhq/mabl-cli 1.12.9 → 1.12.38
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/api/basicApiClient.js +1 -1
- package/api/mablApiClient.js +9 -9
- package/auth/AuthClient.js +1 -4
- package/browserLauncher/browserLauncher.js +3 -1
- package/browserLauncher/browserLauncherFactory.js +6 -2
- package/browserLauncher/elementHandle.js +8 -1
- package/browserLauncher/frame.js +15 -0
- package/browserLauncher/frameBase.js +4 -0
- package/browserLauncher/playwrightBrowserLauncher/playwrightBrowser.js +2 -2
- package/browserLauncher/playwrightBrowserLauncher/playwrightBrowserLauncher.js +1 -0
- package/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +119 -31
- package/browserLauncher/playwrightBrowserLauncher/playwrightFrame.js +32 -21
- package/browserLauncher/playwrightBrowserLauncher/playwrightHttpResponse.js +3 -0
- package/browserLauncher/playwrightBrowserLauncher/playwrightPage.js +43 -75
- package/browserLauncher/playwrightBrowserLauncher/wrappers.js +1 -1
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerBrowser.js +3 -3
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerElementHandle.js +59 -5
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerFrame.js +9 -8
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerHttpRequest.js +1 -1
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerHttpResponse.js +4 -1
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerJsHandle.js +3 -3
- package/browserLauncher/puppeteerBrowserLauncher/puppeteerPage.js +23 -61
- package/browserLauncher/puppeteerBrowserLauncher/wrappers.js +1 -1
- package/cli.js +6 -4
- package/commands/applications/applications_cmds/list.js +1 -1
- package/commands/branches/branches_cmds/create.js +1 -1
- package/commands/branches/branches_cmds/list.js +1 -1
- package/commands/branches/branches_cmds/merge.js +1 -1
- package/commands/commandUtil/awaitCompletion.js +2 -2
- package/commands/commandUtil/codeInsights.js +6 -6
- package/commands/commandUtil/fileUtil.js +1 -1
- package/commands/commandUtil/util.js +12 -12
- package/commands/config/config_cmds/list.js +1 -1
- package/commands/constants.js +1 -1
- package/commands/credentials/credentials_cmds/list.js +1 -1
- package/commands/deploy/deploy_cmds/create.js +2 -2
- package/commands/deploy/deploy_cmds/executionResultPresenter.js +7 -7
- package/commands/deploy/deploy_cmds/list.js +1 -1
- package/commands/environments/environments_cmds/create.js +3 -3
- package/commands/environments/environments_cmds/list.js +1 -1
- package/commands/environments/environments_cmds/urls_cmds/add.js +1 -1
- package/commands/flows/flows_cmds/list.js +1 -1
- package/commands/plans/plans_cmds/list.js +1 -1
- package/commands/test-runs/test-runs_cmds/export.js +1 -1
- package/commands/tests/executionUtil.js +1 -1
- package/commands/tests/testsUtil.js +16 -20
- package/commands/tests/tests_cmds/edit.js +1 -1
- package/commands/tests/tests_cmds/export.js +1 -1
- package/commands/tests/tests_cmds/import.js +13 -13
- package/commands/tests/tests_cmds/list.js +2 -2
- package/commands/tests/tests_cmds/run-alpha.js +1 -1
- package/commands/tests/tests_cmds/run-cloud.js +7 -7
- package/commands/tests/tests_cmds/run-legacy.js +2 -2
- package/commands/tests/tests_cmds/run.js +25 -7
- package/commands/workspaces/workspace_cmds/copy.js +1 -1
- package/commands/workspaces/workspace_cmds/list.js +1 -1
- package/configGenerators/flowConfigGenerator.js +3 -3
- package/configGenerators/selIdeGenerator.js +1 -1
- package/configGenerators/testConfigGenerator.js +7 -8
- package/core/execution/ApiTestUtils.js +2 -2
- package/core/messaging/messaging.js +14 -1
- package/core/trainer/openUtils.js +47 -0
- package/core/trainer/trainingSessions.js +36 -61
- package/env/defaultEnv.js +2 -1
- package/env/dev.js +2 -1
- package/env/env.js +3 -1
- package/env/local.js +2 -1
- package/env/prod.js +2 -1
- package/execution/index.js +1 -1
- package/index.d.ts +7 -0
- package/mablApi/index.js +1 -1
- package/mablscript/MablStep.js +11 -7
- package/mablscript/actions/ConditionAction.js +2 -4
- package/mablscript/actions/FindAction.js +4 -4
- package/mablscript/importer.js +16 -14
- package/mablscript/steps/AccessibilityCheck.js +88 -0
- package/mablscript/steps/AssertStep.js +6 -5
- package/mablscript/steps/CreateVariableStep.js +2 -3
- package/mablscript/steps/DownloadStep.js +1 -2
- package/mablscript/steps/EnterTextStep.js +2 -1
- package/mablscript/steps/IfConditionStep.js +3 -3
- package/mablscript/steps/SendHttpRequestStep.js +2 -2
- package/mablscript/steps/SendKeyStep.js +2 -2
- package/mablscript/steps/SetFilesStep.js +1 -1
- package/mablscript/steps/SwitchContextStep.js +2 -1
- package/mablscript/types/AccessibilityCheckStepDescriptor.js +2 -0
- package/mablscript/types/AccessibilityCheckTypes.js +9 -0
- package/mablscript/types/VariableDataType.js +1 -8
- package/mablscript/types/VariableNamespace.js +1 -1
- package/mablscriptFind/index.js +1 -1
- package/package.json +6 -4
- package/popupDismissal/index.js +13 -12
- package/providers/authenticationProvider.js +2 -3
- package/providers/cliConfigProvider.js +1 -1
- package/providers/exportRequestProvider.js +1 -1
- package/providers/logging/loggingProvider.js +2 -2
- package/providers/scmContextProvider.js +1 -1
- package/reporters/mochAwesome/mochAwesomeReporter.js +10 -6
- package/reporters/reporter.js +1 -1
- package/resources/mablFind.js +1 -1
- package/resources/popupDismissal.js +1 -1
- package/util/RichPromise.js +2 -2
- package/util/actionabilityUtil.js +44 -14
- package/util/downloadUtil.js +1 -1
- package/util/logUtils.js +20 -1
- package/util/markdownUtil.js +3 -3
- package/util/pureUtil.js +6 -6
- package/util/resourceUtil.js +14 -1
- package/core/trainer/trainerBrowserUtil.js +0 -33
package/api/basicApiClient.js
CHANGED
|
@@ -129,7 +129,7 @@ class BasicApiClient {
|
|
|
129
129
|
maxRetryTime: (_h = (_g = this.retryConfig) === null || _g === void 0 ? void 0 : _g.maxRetryTimeMillis) !== null && _h !== void 0 ? _h : DEFAULT_MAX_TOTAL_RETRY_TIME_MILLISECONDS,
|
|
130
130
|
forever: false,
|
|
131
131
|
};
|
|
132
|
-
return async_retry_1.default(async (bail) => requestFunc().catch(error => {
|
|
132
|
+
return async_retry_1.default(async (bail) => requestFunc().catch((error) => {
|
|
133
133
|
var _a, _b;
|
|
134
134
|
const statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
135
135
|
if (statusCode === 429 ||
|
package/api/mablApiClient.js
CHANGED
|
@@ -67,7 +67,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
67
67
|
organization_id: workspaceId,
|
|
68
68
|
limit,
|
|
69
69
|
});
|
|
70
|
-
const applications = await this.makeGetRequest(`${env_1.BASE_API_URL}/applications?${applicationQueryString}`).then(result => { var _a; return (_a = result.applications) !== null && _a !== void 0 ? _a : []; });
|
|
70
|
+
const applications = await this.makeGetRequest(`${env_1.BASE_API_URL}/applications?${applicationQueryString}`).then((result) => { var _a; return (_a = result.applications) !== null && _a !== void 0 ? _a : []; });
|
|
71
71
|
sortTemporallyAscending(applications);
|
|
72
72
|
return applications;
|
|
73
73
|
}
|
|
@@ -117,7 +117,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
117
117
|
organization_id: workspaceId,
|
|
118
118
|
limit,
|
|
119
119
|
});
|
|
120
|
-
const environments = await this.makeGetRequest(`${env_1.BASE_API_URL}/v1/environments/?${environmentQueryString}`).then(result => { var _a; return (_a = result.environments) !== null && _a !== void 0 ? _a : []; });
|
|
120
|
+
const environments = await this.makeGetRequest(`${env_1.BASE_API_URL}/v1/environments/?${environmentQueryString}`).then((result) => { var _a; return (_a = result.environments) !== null && _a !== void 0 ? _a : []; });
|
|
121
121
|
sortTemporallyAscending(environments);
|
|
122
122
|
return environments;
|
|
123
123
|
}
|
|
@@ -170,7 +170,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
170
170
|
organization_id: workspaceId,
|
|
171
171
|
limit,
|
|
172
172
|
});
|
|
173
|
-
return await this.makeGetRequest(`${env_1.BASE_API_URL}/credentials?${credentialsQueryString}`).then(result => { var _a; return (_a = result.credentials) !== null && _a !== void 0 ? _a : []; });
|
|
173
|
+
return await this.makeGetRequest(`${env_1.BASE_API_URL}/credentials?${credentialsQueryString}`).then((result) => { var _a; return (_a = result.credentials) !== null && _a !== void 0 ? _a : []; });
|
|
174
174
|
}
|
|
175
175
|
catch (error) {
|
|
176
176
|
throw toApiError(`Failed to get credentials`, error);
|
|
@@ -190,7 +190,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
190
190
|
workspace_id: workspaceId,
|
|
191
191
|
limit,
|
|
192
192
|
});
|
|
193
|
-
return await this.makeGetRequest(`${env_1.BASE_API_URL}/events/deployment?${deploymentQueryString}`).then(result => { var _a; return (_a = result.deployments) !== null && _a !== void 0 ? _a : []; });
|
|
193
|
+
return await this.makeGetRequest(`${env_1.BASE_API_URL}/events/deployment?${deploymentQueryString}`).then((result) => { var _a; return (_a = result.deployments) !== null && _a !== void 0 ? _a : []; });
|
|
194
194
|
}
|
|
195
195
|
catch (error) {
|
|
196
196
|
throw toApiError(`Failed to get deployment events`, error);
|
|
@@ -245,7 +245,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
245
245
|
}
|
|
246
246
|
async getTestOverrides(testId, environmentId, selectorOverrideLimit = 10) {
|
|
247
247
|
try {
|
|
248
|
-
return await this.makeGetRequest(`${env_1.BASE_API_URL}/tests/testScripts/${testId}/overrides?environment_id=${environmentId}&selector_override_limit=${selectorOverrideLimit}`).then(result => { var _a; return (_a = result.overrides) !== null && _a !== void 0 ? _a : []; });
|
|
248
|
+
return await this.makeGetRequest(`${env_1.BASE_API_URL}/tests/testScripts/${testId}/overrides?environment_id=${environmentId}&selector_override_limit=${selectorOverrideLimit}`).then((result) => { var _a; return (_a = result.overrides) !== null && _a !== void 0 ? _a : []; });
|
|
249
249
|
}
|
|
250
250
|
catch (error) {
|
|
251
251
|
throw toApiError(`Failed to get selector overrides`, error);
|
|
@@ -271,7 +271,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
271
271
|
var _a, _b;
|
|
272
272
|
try {
|
|
273
273
|
const userInfo = await this.getSelf();
|
|
274
|
-
const requests = (_b = (_a = userInfo.roles) === null || _a === void 0 ? void 0 : _a.slice(0, limit).map(role => this.getWorkspace(role.organization_id))) !== null && _b !== void 0 ? _b : [];
|
|
274
|
+
const requests = (_b = (_a = userInfo.roles) === null || _a === void 0 ? void 0 : _a.slice(0, limit).map((role) => this.getWorkspace(role.organization_id))) !== null && _b !== void 0 ? _b : [];
|
|
275
275
|
const workspaces = await Promise.all(requests);
|
|
276
276
|
sortTemporallyAscending(workspaces);
|
|
277
277
|
return workspaces;
|
|
@@ -406,7 +406,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
406
406
|
limit,
|
|
407
407
|
status: statusFilter,
|
|
408
408
|
});
|
|
409
|
-
return await this.makeGetRequest(`${env_1.BASE_API_URL}/branch?${branchQueryString}`).then(result => { var _a; return (_a = result.branches) !== null && _a !== void 0 ? _a : []; });
|
|
409
|
+
return await this.makeGetRequest(`${env_1.BASE_API_URL}/branch?${branchQueryString}`).then((result) => { var _a; return (_a = result.branches) !== null && _a !== void 0 ? _a : []; });
|
|
410
410
|
}
|
|
411
411
|
catch (error) {
|
|
412
412
|
throw toApiError(`Failed to get Branches`, error);
|
|
@@ -422,7 +422,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
422
422
|
}
|
|
423
423
|
async getDatatableRows(datatableId) {
|
|
424
424
|
try {
|
|
425
|
-
return await this.makeGetRequest(`${env_1.BASE_API_URL}/variables/tables/${datatableId}/rows`).then(result => { var _a; return (_a = result.variableRows) !== null && _a !== void 0 ? _a : []; });
|
|
425
|
+
return await this.makeGetRequest(`${env_1.BASE_API_URL}/variables/tables/${datatableId}/rows`).then((result) => { var _a; return (_a = result.variableRows) !== null && _a !== void 0 ? _a : []; });
|
|
426
426
|
}
|
|
427
427
|
catch (error) {
|
|
428
428
|
throw toApiError(`Failed to get datatable rows`, error);
|
|
@@ -537,7 +537,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
537
537
|
planOverrides.deployment_ids = options.deploymentIds;
|
|
538
538
|
}
|
|
539
539
|
if ((_h = options.httpHeaders) === null || _h === void 0 ? void 0 : _h.length) {
|
|
540
|
-
planOverrides.http_headers = options.httpHeaders.map(header => {
|
|
540
|
+
planOverrides.http_headers = options.httpHeaders.map((header) => {
|
|
541
541
|
const parts = header.split(':', 2);
|
|
542
542
|
return {
|
|
543
543
|
name: parts[0],
|
package/auth/AuthClient.js
CHANGED
|
@@ -22,10 +22,7 @@ class AuthClient {
|
|
|
22
22
|
.replace(/=/g, '');
|
|
23
23
|
}
|
|
24
24
|
sha256(input) {
|
|
25
|
-
return crypto_1.default
|
|
26
|
-
.createHash('sha256')
|
|
27
|
-
.update(input)
|
|
28
|
-
.digest();
|
|
25
|
+
return crypto_1.default.createHash('sha256').update(input).digest();
|
|
29
26
|
}
|
|
30
27
|
buildAuthorizationUrl(codeChallenge, redirectUri, idpType) {
|
|
31
28
|
const loginQueryString = query_string_1.default.stringify({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LifecycleEvent = exports.BrowserLauncherFactory = exports.TimeoutError = exports.RunnerError = exports.RUNNER_ERRORS = exports.PageEvent = exports.BrowserEvent = void 0;
|
|
3
|
+
exports.LifecycleEvent = exports.BrowserLauncherFactory = exports.Frame = exports.TimeoutError = exports.RunnerError = exports.RUNNER_ERRORS = exports.PageEvent = exports.BrowserEvent = void 0;
|
|
4
4
|
var browserEvent_1 = require("./browserEvent");
|
|
5
5
|
Object.defineProperty(exports, "BrowserEvent", { enumerable: true, get: function () { return browserEvent_1.BrowserEvent; } });
|
|
6
6
|
var pageEvent_1 = require("./pageEvent");
|
|
@@ -9,6 +9,8 @@ var errors_1 = require("./errors");
|
|
|
9
9
|
Object.defineProperty(exports, "RUNNER_ERRORS", { enumerable: true, get: function () { return errors_1.RUNNER_ERRORS; } });
|
|
10
10
|
Object.defineProperty(exports, "RunnerError", { enumerable: true, get: function () { return errors_1.RunnerError; } });
|
|
11
11
|
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
12
|
+
var frame_1 = require("./frame");
|
|
13
|
+
Object.defineProperty(exports, "Frame", { enumerable: true, get: function () { return frame_1.Frame; } });
|
|
12
14
|
var browserLauncherFactory_1 = require("./browserLauncherFactory");
|
|
13
15
|
Object.defineProperty(exports, "BrowserLauncherFactory", { enumerable: true, get: function () { return browserLauncherFactory_1.BrowserLauncherFactory; } });
|
|
14
16
|
var types_1 = require("./types");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.BrowserLauncherFactory = void 0;
|
|
4
7
|
const puppeteerBrowserLauncher_1 = require("./puppeteerBrowserLauncher/puppeteerBrowserLauncher");
|
|
@@ -6,6 +9,7 @@ const playwrightBrowserLauncher_1 = require("./playwrightBrowserLauncher/playwri
|
|
|
6
9
|
const runnerType_1 = require("./runnerType");
|
|
7
10
|
const logUtils_1 = require("../util/logUtils");
|
|
8
11
|
const loggingProvider_1 = require("../providers/logging/loggingProvider");
|
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
13
|
class BrowserLauncherFactory {
|
|
10
14
|
static getRunnerFromEnvironment() {
|
|
11
15
|
var _a;
|
|
@@ -16,10 +20,10 @@ class BrowserLauncherFactory {
|
|
|
16
20
|
const runner = runnerFromEnv ? runnerFromEnv : runnerType;
|
|
17
21
|
loggerFunc = loggerFunc !== null && loggerFunc !== void 0 ? loggerFunc : ((line) => logUtils_1.logCliOutput(loggingProvider_1.LogLevel.Info, line));
|
|
18
22
|
if (runner === runnerType_1.RunnerType.Playwright) {
|
|
19
|
-
loggerFunc(
|
|
23
|
+
loggerFunc(chalk_1.default.cyan(`Browser launcher:`, chalk_1.default.magenta('Playwright')));
|
|
20
24
|
return new playwrightBrowserLauncher_1.PlaywrightBrowserLauncher();
|
|
21
25
|
}
|
|
22
|
-
loggerFunc(
|
|
26
|
+
loggerFunc(chalk_1.default.cyan(`Browser launcher:`, chalk_1.default.magenta('Puppeteer')));
|
|
23
27
|
return new puppeteerBrowserLauncher_1.PuppeteerBrowserLauncher();
|
|
24
28
|
}
|
|
25
29
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isElementHandle = void 0;
|
|
3
|
+
exports.isElementHandle = exports.getHighlightColor = exports.MAX_HIGHLIGHT_OPACITY = void 0;
|
|
4
|
+
exports.MAX_HIGHLIGHT_OPACITY = 0.9;
|
|
5
|
+
exports.getHighlightColor = (transparency) => ({
|
|
6
|
+
r: 196,
|
|
7
|
+
g: 68,
|
|
8
|
+
b: 183,
|
|
9
|
+
a: transparency,
|
|
10
|
+
});
|
|
4
11
|
function isElementHandle(value) {
|
|
5
12
|
return (value &&
|
|
6
13
|
typeof value === 'object' &&
|
package/browserLauncher/frame.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Frame = void 0;
|
|
4
|
+
const frameBase_1 = require("./frameBase");
|
|
5
|
+
const loggingProvider_1 = require("../providers/logging/loggingProvider");
|
|
6
|
+
class Frame extends frameBase_1.FrameBase {
|
|
7
|
+
getFrameId() {
|
|
8
|
+
const frameId = this.id();
|
|
9
|
+
if (typeof frameId !== 'string' ||
|
|
10
|
+
frameId.length < 20 ||
|
|
11
|
+
frameId.length > 40) {
|
|
12
|
+
loggingProvider_1.logger.warn(`Warning: The frame ID value is unexpected. It was: ${frameId}`);
|
|
13
|
+
}
|
|
14
|
+
return frameId;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Frame = Frame;
|
|
@@ -73,12 +73,12 @@ class PlaywrightBrowser extends events_1.default {
|
|
|
73
73
|
async pages() {
|
|
74
74
|
return Promise.all(this.getDefaultContext()
|
|
75
75
|
.pages()
|
|
76
|
-
.map(page => this.getOrCreatePage(page)));
|
|
76
|
+
.map((page) => this.getOrCreatePage(page)));
|
|
77
77
|
}
|
|
78
78
|
async getExtensionBackgroundPage(extensionId) {
|
|
79
79
|
const backgroundExtensionPage = this.defaultContext
|
|
80
80
|
.backgroundPages()
|
|
81
|
-
.find(page => page.url().includes(extensionId));
|
|
81
|
+
.find((page) => page.url().includes(extensionId));
|
|
82
82
|
if (!backgroundExtensionPage) {
|
|
83
83
|
throw new Error('mabl test initialization failure, unable to locate mabl extension page, please try again');
|
|
84
84
|
}
|
|
@@ -31,6 +31,7 @@ class PlaywrightBrowserLauncher {
|
|
|
31
31
|
viewport,
|
|
32
32
|
acceptDownloads: true,
|
|
33
33
|
httpCredentials: options.credentials,
|
|
34
|
+
extraHTTPHeaders: options.extraHttpHeaders,
|
|
34
35
|
isMobile: (_a = options.defaultDeviceDescriptor) === null || _a === void 0 ? void 0 : _a.isMobile,
|
|
35
36
|
deviceScaleFactor: (_b = options.defaultDeviceDescriptor) === null || _b === void 0 ? void 0 : _b.deviceScaleFactor,
|
|
36
37
|
hasTouch: (_c = options.defaultDeviceDescriptor) === null || _c === void 0 ? void 0 : _c.hasTouch,
|
|
@@ -19,10 +19,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.PlaywrightElementHandle = exports.PlaywrightJsHandle = void 0;
|
|
22
|
+
exports.PlaywrightElementHandle = exports.PlaywrightJsHandle = exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS = void 0;
|
|
23
23
|
const playwright = __importStar(require("@playwright/test"));
|
|
24
24
|
const utils_1 = require("../utils");
|
|
25
25
|
const logUtils_1 = require("../../util/logUtils");
|
|
26
|
+
const elementHandle_1 = require("../elementHandle");
|
|
27
|
+
const testsUtil_1 = require("../../commands/tests/testsUtil");
|
|
28
|
+
exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS = 30000;
|
|
26
29
|
class PlaywrightJsHandle {
|
|
27
30
|
constructor(handle, page) {
|
|
28
31
|
this.handle = handle;
|
|
@@ -39,55 +42,72 @@ class PlaywrightJsHandle {
|
|
|
39
42
|
}
|
|
40
43
|
async evaluateHandle(code, arg) {
|
|
41
44
|
const handle = await this.handle.evaluateHandle(code, PlaywrightJsHandle.unwrapProperties(arg));
|
|
42
|
-
return utils_1.mapIfNotNull(handle, handle => handle.asElement()
|
|
45
|
+
return utils_1.mapIfNotNull(handle, (handle) => handle.asElement()
|
|
43
46
|
? new PlaywrightElementHandle(handle.asElement(), this.page)
|
|
44
47
|
: new PlaywrightJsHandle(handle, this.page));
|
|
45
48
|
}
|
|
46
49
|
async getProperty(propertyName) {
|
|
47
|
-
return utils_1.mapIfNotNull(await this.handle.getProperty(propertyName), handle => new PlaywrightJsHandle(handle, this.page));
|
|
50
|
+
return utils_1.mapIfNotNull(await this.handle.getProperty(propertyName), (handle) => new PlaywrightJsHandle(handle, this.page));
|
|
48
51
|
}
|
|
49
52
|
jsonValue() {
|
|
50
53
|
return this.handle.jsonValue();
|
|
51
54
|
}
|
|
52
55
|
static unwrapProperties(arg, addSecondaryWorldFlag = false) {
|
|
53
56
|
if (arg === undefined) {
|
|
54
|
-
return addSecondaryWorldFlag ? {
|
|
57
|
+
return addSecondaryWorldFlag ? { secondaryWorldValue: undefined } : null;
|
|
55
58
|
}
|
|
56
|
-
if (addSecondaryWorldFlag &&
|
|
57
|
-
(arg instanceof PlaywrightJsHandle || typeof arg !== 'object')) {
|
|
59
|
+
if (addSecondaryWorldFlag && arg instanceof PlaywrightJsHandle) {
|
|
58
60
|
throw new Error('Unable to setup the secondary world if the argument is a JsHandle. Pass an object instead');
|
|
59
61
|
}
|
|
62
|
+
let result = arg;
|
|
60
63
|
if (arg instanceof PlaywrightJsHandle) {
|
|
61
|
-
|
|
64
|
+
result = arg.getPlaywrightHandle();
|
|
62
65
|
}
|
|
63
|
-
if (typeof arg !== 'object')
|
|
64
|
-
|
|
66
|
+
else if ((typeof arg !== 'object' || Array.isArray(arg)) &&
|
|
67
|
+
!addSecondaryWorldFlag) {
|
|
68
|
+
result = arg;
|
|
65
69
|
}
|
|
66
|
-
if (
|
|
67
|
-
arg.
|
|
70
|
+
else if (typeof arg === 'object' &&
|
|
71
|
+
!Object.keys(arg).some((key) => arg[key] instanceof PlaywrightJsHandle)) {
|
|
72
|
+
result = arg;
|
|
68
73
|
}
|
|
69
|
-
if (typeof arg === 'object' &&
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
else if (typeof arg === 'object' && !Array.isArray(arg)) {
|
|
75
|
+
const unwrapped = { ...arg };
|
|
76
|
+
Object.keys(arg).forEach((propertyName) => {
|
|
77
|
+
const propertyValue = unwrapped[propertyName];
|
|
78
|
+
if (propertyValue instanceof PlaywrightJsHandle) {
|
|
79
|
+
unwrapped[propertyName] = propertyValue.getPlaywrightHandle();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
result = unwrapped;
|
|
72
83
|
}
|
|
73
|
-
|
|
74
|
-
Object.keys(arg).forEach(propertyName => {
|
|
75
|
-
const propertyValue = unwrapped[propertyName];
|
|
76
|
-
if (propertyValue instanceof PlaywrightJsHandle) {
|
|
77
|
-
unwrapped[propertyName] = propertyValue.getPlaywrightHandle();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return unwrapped;
|
|
84
|
+
return addSecondaryWorldFlag ? { secondaryWorldValue: result } : result;
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
exports.PlaywrightJsHandle = PlaywrightJsHandle;
|
|
84
88
|
class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
85
89
|
constructor(element, page) {
|
|
90
|
+
var _a, _b, _c, _d, _e, _f;
|
|
86
91
|
super(element, page);
|
|
87
92
|
this.element = element;
|
|
88
93
|
this.page = page;
|
|
89
94
|
try {
|
|
90
95
|
this.elementImpl = playwright._toImpl(this.element);
|
|
96
|
+
this.cdpSession = (_c = (_b = (_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a._context) === null || _b === void 0 ? void 0 : _b._delegate) === null || _c === void 0 ? void 0 : _c._client;
|
|
97
|
+
if (this.elementImpl === undefined) {
|
|
98
|
+
logUtils_1.logInternal(`Unable to get the Element's internal implementation.
|
|
99
|
+
Some functionality, such as getting the clickable point or element highlighting might not work.`);
|
|
100
|
+
}
|
|
101
|
+
else if (this.cdpSession === undefined) {
|
|
102
|
+
const undefinedField = ((_e = (_d = this.elementImpl) === null || _d === void 0 ? void 0 : _d._context) === null || _e === void 0 ? void 0 : _e._delegate) !== undefined
|
|
103
|
+
? '_client'
|
|
104
|
+
: ((_f = this.elementImpl) === null || _f === void 0 ? void 0 : _f._context) !== undefined
|
|
105
|
+
? '_delegate'
|
|
106
|
+
: '_context';
|
|
107
|
+
logUtils_1.logInternal(`Unable to get the CDP Session of the element handle.
|
|
108
|
+
${undefinedField} is undefined.
|
|
109
|
+
Some functionality, such as element highlighting will not work.`);
|
|
110
|
+
}
|
|
91
111
|
}
|
|
92
112
|
catch (e) {
|
|
93
113
|
logUtils_1.logInternal(`Unable to get the element handle's implementation. Error: ${e}`);
|
|
@@ -97,13 +117,13 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
97
117
|
return this.element.setInputFiles(filePath);
|
|
98
118
|
}
|
|
99
119
|
async $x(xpathQuery) {
|
|
100
|
-
return (await this.element.$$(`xpath=${xpathQuery}`)).map(element => new PlaywrightElementHandle(element, this.page));
|
|
120
|
+
return (await this.element.$$(`xpath=${xpathQuery}`)).map((element) => new PlaywrightElementHandle(element, this.page));
|
|
101
121
|
}
|
|
102
122
|
asElement() {
|
|
103
|
-
return utils_1.mapIfNotNull(this.handle.asElement(), handle => new PlaywrightElementHandle(handle, this.page));
|
|
123
|
+
return utils_1.mapIfNotNull(this.handle.asElement(), (handle) => new PlaywrightElementHandle(handle, this.page));
|
|
104
124
|
}
|
|
105
125
|
async boundingBox() {
|
|
106
|
-
return utils_1.mapIfNotNull(await this.element.boundingBox(), boundingBox => boundingBox);
|
|
126
|
+
return utils_1.mapIfNotNull(await this.element.boundingBox(), (boundingBox) => boundingBox);
|
|
107
127
|
}
|
|
108
128
|
click(options) {
|
|
109
129
|
var _a, _b;
|
|
@@ -125,13 +145,13 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
125
145
|
return clickablePoint;
|
|
126
146
|
}
|
|
127
147
|
async contentFrame() {
|
|
128
|
-
return utils_1.mapIfNotNull(await this.element.contentFrame(), frame => this.page.getOrCreateFrame(frame));
|
|
148
|
+
return utils_1.mapIfNotNull(await this.element.contentFrame(), (frame) => this.page.getOrCreateFrame(frame));
|
|
129
149
|
}
|
|
130
150
|
focus() {
|
|
131
151
|
return this.element.focus();
|
|
132
152
|
}
|
|
133
153
|
async frame() {
|
|
134
|
-
return utils_1.mapIfNotNull(await this.element.ownerFrame(), frame => this.page.getOrCreateFrame(frame));
|
|
154
|
+
return utils_1.mapIfNotNull(await this.element.ownerFrame(), (frame) => this.page.getOrCreateFrame(frame));
|
|
135
155
|
}
|
|
136
156
|
hover() {
|
|
137
157
|
return this.element.hover();
|
|
@@ -142,16 +162,84 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
142
162
|
select(value) {
|
|
143
163
|
return this.element.selectOption(value);
|
|
144
164
|
}
|
|
145
|
-
async type(text) {
|
|
165
|
+
async type(text, options) {
|
|
166
|
+
const timeout = PlaywrightElementHandle.getTypeTimeout(text, options);
|
|
146
167
|
await this.element.focus();
|
|
147
|
-
await this.element.selectText();
|
|
148
|
-
return this.element.type(text
|
|
168
|
+
await this.element.selectText({ force: true });
|
|
169
|
+
return this.element.type(text, {
|
|
170
|
+
delay: options === null || options === void 0 ? void 0 : options.delay,
|
|
171
|
+
timeout,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
static getTypeTimeout(text, options) {
|
|
175
|
+
var _a;
|
|
176
|
+
let timeout;
|
|
177
|
+
const newTimeout = text.length * ((_a = options === null || options === void 0 ? void 0 : options.delay) !== null && _a !== void 0 ? _a : 1) * 2;
|
|
178
|
+
if (newTimeout > exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS) {
|
|
179
|
+
timeout = newTimeout;
|
|
180
|
+
}
|
|
181
|
+
return timeout;
|
|
149
182
|
}
|
|
150
183
|
press(key) {
|
|
151
184
|
return this.element.press(key);
|
|
152
185
|
}
|
|
153
186
|
getRemoteObjectId() {
|
|
154
|
-
|
|
187
|
+
var _a, _b, _c;
|
|
188
|
+
if (((_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a._objectId) === undefined) {
|
|
189
|
+
logUtils_1.logInternal('ObjectId of an element handle was not found.');
|
|
190
|
+
}
|
|
191
|
+
return (_c = (_b = this.elementImpl) === null || _b === void 0 ? void 0 : _b._objectId) !== null && _c !== void 0 ? _c : '';
|
|
192
|
+
}
|
|
193
|
+
async highlight(highlightDurationMillis, highlightPhases) {
|
|
194
|
+
await this.enableDom();
|
|
195
|
+
await this.enableOverlay();
|
|
196
|
+
const nodeInfo = await this.makeCdpCall('DOM.describeNode', {
|
|
197
|
+
objectId: this.getRemoteObjectId(),
|
|
198
|
+
depth: -1,
|
|
199
|
+
pierce: true,
|
|
200
|
+
});
|
|
201
|
+
const highlightConfig = {
|
|
202
|
+
backendNodeId: nodeInfo.node.backendNodeId,
|
|
203
|
+
highlightConfig: {
|
|
204
|
+
borderColor: elementHandle_1.getHighlightColor(0),
|
|
205
|
+
contentColor: elementHandle_1.getHighlightColor(1),
|
|
206
|
+
colorFormat: 'rgb',
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
await this.fadeInOutHighlight(highlightConfig, highlightDurationMillis, highlightPhases);
|
|
210
|
+
await this.hideHighlight();
|
|
211
|
+
}
|
|
212
|
+
async getValue() {
|
|
213
|
+
return this.element.inputValue();
|
|
214
|
+
}
|
|
215
|
+
async fadeInOutHighlight(highlightConfig, highlightDurationMillis, highlightPhases) {
|
|
216
|
+
var _a;
|
|
217
|
+
if (highlightPhases <= 0) {
|
|
218
|
+
throw new Error('Highlight phases must be greater than 0');
|
|
219
|
+
}
|
|
220
|
+
const phaseIntervalMilliseconds = highlightDurationMillis / highlightPhases;
|
|
221
|
+
for (let iteration = 0; iteration < highlightPhases; iteration++) {
|
|
222
|
+
if (((_a = highlightConfig.highlightConfig.contentColor) === null || _a === void 0 ? void 0 : _a.a) !== undefined) {
|
|
223
|
+
const x = iteration / highlightPhases;
|
|
224
|
+
highlightConfig.highlightConfig.contentColor.a =
|
|
225
|
+
x * (1 - x) * 4 * elementHandle_1.MAX_HIGHLIGHT_OPACITY;
|
|
226
|
+
}
|
|
227
|
+
await this.makeCdpCall('Overlay.highlightNode', highlightConfig);
|
|
228
|
+
await testsUtil_1.sleep(phaseIntervalMilliseconds);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async enableDom() {
|
|
232
|
+
await this.makeCdpCall('DOM.enable');
|
|
233
|
+
}
|
|
234
|
+
async enableOverlay() {
|
|
235
|
+
await this.makeCdpCall('Overlay.enable');
|
|
236
|
+
}
|
|
237
|
+
async hideHighlight() {
|
|
238
|
+
await this.makeCdpCall('Overlay.hideHighlight');
|
|
239
|
+
}
|
|
240
|
+
async makeCdpCall(method, paramArgs) {
|
|
241
|
+
var _a;
|
|
242
|
+
return ((_a = this.cdpSession) !== null && _a !== void 0 ? _a : (await this.page.getCdpSession())).send(method, paramArgs);
|
|
155
243
|
}
|
|
156
244
|
}
|
|
157
245
|
exports.PlaywrightElementHandle = PlaywrightElementHandle;
|
|
@@ -27,8 +27,11 @@ const playwrightHttpResponse_1 = require("./playwrightHttpResponse");
|
|
|
27
27
|
const playwrightDom_1 = require("./playwrightDom");
|
|
28
28
|
const testsUtil_1 = require("../../commands/tests/testsUtil");
|
|
29
29
|
const WAIT_FOR_CONTEXT_TIMEOUT = 1000;
|
|
30
|
-
|
|
30
|
+
const MAIN_CONTEXT = 'main';
|
|
31
|
+
const UTILITY_CONTEXT = 'utility';
|
|
32
|
+
class PlaywrightFrame extends browserLauncher_1.Frame {
|
|
31
33
|
constructor(frame, parentPage) {
|
|
34
|
+
super();
|
|
32
35
|
this.frame = frame;
|
|
33
36
|
this.parentPage = parentPage;
|
|
34
37
|
this.injectSecondaryWorld();
|
|
@@ -36,61 +39,69 @@ class PlaywrightFrame {
|
|
|
36
39
|
injectSecondaryWorld() {
|
|
37
40
|
const serverFrame = this.getFrameImpl();
|
|
38
41
|
serverFrame.checkWorldFunction = async function (arg) {
|
|
39
|
-
let forcedWorld =
|
|
42
|
+
let forcedWorld = MAIN_CONTEXT;
|
|
40
43
|
if (this.utilityWorldAvailable === undefined) {
|
|
41
44
|
await Promise.race([
|
|
42
|
-
this._contextData.get(
|
|
45
|
+
this._contextData.get(UTILITY_CONTEXT).contextPromise,
|
|
43
46
|
testsUtil_1.sleep(WAIT_FOR_CONTEXT_TIMEOUT),
|
|
44
47
|
]);
|
|
45
48
|
this.utilityWorldAvailable =
|
|
46
|
-
this._contextData.get(
|
|
49
|
+
this._contextData.get(UTILITY_CONTEXT).context !== null;
|
|
47
50
|
}
|
|
48
|
-
if (
|
|
49
|
-
forcedWorld =
|
|
50
|
-
|
|
51
|
+
if (arg === null || arg === void 0 ? void 0 : arg.hasOwnProperty('secondaryWorldValue')) {
|
|
52
|
+
forcedWorld = UTILITY_CONTEXT;
|
|
53
|
+
if (!this.utilityWorldAvailable) {
|
|
54
|
+
this._contextData.set(UTILITY_CONTEXT, this._contextData.get(MAIN_CONTEXT));
|
|
55
|
+
this.utilityWorldAvailable = true;
|
|
56
|
+
}
|
|
57
|
+
arg = arg.secondaryWorldValue;
|
|
51
58
|
}
|
|
52
|
-
return forcedWorld;
|
|
59
|
+
return { world: forcedWorld, value: arg };
|
|
53
60
|
};
|
|
54
61
|
const originalEvaluateExpressionFunction = serverFrame.evaluateExpressionAndWaitForSignals.bind(serverFrame);
|
|
55
62
|
const functionOverride = async function (expression, isFunction, arg, _world) {
|
|
56
|
-
|
|
63
|
+
const { world, value } = await this.checkWorldFunction(arg);
|
|
64
|
+
return originalEvaluateExpressionFunction(expression, isFunction, value, world);
|
|
57
65
|
};
|
|
58
|
-
serverFrame.evaluateExpressionAndWaitForSignals =
|
|
66
|
+
serverFrame.evaluateExpressionAndWaitForSignals =
|
|
67
|
+
functionOverride.bind(serverFrame);
|
|
59
68
|
const originalEvaluateExpressionHandleFunction = serverFrame.evaluateExpressionHandleAndWaitForSignals.bind(serverFrame);
|
|
60
69
|
const functionHandleOverride = async function (expression, isFunction, arg, _world) {
|
|
61
|
-
|
|
70
|
+
const { world, value } = await this.checkWorldFunction(arg);
|
|
71
|
+
return originalEvaluateExpressionHandleFunction(expression, isFunction, value, world);
|
|
62
72
|
};
|
|
63
|
-
serverFrame.evaluateExpressionHandleAndWaitForSignals =
|
|
73
|
+
serverFrame.evaluateExpressionHandleAndWaitForSignals =
|
|
74
|
+
functionHandleOverride.bind(serverFrame);
|
|
64
75
|
}
|
|
65
76
|
async $(selector) {
|
|
66
|
-
return utils_1.mapIfNotNull(await this.frame.$(selector), handle => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
77
|
+
return utils_1.mapIfNotNull(await this.frame.$(selector), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
67
78
|
}
|
|
68
79
|
async $$(selector) {
|
|
69
80
|
const maybePlaywrightHandles = await this.frame.$$(selector);
|
|
70
81
|
if (!maybePlaywrightHandles.length) {
|
|
71
82
|
return [];
|
|
72
83
|
}
|
|
73
|
-
return maybePlaywrightHandles.map(handle => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
84
|
+
return maybePlaywrightHandles.map((handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
74
85
|
}
|
|
75
86
|
async $$eval(selector, pageFunction, ...args) {
|
|
76
|
-
const result = await this.frame.$$eval(selector, pageFunction, ...args === null || args === void 0 ? void 0 : args.map(argument => argument instanceof playwrightDom_1.PlaywrightJsHandle
|
|
87
|
+
const result = await this.frame.$$eval(selector, pageFunction, ...args === null || args === void 0 ? void 0 : args.map((argument) => argument instanceof playwrightDom_1.PlaywrightJsHandle
|
|
77
88
|
? argument.getPlaywrightHandle()
|
|
78
89
|
: argument));
|
|
79
90
|
return result;
|
|
80
91
|
}
|
|
81
92
|
async $eval(selector, pageFunction, ...args) {
|
|
82
|
-
const result = await this.frame.$eval(selector, pageFunction, ...args === null || args === void 0 ? void 0 : args.map(argument => argument instanceof playwrightDom_1.PlaywrightJsHandle
|
|
93
|
+
const result = await this.frame.$eval(selector, pageFunction, ...args === null || args === void 0 ? void 0 : args.map((argument) => argument instanceof playwrightDom_1.PlaywrightJsHandle
|
|
83
94
|
? argument.getPlaywrightHandle()
|
|
84
95
|
: argument));
|
|
85
96
|
return result;
|
|
86
97
|
}
|
|
87
98
|
async $x(xpathQuery) {
|
|
88
|
-
return (await this.frame.$$(`xpath=${xpathQuery}`)).map(element => new playwrightDom_1.PlaywrightElementHandle(element, this.parentPage));
|
|
99
|
+
return (await this.frame.$$(`xpath=${xpathQuery}`)).map((element) => new playwrightDom_1.PlaywrightElementHandle(element, this.parentPage));
|
|
89
100
|
}
|
|
90
101
|
childFrames() {
|
|
91
102
|
return this.frame
|
|
92
103
|
.childFrames()
|
|
93
|
-
.map(frame => this.parentPage.getOrCreateFrame(frame));
|
|
104
|
+
.map((frame) => this.parentPage.getOrCreateFrame(frame));
|
|
94
105
|
}
|
|
95
106
|
evaluate(pageFunction, arg, addSecondaryWorldFlag = false) {
|
|
96
107
|
return this.frame.evaluate(pageFunction, playwrightDom_1.PlaywrightJsHandle.unwrapProperties(arg, addSecondaryWorldFlag));
|
|
@@ -107,7 +118,7 @@ class PlaywrightFrame {
|
|
|
107
118
|
async goto(url, options) {
|
|
108
119
|
try {
|
|
109
120
|
const response = await this.frame.goto(url, options);
|
|
110
|
-
return utils_1.mapIfNotNull(response, response => new playwrightHttpResponse_1.PlaywrightHttpResponse(this.parentPage, response));
|
|
121
|
+
return utils_1.mapIfNotNull(response, (response) => new playwrightHttpResponse_1.PlaywrightHttpResponse(this.parentPage, response));
|
|
111
122
|
}
|
|
112
123
|
catch (e) {
|
|
113
124
|
if (e instanceof playwright.errors.TimeoutError) {
|
|
@@ -123,13 +134,13 @@ class PlaywrightFrame {
|
|
|
123
134
|
return this.frame.name();
|
|
124
135
|
}
|
|
125
136
|
parentFrame() {
|
|
126
|
-
return utils_1.mapIfNotNull(this.frame.parentFrame(), frame => this.parentPage.getOrCreateFrame(frame));
|
|
137
|
+
return utils_1.mapIfNotNull(this.frame.parentFrame(), (frame) => this.parentPage.getOrCreateFrame(frame));
|
|
127
138
|
}
|
|
128
139
|
url() {
|
|
129
140
|
return this.frame.url();
|
|
130
141
|
}
|
|
131
142
|
async waitForSelector(selector, options) {
|
|
132
|
-
return utils_1.mapIfNotNull(await this.frame.waitForSelector(selector, options), handle => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
143
|
+
return utils_1.mapIfNotNull(await this.frame.waitForSelector(selector, options), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
|
|
133
144
|
}
|
|
134
145
|
page() {
|
|
135
146
|
return this.parentPage;
|