@testim/testim-cli 3.289.0 → 3.290.1-beta
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/cli.js +22390 -122
- package/cli.js.map +1 -0
- package/npm-shrinkwrap.json +1169 -12846
- package/package.json +16 -10
- package/OverrideTestDataBuilder.js +0 -117
- package/agent/routers/cliJsCode/index.js +0 -13
- package/agent/routers/cliJsCode/router.js +0 -63
- package/agent/routers/cliJsCode/service.js +0 -705
- package/agent/routers/codim/router.js +0 -69
- package/agent/routers/codim/router.test.js +0 -60
- package/agent/routers/codim/service.js +0 -193
- package/agent/routers/general/index.js +0 -36
- package/agent/routers/hybrid/registerRoutes.js +0 -81
- package/agent/routers/index.js +0 -56
- package/agent/routers/playground/router.js +0 -77
- package/agent/routers/playground/service.js +0 -96
- package/agent/routers/standalone-browser/registerRoutes.js +0 -47
- package/agent/server.js +0 -150
- package/cdpTestRunner.js +0 -86
- package/chromiumInstaller.js +0 -91
- package/cli/isCiRun.js +0 -10
- package/cli/onExit.js +0 -65
- package/cli/writeStackTrace.js +0 -27
- package/cliAgentMode.js +0 -384
- package/codim/codim-cli.js +0 -91
- package/codim/codim-npm-package/index.ts +0 -427
- package/codim/codim-npm-package/package-lock.json +0 -14
- package/codim/codim-npm-package/package.json +0 -14
- package/codim/hybrid-utils.js +0 -28
- package/codim/measure-perf.js +0 -41
- package/codim/template.js/.idea/workspace.xml +0 -57
- package/codim/template.js/.vscode/launch.json +0 -53
- package/codim/template.ts/.idea/workspace.xml +0 -57
- package/codim/template.ts/.vscode/launch.json +0 -55
- package/commons/AbortError.js +0 -12
- package/commons/SeleniumPerfStats.js +0 -58
- package/commons/chrome-launcher.js +0 -15
- package/commons/chromedriverWrapper.js +0 -70
- package/commons/config.js +0 -39
- package/commons/constants.js +0 -67
- package/commons/detectDebugger.js +0 -19
- package/commons/featureAvailabilityService.js +0 -26
- package/commons/featureFlags.js +0 -132
- package/commons/getSessionPlayerRequire.js +0 -28
- package/commons/httpRequest.js +0 -261
- package/commons/httpRequestCounters.js +0 -98
- package/commons/httpRequestCounters.test.js +0 -38
- package/commons/initializeUserWithAuth.js +0 -55
- package/commons/lazyRequire.js +0 -105
- package/commons/logUtils.js +0 -15
- package/commons/logUtils.test.js +0 -21
- package/commons/logger.js +0 -178
- package/commons/mockNetworkRuleFileSchema.json +0 -140
- package/commons/npmWrapper.js +0 -174
- package/commons/npmWrapper.test.js +0 -374
- package/commons/performance-logger.js +0 -71
- package/commons/preloadTests.js +0 -29
- package/commons/prepareRunner.js +0 -85
- package/commons/prepareRunner.test.js +0 -144
- package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
- package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
- package/commons/requireWithFallback.js +0 -25
- package/commons/runnerFileCache.js +0 -204
- package/commons/socket/baseSocketServiceSocketIO.js +0 -197
- package/commons/socket/realDataService.js +0 -59
- package/commons/socket/realDataServiceSocketIO.js +0 -33
- package/commons/socket/remoteStepService.js +0 -55
- package/commons/socket/remoteStepServiceSocketIO.js +0 -61
- package/commons/socket/socketService.js +0 -175
- package/commons/socket/testResultService.js +0 -62
- package/commons/socket/testResultServiceSocketIO.js +0 -64
- package/commons/testimAnalytics.js +0 -40
- package/commons/testimCloudflare.js +0 -83
- package/commons/testimCloudflare.test.js +0 -185
- package/commons/testimCustomToken.js +0 -124
- package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
- package/commons/testimNgrok.js +0 -90
- package/commons/testimNgrok.test.js +0 -140
- package/commons/testimServicesApi.js +0 -631
- package/commons/testimTunnel.js +0 -73
- package/commons/testimTunnel.test.js +0 -172
- package/commons/xhr2.js +0 -897
- package/coverage/SummaryToObjectReport.js +0 -19
- package/coverage/jsCoverage.js +0 -252
- package/credentialsManager.js +0 -142
- package/errors.js +0 -161
- package/executionQueue.js +0 -37
- package/fixLocalBuild.js +0 -24
- package/inputFileUtils.js +0 -103
- package/lib/coralogix-winston.transport.js +0 -99
- package/player/SeleniumProtocolError.js +0 -100
- package/player/WebDriverHttpRequest.js +0 -177
- package/player/WebdriverioWebDriverApi.js +0 -671
- package/player/appiumTestPlayer.js +0 -90
- package/player/chromeLauncherTestPlayer.js +0 -67
- package/player/constants.js +0 -332
- package/player/extensionTestPlayer.js +0 -32
- package/player/findElementStrategy.js +0 -154
- package/player/scripts/isElementDisplayed.js +0 -252
- package/player/seleniumTestPlayer.js +0 -140
- package/player/services/frameLocator.js +0 -170
- package/player/services/mobileFrameLocatorMock.js +0 -32
- package/player/services/playbackTimeoutCalculator.js +0 -175
- package/player/services/portSelector.js +0 -19
- package/player/services/tabService.js +0 -551
- package/player/services/tabServiceMock.js +0 -167
- package/player/services/windowCreationListener.js +0 -8
- package/player/stepActions/RefreshStepAction.js +0 -16
- package/player/stepActions/apiStepAction.js +0 -89
- package/player/stepActions/baseCliJsStepAction.js +0 -51
- package/player/stepActions/baseJsStepAction.js +0 -277
- package/player/stepActions/cliConditionStepAction.js +0 -11
- package/player/stepActions/cliJsStepAction.js +0 -11
- package/player/stepActions/dropFileStepAction.js +0 -34
- package/player/stepActions/evaluateExpressionStepAction.js +0 -52
- package/player/stepActions/extensionOnlyStepAction.js +0 -12
- package/player/stepActions/extractTextStepAction.js +0 -19
- package/player/stepActions/hoverStepAction.js +0 -55
- package/player/stepActions/inputFileStepAction.js +0 -199
- package/player/stepActions/jsCodeStepAction.js +0 -11
- package/player/stepActions/jsConditionStepAction.js +0 -11
- package/player/stepActions/locateStepAction.js +0 -159
- package/player/stepActions/mouseStepAction.js +0 -370
- package/player/stepActions/navigationStepAction.js +0 -29
- package/player/stepActions/nodePackageStepAction.js +0 -47
- package/player/stepActions/pixelValidationStepAction.js +0 -39
- package/player/stepActions/scripts/dispatchEvents.js +0 -282
- package/player/stepActions/scripts/doClick.js +0 -221
- package/player/stepActions/scripts/doDragPath.js +0 -225
- package/player/stepActions/scripts/doubleClick.js +0 -119
- package/player/stepActions/scripts/dropEvent.js +0 -63
- package/player/stepActions/scripts/focusElement.js +0 -46
- package/player/stepActions/scripts/html5dragAction.js +0 -56
- package/player/stepActions/scripts/html5dragActionV2.js +0 -312
- package/player/stepActions/scripts/runCode.js +0 -147
- package/player/stepActions/scripts/scroll.js +0 -90
- package/player/stepActions/scripts/selectOption.js +0 -51
- package/player/stepActions/scripts/setText.js +0 -415
- package/player/stepActions/scripts/wheel.js +0 -61
- package/player/stepActions/scrollStepAction.js +0 -96
- package/player/stepActions/selectOptionStepAction.js +0 -49
- package/player/stepActions/sfdcRecordedStepAction.js +0 -24
- package/player/stepActions/sfdcStepAction.js +0 -28
- package/player/stepActions/sleepStepAction.js +0 -12
- package/player/stepActions/specialKeyStepAction.js +0 -52
- package/player/stepActions/stepAction.js +0 -73
- package/player/stepActions/stepActionRegistrar.js +0 -111
- package/player/stepActions/submitStepAction.js +0 -12
- package/player/stepActions/tdkHybridStepAction.js +0 -18
- package/player/stepActions/textStepAction.js +0 -110
- package/player/stepActions/textValidationStepAction.js +0 -64
- package/player/stepActions/wheelStepAction.js +0 -41
- package/player/utils/cookieUtils.js +0 -39
- package/player/utils/eyeSdkService.js +0 -250
- package/player/utils/imageCaptureUtils.js +0 -267
- package/player/utils/screenshotUtils.js +0 -68
- package/player/utils/stepActionUtils.js +0 -90
- package/player/utils/windowUtils.js +0 -195
- package/player/webDriverUtils.js +0 -40
- package/player/webDriverUtils.test.js +0 -116
- package/player/webdriver.js +0 -976
- package/polyfills/Array.prototype.at.js +0 -13
- package/polyfills/index.js +0 -13
- package/processHandler.js +0 -79
- package/processHandler.test.js +0 -55
- package/reports/chromeReporter.js +0 -17
- package/reports/consoleReporter.js +0 -190
- package/reports/debugReporter.js +0 -82
- package/reports/jsonReporter.js +0 -55
- package/reports/junitReporter.js +0 -183
- package/reports/reporter.js +0 -166
- package/reports/reporterUtils.js +0 -54
- package/reports/teamCityReporter.js +0 -73
- package/runOptions.d.ts +0 -305
- package/runOptions.js +0 -1288
- package/runOptionsAgentFlow.js +0 -87
- package/runOptionsUtils.js +0 -60
- package/runner.js +0 -355
- package/runners/ParallelWorkerManager.js +0 -284
- package/runners/TestPlanRunner.js +0 -419
- package/runners/buildCodeTests.js +0 -159
- package/runners/runnerUtils.js +0 -81
- package/services/analyticsService.js +0 -96
- package/services/branchService.js +0 -29
- package/services/gridService.js +0 -357
- package/services/gridService.test.js +0 -357
- package/services/labFeaturesService.js +0 -64
- package/services/lambdatestService.js +0 -227
- package/services/lambdatestService.test.js +0 -353
- package/services/localRCASaver.js +0 -124
- package/stepPlayers/cliJsStepPlayback.js +0 -40
- package/stepPlayers/hybridStepPlayback.js +0 -140
- package/stepPlayers/nodePackageStepPlayback.js +0 -28
- package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
- package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
- package/stepPlayers/remoteStepPlayback.js +0 -80
- package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
- package/stepPlayers/tdkHybridStepPlayback.js +0 -112
- package/testRunHandler.js +0 -603
- package/testRunStatus.js +0 -567
- package/testimNpmDriver.js +0 -52
- package/utils/argsUtils.js +0 -91
- package/utils/argsUtils.test.js +0 -32
- package/utils/fsUtils.js +0 -174
- package/utils/index.js +0 -197
- package/utils/promiseUtils.js +0 -85
- package/utils/stringUtils.js +0 -98
- package/utils/stringUtils.test.js +0 -22
- package/utils/timeUtils.js +0 -25
- package/utils/utils.test.js +0 -27
- package/workers/BaseWorker.js +0 -498
- package/workers/BaseWorker.test.js +0 -186
- package/workers/WorkerAppium.js +0 -180
- package/workers/WorkerExtension.js +0 -192
- package/workers/WorkerExtensionSingleBrowser.js +0 -77
- package/workers/WorkerSelenium.js +0 -253
- package/workers/workerUtils.js +0 -20
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const service = require('../agent/routers/cliJsCode/service');
|
|
4
|
-
const { NpmPackageError } = require('../errors');
|
|
5
|
-
const utils = require('../utils');
|
|
6
|
-
|
|
7
|
-
module.exports.run = async (browser, step) => {
|
|
8
|
-
const { stepId, testResultId, retryIndex, stepResultId, packageData, timeout } = step.data;
|
|
9
|
-
try {
|
|
10
|
-
const data = await service.installPackage(stepId, testResultId, retryIndex, packageData, stepResultId, timeout);
|
|
11
|
-
return { data, success: true };
|
|
12
|
-
} catch (err) {
|
|
13
|
-
if (err instanceof NpmPackageError) {
|
|
14
|
-
return {
|
|
15
|
-
success: false,
|
|
16
|
-
code: 'invalid-node-package',
|
|
17
|
-
message: err.message,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
if (err instanceof utils.TimeoutError) {
|
|
21
|
-
return {
|
|
22
|
-
success: false,
|
|
23
|
-
code: 'timeout',
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const lazyRequire = require('../commons/lazyRequire');
|
|
4
|
-
const { AbortError } = require('../commons/AbortError');
|
|
5
|
-
const { last } = require('lodash');
|
|
6
|
-
const { getArgumentsFromContext } = require('../codim/hybrid-utils');
|
|
7
|
-
|
|
8
|
-
module.exports.execute = async function executePlaywrightFunction(player, hybridFunction, step, testimContext, source, abortSignal) {
|
|
9
|
-
let onAbort;
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const playwright = await lazyRequire('playwright');
|
|
13
|
-
|
|
14
|
-
if (abortSignal.aborted) {
|
|
15
|
-
throw new AbortError();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const browser = await playwright.chromium.connect({
|
|
19
|
-
wsEndpoint: player.driver.cdpUrl,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (abortSignal.aborted) {
|
|
23
|
-
browser.disconnect();
|
|
24
|
-
throw new AbortError();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
onAbort = function onAbort() {
|
|
28
|
-
// this will make any future browser action to fail
|
|
29
|
-
browser.disconnect();
|
|
30
|
-
}
|
|
31
|
-
abortSignal.addEventListener("abort", onAbort);
|
|
32
|
-
|
|
33
|
-
//TODO(Benji) https://github.com/microsoft/playwright/issues/1985
|
|
34
|
-
|
|
35
|
-
const playwrightContext = await browser.newContext({viewport: null })
|
|
36
|
-
const pages = await playwrightContext.pages();
|
|
37
|
-
const page = last(pages);
|
|
38
|
-
function getLocator(arg) {
|
|
39
|
-
return page.$(arg.selector);
|
|
40
|
-
}
|
|
41
|
-
const args = await getArgumentsFromContext(step, testimContext, getLocator);
|
|
42
|
-
const fn = hybridFunction.bind(null, page, ...args);
|
|
43
|
-
|
|
44
|
-
await fn();
|
|
45
|
-
return { success: true }
|
|
46
|
-
} catch (e) {
|
|
47
|
-
if (abortSignal.aborted) {
|
|
48
|
-
return { success: false, shouldRetry: false, reason: "aborted" };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
success: false,
|
|
53
|
-
reason: (e && e.message || e) ,
|
|
54
|
-
extraInfo: e && e.constructor && e.constructor.name
|
|
55
|
-
};
|
|
56
|
-
} finally {
|
|
57
|
-
if (onAbort) {
|
|
58
|
-
abortSignal.removeEventListener("abort", onAbort);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const lazyRequire = require('../commons/lazyRequire');
|
|
4
|
-
const { AbortError } = require('../commons/AbortError');
|
|
5
|
-
const { last } = require("lodash");
|
|
6
|
-
const { getArgumentsFromContext } = require('../codim/hybrid-utils');
|
|
7
|
-
|
|
8
|
-
module.exports.execute = async function executePuppeteerFunction(player, hybridFunction, step, context, source, abortSignal) {
|
|
9
|
-
let onAbort;
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
/**
|
|
13
|
-
* @type {typeof import("puppeteer")}
|
|
14
|
-
*/
|
|
15
|
-
const puppeteer = await lazyRequire('puppeteer');
|
|
16
|
-
|
|
17
|
-
if (abortSignal.aborted) {
|
|
18
|
-
throw new AbortError();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const browser = await puppeteer.connect({
|
|
22
|
-
browserWSEndpoint: player.driver.cdpUrl,
|
|
23
|
-
defaultViewport: null, // disable puppeteer resize
|
|
24
|
-
product: 'chrome', //
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (abortSignal.aborted) {
|
|
28
|
-
browser.disconnect();
|
|
29
|
-
throw new AbortError();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onAbort = function onAbort() {
|
|
33
|
-
// this will make puppeteer action to fail
|
|
34
|
-
browser.disconnect();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
abortSignal.addEventListener("abort", onAbort);
|
|
38
|
-
|
|
39
|
-
const pages = await browser.pages();
|
|
40
|
-
let foundMainPage;
|
|
41
|
-
|
|
42
|
-
for (const page of pages) {
|
|
43
|
-
if (await page.evaluate(function () {
|
|
44
|
-
return window.__isMainTestimTab;
|
|
45
|
-
})) {
|
|
46
|
-
foundMainPage = page;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const page = foundMainPage ? foundMainPage : last(pages);
|
|
52
|
-
function getLocator(arg) {
|
|
53
|
-
return page.$(arg.selector);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const args = await getArgumentsFromContext(step, context, getLocator);
|
|
57
|
-
const fn = hybridFunction.bind(null, page, ...args);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
await fn();
|
|
61
|
-
return { success: true }
|
|
62
|
-
} catch (e) {
|
|
63
|
-
if (abortSignal.aborted) {
|
|
64
|
-
return { success: false, shouldRetry: false, reason: "aborted" };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
success: false,
|
|
69
|
-
shouldRetry: false,
|
|
70
|
-
reason: (e && e.message || e),
|
|
71
|
-
extraInfo: e && e.constructor && e.constructor.name
|
|
72
|
-
};
|
|
73
|
-
} finally {
|
|
74
|
-
abortSignal.removeEventListener("abort", onAbort);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const cliJsStepPlayback = require('./cliJsStepPlayback');
|
|
4
|
-
const hybridStepPlayback = require('./hybridStepPlayback');
|
|
5
|
-
const nodePackageStepPlayback = require('./nodePackageStepPlayback');
|
|
6
|
-
const testimServicesApi = require('../commons/testimServicesApi');
|
|
7
|
-
const { getLogger } = require('../commons/logger');
|
|
8
|
-
|
|
9
|
-
const logger = getLogger('step-playback');
|
|
10
|
-
|
|
11
|
-
const playbacks = {
|
|
12
|
-
'cli-validation-code-step': cliJsStepPlayback,
|
|
13
|
-
'cli-wait-for-code-step': cliJsStepPlayback,
|
|
14
|
-
'cli-action-code-step': cliJsStepPlayback,
|
|
15
|
-
'cli-api-code-step': cliJsStepPlayback,
|
|
16
|
-
'cli-condition-step': cliJsStepPlayback,
|
|
17
|
-
'cli-download-code-step': cliJsStepPlayback,
|
|
18
|
-
'node-package': nodePackageStepPlayback,
|
|
19
|
-
'tdk-hybrid': hybridStepPlayback,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
async function saveRemoteStep(projectId, resultId, stepId, remoteStepData) {
|
|
23
|
-
try {
|
|
24
|
-
return await testimServicesApi.saveRemoteStep(projectId, resultId, stepId, remoteStepData);
|
|
25
|
-
} catch (e) {
|
|
26
|
-
logger.error('failed to report remote step state', { projectId, resultId, stepId });
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function onCompleted(projectId, resultId, stepId, runResult, sessionId) {
|
|
32
|
-
logger.info('finished to run remote step', { stepId, sessionId });
|
|
33
|
-
const remoteStepData = {
|
|
34
|
-
status: 'completed',
|
|
35
|
-
success: true,
|
|
36
|
-
failureReason: null,
|
|
37
|
-
data: runResult,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return await saveRemoteStep(projectId, resultId, stepId, remoteStepData);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function onFailed(projectId, resultId, stepId, failureReason, sessionId) {
|
|
44
|
-
logger.info('failed to run remote step', { stepId, sessionId, failureReason });
|
|
45
|
-
const remoteStepData = {
|
|
46
|
-
status: 'completed',
|
|
47
|
-
success: false,
|
|
48
|
-
failureReason,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return await saveRemoteStep(projectId, resultId, stepId, remoteStepData);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function executeStep(options, driver, step, resultId) {
|
|
55
|
-
if (!step?.type || step.status === 'completed') {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { project: projectId, projectData, userData } = options;
|
|
60
|
-
const stepType = step.type;
|
|
61
|
-
const sessionId = driver.getSessionId();
|
|
62
|
-
const stepId = step.id;
|
|
63
|
-
logger.info('start play remote step', { stepType, stepId, sessionId });
|
|
64
|
-
|
|
65
|
-
const playback = playbacks[stepType];
|
|
66
|
-
if (!playback) {
|
|
67
|
-
return await onFailed(projectId, resultId, stepId, `Failed to find step type ${stepType}`, sessionId);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const runResult = await playback.run(driver, step, projectData, userData);
|
|
72
|
-
return await onCompleted(projectId, resultId, stepId, runResult, sessionId);
|
|
73
|
-
} catch (err) {
|
|
74
|
-
return await onFailed(projectId, resultId, stepId, err.message, sessionId);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = {
|
|
79
|
-
executeStep,
|
|
80
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const lazyRequire = require('../commons/lazyRequire');
|
|
4
|
-
const { getArgumentsFromContext } = require('../codim/hybrid-utils');
|
|
5
|
-
|
|
6
|
-
module.exports.execute = async function executeSeleniumFunction(player, hybridFunction, step, context, source, abortSignal) {
|
|
7
|
-
let onAbort;
|
|
8
|
-
|
|
9
|
-
// with selenium - we don't have any instrumentation - so we just run the code.
|
|
10
|
-
try {
|
|
11
|
-
// selenium hybrid test
|
|
12
|
-
/**
|
|
13
|
-
* @type {import("selenium-webdriver")}
|
|
14
|
-
*/
|
|
15
|
-
const { WebDriver } = await lazyRequire('selenium-webdriver');
|
|
16
|
-
|
|
17
|
-
if (abortSignal.aborted) {
|
|
18
|
-
throw new AbortError();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { Executor, HttpClient } = require('selenium-webdriver/http');
|
|
22
|
-
|
|
23
|
-
const webdriverOptions = player.driver.client.requestHandler.defaultOptions;
|
|
24
|
-
const startPath = player.driver.client.requestHandler.startPath;
|
|
25
|
-
const seleniumServerUrl = `${webdriverOptions.protocol}://${webdriverOptions.hostname}:${webdriverOptions.port}`;
|
|
26
|
-
const seleniumUrl = seleniumServerUrl + startPath; // we do not add startPath since selenium-webdriver adds /wd/hub on its own + startPath;
|
|
27
|
-
const client = new HttpClient(seleniumUrl);
|
|
28
|
-
const webDriver = new WebDriver(player.getSessionId() , new Executor(client));
|
|
29
|
-
|
|
30
|
-
// find main tab
|
|
31
|
-
await fixSeleniumMainTab(webDriver, player.driver);
|
|
32
|
-
|
|
33
|
-
function getLocator(arg) {
|
|
34
|
-
return webDriver.findElement({ css: arg.selector });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const args = await getArgumentsFromContext(step, context, getLocator);
|
|
38
|
-
const fn = hybridFunction.bind(null, webDriver, ...args);
|
|
39
|
-
|
|
40
|
-
onAbort = function onAbort() {
|
|
41
|
-
// We don't have real way to abort user code,
|
|
42
|
-
// So we kill the http client of the WebDriver
|
|
43
|
-
client.send = async function send() {
|
|
44
|
-
throw new AbortError();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
abortSignal.addEventListener("abort", onAbort);
|
|
48
|
-
|
|
49
|
-
await fn();
|
|
50
|
-
return { success: true };
|
|
51
|
-
} catch (e) {
|
|
52
|
-
if (abortSignal.aborted) {
|
|
53
|
-
return { success: false, shouldRetry: false, reason: "aborted" };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
success: false,
|
|
58
|
-
shouldRetry: false,
|
|
59
|
-
reason: (e && e.message || e),
|
|
60
|
-
extraInfo: e && e.constructor && e.constructor.name
|
|
61
|
-
};
|
|
62
|
-
} finally {
|
|
63
|
-
if (onAbort) {
|
|
64
|
-
abortSignal.removeEventListener("abort", onAbort);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
async function fixSeleniumMainTab(webDriver, driver) {
|
|
70
|
-
if (!driver.cdpUrl) {
|
|
71
|
-
// remote run
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
{
|
|
75
|
-
const contexts = await webDriver.getAllWindowHandles();
|
|
76
|
-
for(const context of contexts) {
|
|
77
|
-
await webDriver.switchTo().window(context);
|
|
78
|
-
const isMainTab = await webDriver.executeScript("return window.__isMainTestimTab");
|
|
79
|
-
if (isMainTab) {
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const perfLogger = require('../commons/performance-logger');
|
|
5
|
-
const { guid } = require('../utils');
|
|
6
|
-
const { AbortError } = require('../commons/AbortError');
|
|
7
|
-
const { getArgumentsFromContext } = require('../codim/hybrid-utils');
|
|
8
|
-
const { getSessionPlayer } = require('../commons/getSessionPlayerRequire');
|
|
9
|
-
|
|
10
|
-
module.exports.execute = async function executeTdkFunction(player, hybridFunction, context, loginData, frameManager, step, source, abortSignal) {
|
|
11
|
-
function onAbort() {
|
|
12
|
-
player.sessionPlayer.stopPlaying();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
16
|
-
|
|
17
|
-
function getLocator(arg) {
|
|
18
|
-
if (step.parameterValues) { // tdk is all grown up and can run real locators
|
|
19
|
-
const locateStep = step.parameterValues.find(param => param.type === 'locate' && param.id === arg.locatorId);
|
|
20
|
-
return { elementLocator: locateStep.elementLocator, id: locateStep.id, name: 'Hybrid Step Locator' };
|
|
21
|
-
}
|
|
22
|
-
if (!arg.locatedElement.shadowPath) {
|
|
23
|
-
return arg; // wat
|
|
24
|
-
}
|
|
25
|
-
// fallback to selector, this should never happen in practice except when there was
|
|
26
|
-
// no locator to begin with (like if we expose reverse-hybrid to TDK)
|
|
27
|
-
return arg.locatedElement.shadowPath[0];
|
|
28
|
-
}
|
|
29
|
-
const args = await getArgumentsFromContext(step, context, getLocator);
|
|
30
|
-
const fn = hybridFunction.bind(null, ...args);
|
|
31
|
-
|
|
32
|
-
// assign same framemanager
|
|
33
|
-
const testId = guid();
|
|
34
|
-
const executionId = guid(); // we don't use the same execution ID to not associate the run with the suite and trigger bugs in features like "rerun by failed run id"
|
|
35
|
-
const resultId = context.testResultId; // this isn't the TDK result id - it's the _parent_ result ID tdk nests under.
|
|
36
|
-
const baseUrl = context.config.baseUrl;
|
|
37
|
-
const userData = _.cloneDeep(context); // the context contains everything needed as userData except login data
|
|
38
|
-
userData.loginData = loginData;
|
|
39
|
-
const sessionPlayerInit = getSessionPlayer();
|
|
40
|
-
const version = sessionPlayerInit.manifestVersion || 'runner';
|
|
41
|
-
const isLocalRun = false;
|
|
42
|
-
const overrideTestConfigId = null;
|
|
43
|
-
const branch = 'master'; // With TDK - branches are meaningless
|
|
44
|
-
const testName = `Execute TDK Function '${step.functionName}'`;
|
|
45
|
-
const ignoreNavigation = true;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const codeTest = {
|
|
49
|
-
fn,
|
|
50
|
-
bypassSetup: true, // don't setup and resize according to the TestConfig when starting
|
|
51
|
-
isBeforeOrAfterTest: true, // not a full test - don't perform "must contain assertions" validation
|
|
52
|
-
name: testName,
|
|
53
|
-
sourceCode: fn.toString(),
|
|
54
|
-
sourceName: fn.name,
|
|
55
|
-
testId,
|
|
56
|
-
resultId: guid(), // we don't want to reuse the resultId of the parent for the child - we need a new resultId
|
|
57
|
-
};
|
|
58
|
-
const onlyLocalReporting = typeof hybridFunction.results === 'boolean' && !hybridFunction.results;
|
|
59
|
-
try {
|
|
60
|
-
perfLogger.log('tdkHybridStepPlayback before addAllTabs');
|
|
61
|
-
if (frameManager) { // we have a frameManager we can reuse
|
|
62
|
-
player.sessionPlayer.playbackAutUtils.frameManager = frameManager;
|
|
63
|
-
player.sessionPlayer.frameManager = frameManager;
|
|
64
|
-
} else {
|
|
65
|
-
// otherwise, we have to tell the session player about them tabs
|
|
66
|
-
//TODO(benji) call getEditorUrl?
|
|
67
|
-
await player.addAllTabs(null, { loadInfo: true, checkForMainTab: true, takeScreenshots: !onlyLocalReporting }, [player.driver.initialUrl]);
|
|
68
|
-
}
|
|
69
|
-
player.sessionPlayer.playbackManager.dontAssociateChildResult = true; // don't associate child result to this test result.
|
|
70
|
-
player.sessionPlayer.playbackManager.onlyLocalReporting = onlyLocalReporting;
|
|
71
|
-
perfLogger.log('tdkHybridStepPlayback before playTestByCode');
|
|
72
|
-
const testResult = await new Promise((resolve, reject) => {
|
|
73
|
-
if (source === 'agent') {
|
|
74
|
-
resolveOnTestResultAndNotAssetsUploaded(player, resolve);
|
|
75
|
-
}
|
|
76
|
-
function onAbort() {
|
|
77
|
-
reject(new AbortError());
|
|
78
|
-
abortSignal.removeEventListener('abort', onAbort);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
82
|
-
|
|
83
|
-
player.sessionPlayer.playTestByCode(
|
|
84
|
-
testId, executionId, resultId, baseUrl, userData, version, resolve, isLocalRun, overrideTestConfigId, branch, [codeTest], testName, ignoreNavigation,
|
|
85
|
-
).catch(reject);
|
|
86
|
-
});
|
|
87
|
-
perfLogger.log('tdkHybridStepPlayback after playTestByCode');
|
|
88
|
-
// testResult.status?
|
|
89
|
-
return { success: testResult.success, shouldRetry: false, resultInfo: { testId, executionId, resultId: codeTest.resultId } };
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return { success: false, error: e, shouldRetry: false };
|
|
92
|
-
} finally {
|
|
93
|
-
abortSignal.removeEventListener('abort', onAbort);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
function resolveOnTestResultAndNotAssetsUploaded(player, resolve) {
|
|
98
|
-
const { commonConstants } = getSessionPlayer();
|
|
99
|
-
player.sessionPlayer.playbackManager.on(commonConstants.playback.START, ({ testResult }) => {
|
|
100
|
-
let runnerStatus = testResult.runnerStatus;
|
|
101
|
-
Object.defineProperty(testResult, 'runnerStatus', {
|
|
102
|
-
get() { return runnerStatus; },
|
|
103
|
-
set(value) {
|
|
104
|
-
runnerStatus = value;
|
|
105
|
-
if (value === 'FINISHED') {
|
|
106
|
-
// resolve as soon as the runner is finished, before assets are uploaded
|
|
107
|
-
resolve(testResult);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|