@testim/testim-cli 3.251.0 → 3.253.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.
Files changed (34) hide show
  1. package/agent/routers/index.js +2 -1
  2. package/agent/routers/playground/router.js +1 -1
  3. package/commons/chrome-launcher.js +6 -6
  4. package/commons/constants.js +2 -0
  5. package/commons/getSessionPlayerRequire.js +2 -20
  6. package/commons/initializeUserWithAuth.js +2 -2
  7. package/commons/mockNetworkRuleFileSchema.json +40 -38
  8. package/commons/testimDesiredCapabilitiesBuilder.js +43 -0
  9. package/commons/testimServicesApi.js +11 -2
  10. package/credentialsManager.js +17 -20
  11. package/npm-shrinkwrap.json +2104 -444
  12. package/package.json +4 -2
  13. package/player/WebdriverioWebDriverApi.js +7 -2
  14. package/player/appiumTestPlayer.js +102 -0
  15. package/player/seleniumTestPlayer.js +3 -2
  16. package/player/services/frameLocator.js +2 -1
  17. package/player/services/mobileFrameLocatorMock.js +32 -0
  18. package/player/services/playbackTimeoutCalculator.js +1 -0
  19. package/player/services/portSelector.js +10 -8
  20. package/player/services/tabService.js +29 -0
  21. package/player/stepActions/sfdcRecordedStepAction.js +2 -2
  22. package/player/stepActions/sfdcStepAction.js +2 -2
  23. package/player/stepActions/stepAction.js +15 -1
  24. package/player/utils/stepActionUtils.js +4 -2
  25. package/player/utils/windowUtils.js +138 -125
  26. package/player/webdriver.js +39 -25
  27. package/reports/debugReporter.js +41 -39
  28. package/reports/jsonReporter.js +53 -50
  29. package/reports/reporter.js +135 -136
  30. package/runOptions.js +2 -1
  31. package/runners/ParallelWorkerManager.js +2 -0
  32. package/testRunStatus.js +457 -459
  33. package/workers/BaseWorker.js +13 -6
  34. package/workers/WorkerAppium.js +123 -0
@@ -5,7 +5,7 @@ const moment = require('moment');
5
5
  const pRetry = require('p-retry');
6
6
  const ms = require('ms');
7
7
 
8
- const { timeoutMessages, testRunStatus, stepResult, runnerTestStatus } = require('../commons/constants');
8
+ const { timeoutMessages, testRunStatus, stepResult, runnerTestStatus, CLI_MODE } = require('../commons/constants');
9
9
  const logger = require('../commons/logger').getLogger('base-worker');
10
10
  const testResultService = require('../commons/socket/testResultService');
11
11
  const remoteStepService = require('../commons/socket/remoteStepService');
@@ -110,8 +110,15 @@ class BaseWorker {
110
110
  return undefined;
111
111
  }
112
112
 
113
+ setSessionTimeout() {
114
+ if (this.options.mode === CLI_MODE.APPIUM) {
115
+ return Math.max(ms('180s'), this.options.getSessionTimeout);
116
+ }
117
+ return Math.max(this.lambdatestService.getSessionTimeout, this.options.getSessionTimeout);
118
+ }
119
+
113
120
  async getTestPlayer(testRunHandler, customExtensionLocalLocation) {
114
- const projectId = this.userData && this.userData.projectId;
121
+ const projectId = this.userData?.projectId;
115
122
  let testPlayer;
116
123
 
117
124
  try {
@@ -148,7 +155,7 @@ class BaseWorker {
148
155
  this.options.gridData.provider = gridInfo.provider;
149
156
  this.options.gridData.host = gridInfo.host;
150
157
  this.options.gridData.failedGetBrowserAttempts = failedGetBrowserAttempts;
151
- const getSessionTimeout = Math.max(this.lambdatestService.getSessionTimeout, this.options.getSessionTimeout);
158
+ const getSessionTimeout = this.setSessionTimeout();
152
159
  const getBrowserRes = await Bluebird.resolve()
153
160
  .log('before getBrowserOnce')
154
161
  .then(() => this.getBrowserOnce(testRunHandler, customExtensionLocalLocation, player, gridInfo))
@@ -186,7 +193,7 @@ class BaseWorker {
186
193
 
187
194
  async runTest(testRunHandler, customExtensionLocalLocation, shouldRerun) {
188
195
  perf.log('inside runTest');
189
- const projectId = this.userData && this.userData.projectId;
196
+ const projectId = this.userData?.projectId;
190
197
  const quarantineResult = this.handleQuarantine(testRunHandler);
191
198
  if (quarantineResult) {
192
199
  return quarantineResult;
@@ -380,8 +387,8 @@ class BaseWorker {
380
387
  }
381
388
  };
382
389
 
383
- const disableResults = this.options.disableSockets || (this.options.lightweightMode && this.options.lightweightMode.disableResults && (this.options.useChromeLauncher || this.options.mode !== 'extension'));
384
- const disableRemoteStep = this.options.disableSockets || (this.options.lightweightMode && this.options.lightweightMode.disableRemoteStep);
390
+ const disableResults = this.options.disableSockets || (this.options.lightweightMode?.disableResults && (this.options.useChromeLauncher || this.options.mode !== 'extension'));
391
+ const disableRemoteStep = this.options.disableSockets || (this.options.lightweightMode?.disableRemoteStep);
385
392
 
386
393
  const runTestAndCalcResult = (testRunHandler, shouldRerun) => Promise.all([
387
394
  !disableRemoteStep && remoteStepService.joinToRemoteStep(this.testResultId),
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ const jsdom = require('jsdom');
4
+ const BaseWorker = require('./BaseWorker');
5
+ const logger = require('../commons/logger').getLogger('worker-appium');
6
+ const reporter = require('../reports/reporter');
7
+ const AppiumTestPlayer = require('../player/appiumTestPlayer');
8
+ const sessionPlayerInit = require('../commons/getSessionPlayerRequire');
9
+ const AppiumApi = require('../commons/getSessionPlayerRequire').AppiumApi;
10
+ const desiredCapabilitiesBuilder = require('../commons/testimDesiredCapabilitiesBuilder');
11
+
12
+ class WorkerAppium extends BaseWorker {
13
+ constructor(...args) {
14
+ super(...args);
15
+ this.getBrowserOnce = Promise.method(this.getBrowserOnce);
16
+ }
17
+
18
+ initPlayer(testRunHandler) {
19
+ return new AppiumTestPlayer(this.id,
20
+ testRunHandler.getRunParams(),
21
+ this.options.shouldMonitorPerformance,
22
+ testRunHandler.getAutomationMode(),
23
+ undefined,
24
+ testRunHandler.getRetryCount(),
25
+ testRunHandler.getPreviousTestResultId());
26
+ }
27
+
28
+ async getBrowserOnce(testRunHandler, customExtensionLocalLocation, appiumTestPlayer, gridInfo) {
29
+ reporter.onGetSession(this.id, this.testName, testRunHandler.getRunMode());
30
+ const { driver } = appiumTestPlayer;
31
+ const nativeApp = testRunHandler.getNativeAppData();
32
+ const projectType = this.options.projectData.type;
33
+ const capabilities = desiredCapabilitiesBuilder.buildAppiumOptions({ projectType, gridInfo, testRunConfig: this.testRunConfig, nativeApp });
34
+ try {
35
+ //we assume the application is installed on the device. (all headspin allocated devices)
36
+ const activeSession = await driver.remote(capabilities);
37
+ driver.activeSession = activeSession;
38
+ logger.info(`init new appium session testName: ${this.testName}`, { sessionId: activeSession.sessionId, testResultId: this.testResultId, nativeApp });
39
+ } catch (err) {
40
+ //TODO: catch app status validation
41
+ logger.error('failed to start application', { err });
42
+ throw err;
43
+ }
44
+ }
45
+
46
+ getServerAddressFromGrid(testRunHandler) {
47
+ const { _options: { gridData: { host, port, accessToken } } } = testRunHandler;
48
+ return `https://${host}:${port}/v0/${accessToken}/wd/hub`;
49
+ }
50
+
51
+ getDirectAddressConnection(activeSessionCapabilities) {
52
+ const { directConnectProtocol: protocol, directConnectHost: host, directConnectPort: port, directConnectPath: path } = activeSessionCapabilities;
53
+ if (protocol && host && port && path) {
54
+ return `${protocol}://${host}:${port}${path}`;
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ async runTestOnce(testRunHandler, appiumTestPlayer) {
60
+ const { driver, sessionPlayer } = appiumTestPlayer;
61
+ const version = sessionPlayerInit.manifestVersion || 'runner';
62
+
63
+ reporter.onWaitToTestComplete(this.id, this.isCodeMode);
64
+
65
+ sessionPlayer.playbackManager.executionId = testRunHandler.getExecutionId();
66
+ sessionPlayer.playbackManager.executionName = testRunHandler.getExecutionName();
67
+
68
+ const serverAddress = this.getDirectAddressConnection(driver.activeSession.capabilities) || this.getServerAddressFromGrid(testRunHandler);
69
+ const DOMParser = new (jsdom.JSDOM)('').window.DOMParser;
70
+ sessionPlayer.playbackManager.appiumApi = new AppiumApi(serverAddress, driver.activeSession.sessionId, DOMParser);
71
+
72
+
73
+ if (sessionPlayerInit.localAssetService) {
74
+ sessionPlayerInit.localAssetService.initialize({ serverUrl: this.options.localRCASaver });
75
+ }
76
+ async function runAppiumTest() {
77
+ try {
78
+ const INCOGNITO = false;
79
+ const testResult = await (new Promise((resolve, reject) =>
80
+ // eslint-disable-next-line no-promise-executor-return
81
+ sessionPlayer.playByTestId(
82
+ this.testId,
83
+ this.executionId,
84
+ this.testResultId,
85
+ this.baseUrl,
86
+ this.userData,
87
+ version,
88
+ resolve,
89
+ false,
90
+ this.overrideTestConfigId,
91
+ this.branch,
92
+ INCOGNITO,
93
+ testRunHandler.getRemoteRunId(),
94
+ undefined,
95
+ undefined,
96
+ undefined,
97
+ )));
98
+ if (sessionPlayerInit.localAssetService) {
99
+ await sessionPlayerInit.localAssetService.drain();
100
+ }
101
+ testResult.stepsResults = null;
102
+ testResult.resultId = this.testResultId;
103
+ const resultWithStats = { ...testResult, ...testRunHandler.seleniumPerfStats.getStats() };
104
+ return resultWithStats;
105
+ } catch (err) {
106
+ //TODO: add test timeout and handle Timeout Error TBD
107
+ // if (err instanceof TimeoutError && sessionPlayer.stopPlayingOnTestTimeout) {
108
+ // sessionPlayer.stopPlayingOnTestTimeout();
109
+ // }
110
+ logger.error('error while running appium tests', { err });
111
+ throw err;
112
+ }
113
+ }
114
+ try {
115
+ await super.runTestOnce(testRunHandler, appiumTestPlayer);
116
+ await runAppiumTest.call(this);
117
+ } catch (err) {
118
+ logger.error('failed to run test once', { err });
119
+ throw err;
120
+ }
121
+ }
122
+ }
123
+ module.exports = WorkerAppium;