@eclipse-che/che-e2e 7.73.0-dev-1397a5e → 7.73.0-dev-62c0c9d

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 (175) hide show
  1. package/configs/inversify.config.ts +6 -6
  2. package/configs/inversify.types.ts +27 -27
  3. package/configs/mocharc.ts +21 -21
  4. package/constants/APITestConstants.ts +39 -38
  5. package/constants/BaseTestConstants.ts +44 -43
  6. package/constants/ChromeDriverConstants.ts +29 -29
  7. package/constants/FactoryTestConstants.ts +30 -30
  8. package/constants/MonacoConstants.ts +10 -10
  9. package/constants/OAuthConstants.ts +46 -46
  10. package/constants/ReporterConstants.ts +28 -28
  11. package/constants/TimeoutConstants.ts +101 -101
  12. package/dist/configs/inversify.config.js.map +1 -1
  13. package/dist/configs/inversify.types.js.map +1 -1
  14. package/dist/configs/mocharc.js +1 -1
  15. package/dist/configs/mocharc.js.map +1 -1
  16. package/dist/constants/APITestConstants.js +2 -2
  17. package/dist/constants/APITestConstants.js.map +1 -1
  18. package/dist/constants/BaseTestConstants.js +1 -1
  19. package/dist/constants/BaseTestConstants.js.map +1 -1
  20. package/dist/constants/ChromeDriverConstants.js +1 -1
  21. package/dist/constants/ChromeDriverConstants.js.map +1 -1
  22. package/dist/constants/FactoryTestConstants.js +1 -1
  23. package/dist/constants/FactoryTestConstants.js.map +1 -1
  24. package/dist/constants/MonacoConstants.js +1 -1
  25. package/dist/constants/MonacoConstants.js.map +1 -1
  26. package/dist/constants/OAuthConstants.js +1 -1
  27. package/dist/constants/OAuthConstants.js.map +1 -1
  28. package/dist/constants/ReporterConstants.js +1 -1
  29. package/dist/constants/ReporterConstants.js.map +1 -1
  30. package/dist/constants/TimeoutConstants.js.map +1 -1
  31. package/dist/driver/ChromeDriver.js.map +1 -1
  32. package/dist/pageobjects/dashboard/CreateWorkspace.js +8 -8
  33. package/dist/pageobjects/dashboard/CreateWorkspace.js.map +1 -1
  34. package/dist/pageobjects/dashboard/Dashboard.js +11 -11
  35. package/dist/pageobjects/dashboard/Dashboard.js.map +1 -1
  36. package/dist/pageobjects/dashboard/Workspaces.js +14 -14
  37. package/dist/pageobjects/dashboard/Workspaces.js.map +1 -1
  38. package/dist/pageobjects/dashboard/workspace-details/WorkspaceDetails.js +8 -8
  39. package/dist/pageobjects/dashboard/workspace-details/WorkspaceDetails.js.map +1 -1
  40. package/dist/pageobjects/git-providers/OauthPage.js +17 -17
  41. package/dist/pageobjects/git-providers/OauthPage.js.map +1 -1
  42. package/dist/pageobjects/ide/CheCodeLocatorLoader.js +1 -1
  43. package/dist/pageobjects/ide/CheCodeLocatorLoader.js.map +1 -1
  44. package/dist/pageobjects/login/kubernetes/DexLoginPage.js +5 -5
  45. package/dist/pageobjects/login/kubernetes/DexLoginPage.js.map +1 -1
  46. package/dist/pageobjects/login/kubernetes/KubernetesLoginPage.js +1 -1
  47. package/dist/pageobjects/login/kubernetes/KubernetesLoginPage.js.map +1 -1
  48. package/dist/pageobjects/login/openshift/OcpLoginPage.js +10 -10
  49. package/dist/pageobjects/login/openshift/OcpLoginPage.js.map +1 -1
  50. package/dist/pageobjects/login/openshift/OcpRedHatLoginPage.js +2 -2
  51. package/dist/pageobjects/login/openshift/OcpRedHatLoginPage.js.map +1 -1
  52. package/dist/pageobjects/login/openshift/OcpUserLoginPage.js +1 -1
  53. package/dist/pageobjects/login/openshift/OcpUserLoginPage.js.map +1 -1
  54. package/dist/pageobjects/login/openshift/RedHatLoginPage.js +6 -6
  55. package/dist/pageobjects/login/openshift/RedHatLoginPage.js.map +1 -1
  56. package/dist/pageobjects/login/openshift/RegularUserOcpCheLoginPage.js +2 -2
  57. package/dist/pageobjects/login/openshift/RegularUserOcpCheLoginPage.js.map +1 -1
  58. package/dist/pageobjects/openshift/OcpApplicationPage.js +2 -2
  59. package/dist/pageobjects/openshift/OcpApplicationPage.js.map +1 -1
  60. package/dist/pageobjects/openshift/OcpImportFromGitPage.js +5 -5
  61. package/dist/pageobjects/openshift/OcpImportFromGitPage.js.map +1 -1
  62. package/dist/pageobjects/openshift/OcpMainPage.js +11 -11
  63. package/dist/pageobjects/openshift/OcpMainPage.js.map +1 -1
  64. package/dist/specs/MochaHooks.js +1 -1
  65. package/dist/specs/MochaHooks.js.map +1 -1
  66. package/dist/specs/SmokeTest.spec.js +7 -3
  67. package/dist/specs/SmokeTest.spec.js.map +1 -1
  68. package/dist/specs/api/ContainerOverridesAPI.spec.js.map +1 -1
  69. package/dist/specs/api/DevfileAcceptanceTestAPI.spec.js +7 -5
  70. package/dist/specs/api/DevfileAcceptanceTestAPI.spec.js.map +1 -1
  71. package/dist/specs/api/EmptyWorkspaceAPI.spec.js +1 -1
  72. package/dist/specs/api/EmptyWorkspaceAPI.spec.js.map +1 -1
  73. package/dist/specs/api/PodOverridesAPI.spec.js.map +1 -1
  74. package/dist/specs/dashboard-samples/EmptyWorkspace.spec.js +9 -5
  75. package/dist/specs/dashboard-samples/EmptyWorkspace.spec.js.map +1 -1
  76. package/dist/specs/dashboard-samples/Quarkus.spec.js +7 -3
  77. package/dist/specs/dashboard-samples/Quarkus.spec.js.map +1 -1
  78. package/dist/specs/dashboard-samples/RecommendedExtensions.spec.js +6 -2
  79. package/dist/specs/dashboard-samples/RecommendedExtensions.spec.js.map +1 -1
  80. package/dist/specs/devconsole-intergration/DevConsoleIntegration.spec.js +3 -1
  81. package/dist/specs/devconsole-intergration/DevConsoleIntegration.spec.js.map +1 -1
  82. package/dist/specs/factory/Factory.spec.js +3 -1
  83. package/dist/specs/factory/Factory.spec.js.map +1 -1
  84. package/dist/specs/factory/NoSetupRepoFactory.spec.js +4 -2
  85. package/dist/specs/factory/NoSetupRepoFactory.spec.js.map +1 -1
  86. package/dist/specs/factory/RefusedOAuthFactory.spec.js +4 -2
  87. package/dist/specs/factory/RefusedOAuthFactory.spec.js.map +1 -1
  88. package/dist/specs/miscellaneous/PredefinedNamespace.spec.js +6 -2
  89. package/dist/specs/miscellaneous/PredefinedNamespace.spec.js.map +1 -1
  90. package/dist/tests-library/LoginTests.js.map +1 -1
  91. package/dist/tests-library/ProjectAndFileTests.js +3 -3
  92. package/dist/tests-library/ProjectAndFileTests.js.map +1 -1
  93. package/dist/tests-library/WorkspaceHandlingTests.js +54 -74
  94. package/dist/tests-library/WorkspaceHandlingTests.js.map +1 -1
  95. package/dist/utils/BrowserTabsUtil.js +10 -10
  96. package/dist/utils/BrowserTabsUtil.js.map +1 -1
  97. package/dist/utils/CheReporter.js.map +1 -1
  98. package/dist/utils/DevWorkspaceConfigurationHelper.js +2 -2
  99. package/dist/utils/DevWorkspaceConfigurationHelper.js.map +1 -1
  100. package/dist/utils/DevfilesRegistryHelper.js +7 -7
  101. package/dist/utils/DevfilesRegistryHelper.js.map +1 -1
  102. package/dist/utils/DriverHelper.js +81 -81
  103. package/dist/utils/DriverHelper.js.map +1 -1
  104. package/dist/utils/KubernetesCommandLineToolsExecutor.js +38 -35
  105. package/dist/utils/KubernetesCommandLineToolsExecutor.js.map +1 -1
  106. package/dist/utils/Logger.js +19 -10
  107. package/dist/utils/Logger.js.map +1 -1
  108. package/dist/utils/ScreenCatcher.js.map +1 -1
  109. package/dist/utils/ShellExecutor.js.map +1 -1
  110. package/dist/utils/StringUtil.js +2 -2
  111. package/dist/utils/StringUtil.js.map +1 -1
  112. package/dist/utils/request-handlers/CheApiRequestHandler.js +13 -11
  113. package/dist/utils/request-handlers/CheApiRequestHandler.js.map +1 -1
  114. package/dist/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.js +1 -1
  115. package/dist/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.js.map +1 -1
  116. package/dist/utils/workspace/ApiUrlResolver.js +3 -3
  117. package/dist/utils/workspace/ApiUrlResolver.js.map +1 -1
  118. package/dist/utils/workspace/TestWorkspaceUtil.js +20 -16
  119. package/dist/utils/workspace/TestWorkspaceUtil.js.map +1 -1
  120. package/dist/utils/workspace/WorkspaceStatus.js.map +1 -1
  121. package/driver/ChromeDriver.ts +44 -44
  122. package/driver/IDriver.ts +1 -1
  123. package/package.json +1 -1
  124. package/pageobjects/dashboard/CreateWorkspace.ts +52 -52
  125. package/pageobjects/dashboard/Dashboard.ts +72 -72
  126. package/pageobjects/dashboard/Workspaces.ts +138 -139
  127. package/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts +92 -93
  128. package/pageobjects/git-providers/OauthPage.ts +136 -136
  129. package/pageobjects/ide/CheCodeLocatorLoader.ts +40 -40
  130. package/pageobjects/login/interfaces/ICheLoginPage.ts +1 -1
  131. package/pageobjects/login/interfaces/IOcpLoginPage.ts +1 -1
  132. package/pageobjects/login/kubernetes/DexLoginPage.ts +27 -27
  133. package/pageobjects/login/kubernetes/KubernetesLoginPage.ts +11 -11
  134. package/pageobjects/login/openshift/OcpLoginPage.ts +50 -50
  135. package/pageobjects/login/openshift/OcpRedHatLoginPage.ts +21 -21
  136. package/pageobjects/login/openshift/OcpUserLoginPage.ts +14 -14
  137. package/pageobjects/login/openshift/RedHatLoginPage.ts +44 -41
  138. package/pageobjects/login/openshift/RegularUserOcpCheLoginPage.ts +23 -23
  139. package/pageobjects/openshift/OcpApplicationPage.ts +16 -16
  140. package/pageobjects/openshift/OcpImportFromGitPage.ts +54 -54
  141. package/pageobjects/openshift/OcpMainPage.ts +64 -64
  142. package/specs/MochaHooks.ts +44 -44
  143. package/specs/SmokeTest.spec.ts +35 -31
  144. package/specs/api/ContainerOverridesAPI.spec.ts +23 -23
  145. package/specs/api/DevfileAcceptanceTestAPI.spec.ts +93 -91
  146. package/specs/api/EmptyWorkspaceAPI.spec.ts +50 -50
  147. package/specs/api/PodOverridesAPI.spec.ts +29 -29
  148. package/specs/dashboard-samples/EmptyWorkspace.spec.ts +29 -25
  149. package/specs/dashboard-samples/Quarkus.spec.ts +31 -27
  150. package/specs/dashboard-samples/RecommendedExtensions.spec.ts +156 -152
  151. package/specs/devconsole-intergration/DevConsoleIntegration.spec.ts +62 -64
  152. package/specs/factory/Factory.spec.ts +149 -147
  153. package/specs/factory/NoSetupRepoFactory.spec.ts +188 -186
  154. package/specs/factory/RefusedOAuthFactory.spec.ts +182 -180
  155. package/specs/miscellaneous/PredefinedNamespace.spec.ts +52 -48
  156. package/tests-library/LoginTests.ts +29 -29
  157. package/tests-library/ProjectAndFileTests.ts +13 -13
  158. package/tests-library/WorkspaceHandlingTests.ts +84 -103
  159. package/utils/BrowserTabsUtil.ts +69 -69
  160. package/utils/CheReporter.ts +4 -6
  161. package/utils/DevWorkspaceConfigurationHelper.ts +58 -58
  162. package/utils/DevfilesRegistryHelper.ts +51 -51
  163. package/utils/DriverHelper.ts +599 -600
  164. package/utils/KubernetesCommandLineToolsExecutor.ts +166 -158
  165. package/utils/Logger.ts +98 -67
  166. package/utils/ScreenCatcher.ts +42 -42
  167. package/utils/ShellExecutor.ts +10 -10
  168. package/utils/StringUtil.ts +29 -29
  169. package/utils/request-handlers/CheApiRequestHandler.ts +84 -82
  170. package/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.ts +18 -18
  171. package/utils/request-handlers/headers/IAuthorizationHeaderHandler.ts +1 -1
  172. package/utils/workspace/ApiUrlResolver.ts +23 -23
  173. package/utils/workspace/ITestWorkspaceUtil.ts +29 -29
  174. package/utils/workspace/TestWorkspaceUtil.ts +120 -116
  175. package/utils/workspace/WorkspaceStatus.ts +3 -3
@@ -7,176 +7,184 @@ import { BaseTestConstants } from '../constants/BaseTestConstants';
7
7
  import { OAuthConstants } from '../constants/OAuthConstants';
8
8
 
9
9
  export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
10
- private static container: string;
11
- private static pod: string;
12
- private readonly namespace: string;
13
- private readonly workspaceName: string | undefined;
14
- private readonly KUBERNETES_COMMAND_LINE_TOOL: string = APITestConstants.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL;
15
-
16
- constructor(_workspaceName?: string, _namespace?: string) {
17
- super();
18
- this.workspaceName = _workspaceName;
19
- this.namespace = this.setNamespace(_namespace);
20
- }
21
-
22
- get getWorkspaceName(): string {
23
- return <string>this.workspaceName;
24
- }
25
-
26
- get getNamespace(): string {
27
- return this.namespace;
28
- }
29
-
30
- // login to Openshift cluster with username and password
31
- loginToOcp(): void {
32
- if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.OC) {
33
- Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: Login to the "OC" client.`);
34
- const url: string = this.getServerUrl();
35
- if (this.isUserLoggedIn()) {
36
- Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: User already logged`);
37
- } else {
38
- Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: Login ${url}, ${OAuthConstants.TS_SELENIUM_OCP_USERNAME}`);
39
- exec(`oc login --server=${url} -u=${OAuthConstants.TS_SELENIUM_OCP_USERNAME} -p=${OAuthConstants.TS_SELENIUM_OCP_PASSWORD} --insecure-skip-tls-verify`);
40
- }
41
- } else {
42
- Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: doesn't support login command`);
43
- }
44
- }
45
-
46
- getContainerName(): string {
47
- Logger.debug(`${this.getLoggingName(this.getContainerName.name)}: Get container name.`);
48
- const output: ShellString = ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} get ${(KubernetesCommandLineToolsExecutor.pod)} -o jsonpath='{.spec.containers[*].name}' -n ${this.namespace}`);
49
- echo('\n');
50
- return output.stderr ? output.stderr : output.stdout;
51
- }
52
-
53
- getWorkspacePodName(): string {
54
- Logger.debug(`${this.getLoggingName(this.getWorkspacePodName.name)}: Get workspace pod name.`);
55
- const output: ShellString = ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} get pod -l controller.devfile.io/devworkspace_name=${this.workspaceName} -n ${this.namespace} -o name`);
56
- return output.stderr ? output.stderr : output.stdout.replace('\n', '');
57
- }
58
-
59
- deleteDevWorkspace(): void {
60
- Logger.debug(`${this.getLoggingName(this.deleteDevWorkspace.name)}: Delete '${this.workspaceName}' workspace`);
61
- ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`);
62
- ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} delete dw ${this.workspaceName} -n ${this.namespace} || true`);
63
- ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} delete dwt ${BaseTestConstants.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`);
64
- }
65
-
66
- applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
67
- if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.KUBECTL) {
68
- this.createNamespace();
69
- }
70
- this.applyYamlConfigurationAsStringOutput(yamlConfiguration);
71
- return this.waitDevWorkspace();
72
- }
73
-
74
- executeCommand(commandToExecute: string, container: string = KubernetesCommandLineToolsExecutor.container): ShellString {
75
- Logger.debug(`${this.getLoggingName(this.executeCommand.name)}:`);
76
- return ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`);
77
- }
78
-
79
- applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
80
- Logger.debug(`${this.getLoggingName(this.applyYamlConfigurationAsStringOutput.name)}:`);
81
- return ShellExecutor.execWithLog(`cat <<EOF | ${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f - \n` +
82
- yamlConfiguration + '\n' +
83
- 'EOF');
84
- }
85
-
86
- applyYamlConfigurationAsFile(pathToFile: string): void {
87
- Logger.debug(`${this.getLoggingName(this.applyYamlConfigurationAsFile.name)}:`);
88
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f "${path.resolve(pathToFile)}"`);
89
- }
90
-
91
- getDevWorkspaceYamlConfiguration(): ShellString {
92
- Logger.debug(`${this.getLoggingName(this.getDevWorkspaceYamlConfiguration.name)}:`);
93
- return ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get dw ${this.workspaceName} -n ${this.namespace} -o yaml`);
94
- }
95
-
96
- waitDevWorkspace(timeout: number = 360): ShellString {
97
- Logger.debug(`${this.getLoggingName(this.waitDevWorkspace.name)}: Wait till workspace ready.`);
98
- const output: ShellString = ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} wait -n ${this.namespace} --for=condition=Ready dw ${this.workspaceName} --timeout=${timeout}s`);
99
- this.getPodAndContainerNames();
100
- return output;
101
- }
102
-
103
- createNamespace(): void {
104
- Logger.debug(`${this.getLoggingName(this.createNamespace.name)}: Create namespace "${this.namespace}".`);
105
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} create namespace ${this.namespace}`);
106
- }
107
-
108
- createProject(projectName: string): void {
109
- Logger.debug(`${this.getLoggingName(this.createProject.name)}: Create new project "${projectName}".`);
110
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} new-project ${projectName} -n ${this.namespace}`);
111
- }
10
+ private static container: string;
11
+ private static pod: string;
12
+ private readonly namespace: string;
13
+ private readonly workspaceName: string | undefined;
14
+ private readonly KUBERNETES_COMMAND_LINE_TOOL: string =
15
+ APITestConstants.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL;
16
+
17
+ constructor(_workspaceName?: string, _namespace?: string) {
18
+ super();
19
+ this.workspaceName = _workspaceName;
20
+ this.namespace = this.setNamespace(_namespace);
21
+ }
22
+
23
+ get getWorkspaceName(): string {
24
+ return <string>this.workspaceName;
25
+ }
26
+
27
+ get getNamespace(): string {
28
+ return this.namespace;
29
+ }
30
+
31
+ // login to Openshift cluster with username and password
32
+ loginToOcp(): void {
33
+ if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.OC) {
34
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - login to the "OC" client.`);
35
+ const url: string = this.getServerUrl();
36
+ if (this.isUserLoggedIn()) {
37
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - user already logged`);
38
+ } else {
39
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - login ${url}, ${OAuthConstants.TS_SELENIUM_OCP_USERNAME}`);
40
+ exec(`oc login --server=${url} -u=${OAuthConstants.TS_SELENIUM_OCP_USERNAME} -p=${OAuthConstants.TS_SELENIUM_OCP_PASSWORD} --insecure-skip-tls-verify`);
41
+ }
42
+ } else {
43
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - doesn't support login command`);
44
+ }
45
+ }
46
+
47
+ getContainerName(): string {
48
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get container name.`);
49
+ const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get ${KubernetesCommandLineToolsExecutor.pod} -o jsonpath='{.spec.containers[*].name}' -n ${this.namespace}`);
50
+ echo('\n');
51
+ return output.stderr ? output.stderr : output.stdout;
52
+ }
53
+
54
+ getWorkspacePodName(): string {
55
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get workspace pod name.`);
56
+ const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get pod -l controller.devfile.io/devworkspace_name=${this.workspaceName} -n ${this.namespace} -o name`);
57
+ return output.stderr ? output.stderr : output.stdout.replace('\n', '');
58
+ }
59
+
60
+ deleteDevWorkspace(): void {
61
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - delete '${this.workspaceName}' workspace`);
62
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`);
63
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete dw ${this.workspaceName} -n ${this.namespace} || true`);
64
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete dwt ${BaseTestConstants.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`);
65
+ }
66
+
67
+ applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
68
+ if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.KUBECTL) {
69
+ this.createNamespace();
70
+ }
71
+ this.applyYamlConfigurationAsStringOutput(yamlConfiguration);
72
+ return this.waitDevWorkspace();
73
+ }
74
+
75
+ executeCommand(
76
+ commandToExecute: string,
77
+ container: string = KubernetesCommandLineToolsExecutor.container): ShellString {
78
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
79
+ return ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`);
80
+ }
81
+
82
+ applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
83
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
84
+ return ShellExecutor.execWithLog(`cat <<EOF | ${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f - \n` +
85
+ yamlConfiguration +
86
+ '\n' +
87
+ 'EOF');
88
+ }
89
+
90
+ applyYamlConfigurationAsFile(pathToFile: string): void {
91
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
92
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f "${path.resolve(pathToFile)}"`);
93
+ }
94
+
95
+ getDevWorkspaceYamlConfiguration(): ShellString {
96
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
97
+ return ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get dw ${this.workspaceName} -n ${this.namespace} -o yaml`);
98
+ }
99
+
100
+ waitDevWorkspace(timeout: number = 360): ShellString {
101
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - wait till workspace ready.`);
102
+ const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} wait -n ${this.namespace} --for=condition=Ready dw ${this.workspaceName} --timeout=${timeout}s`);
103
+ this.getPodAndContainerNames();
104
+ return output;
105
+ }
106
+
107
+ createNamespace(): void {
108
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - create namespace "${this.namespace}".`);
109
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} create namespace ${this.namespace}`);
110
+ }
111
+
112
+ createProject(projectName: string): void {
113
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - create new project "${projectName}".`);
114
+ ShellExecutor.execWithLog(
115
+ `${this.KUBERNETES_COMMAND_LINE_TOOL} new-project ${projectName} -n ${this.namespace}`
116
+ );
117
+ }
118
+
119
+ deleteProject(projectName: string): void {
120
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - delete "${projectName}".`);
121
+ ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete project ${projectName} -n ${this.namespace}`);
122
+ }
123
+
124
+ private getPodAndContainerNames(): void {
125
+ KubernetesCommandLineToolsExecutor.pod = this.getWorkspacePodName();
126
+ KubernetesCommandLineToolsExecutor.container = this.getContainerName();
127
+ }
128
+
129
+ private isUserLoggedIn(): boolean {
130
+ const whoamiCommandOutput: ShellString = ShellExecutor.execWithLog('oc whoami && oc whoami --show-server=true');
131
+
132
+ return (
133
+ whoamiCommandOutput.stdout.includes(OAuthConstants.TS_SELENIUM_OCP_USERNAME) && whoamiCommandOutput.stdout.includes(this.getServerUrl()));
134
+ }
135
+
136
+ private setNamespace(_namespace: string | undefined): string {
137
+ _namespace =
138
+ _namespace !== undefined
139
+ ? _namespace
140
+ : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('devspaces')
141
+ ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-devspaces'
142
+ : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('che')
143
+ ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-che'
144
+ : 'default';
145
+ return _namespace;
146
+ }
147
+
148
+ private getServerUrl(): string {
149
+ Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get server api url.`);
150
+ return (BaseTestConstants.TS_SELENIUM_BASE_URL.replace('devspaces.apps', 'api') + ':6443');
151
+ }
152
+ }
112
153
 
113
- deleteProject(projectName: string): void {
114
- Logger.debug(`${this.getLoggingName(this.deleteProject.name)}: Delete "${projectName}".`);
115
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete project ${projectName} -n ${this.namespace}`);
154
+ export namespace KubernetesCommandLineToolsExecutor {
155
+ export class ContainerTerminal extends KubernetesCommandLineToolsExecutor {
156
+ constructor(cluster: KubernetesCommandLineToolsExecutor) {
157
+ super(cluster.getWorkspaceName, cluster.getNamespace);
116
158
  }
117
159
 
118
- private getPodAndContainerNames(): void {
119
- KubernetesCommandLineToolsExecutor.pod = this.getWorkspacePodName();
120
- KubernetesCommandLineToolsExecutor.container = this.getContainerName();
160
+ ls(path: string = ''): ShellString {
161
+ return this.executeCommand('ls ' + path);
121
162
  }
122
163
 
123
- private isUserLoggedIn(): boolean {
124
- const whoamiCommandOutput: ShellString = ShellExecutor.execWithLog('oc whoami && oc whoami --show-server=true');
125
-
126
- return whoamiCommandOutput.stdout.includes(OAuthConstants.TS_SELENIUM_OCP_USERNAME) && whoamiCommandOutput.stdout.includes(this.getServerUrl());
164
+ pwd(): ShellString {
165
+ return this.executeCommand('pwd');
127
166
  }
128
167
 
129
- private getLoggingName(methodName: string): string {
130
- return `${this.constructor.name}.${methodName} - ${(this.KUBERNETES_COMMAND_LINE_TOOL)}`;
168
+ cd(path: string): ShellString {
169
+ return this.executeCommand('cd ' + path);
131
170
  }
132
171
 
133
- private setNamespace(_namespace: string | undefined): string {
134
- _namespace = _namespace !== undefined ? _namespace
135
- : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('devspaces') ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-devspaces'
136
- : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('che') ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-che'
137
- : 'default';
138
- return _namespace;
172
+ gitClone(repository: string): ShellString {
173
+ return this.executeCommand('git clone ' + repository);
139
174
  }
140
175
 
141
- private getServerUrl(): string {
142
- Logger.debug(`${this.getLoggingName(this.getServerUrl.name)}: Get server api url.`);
143
- return BaseTestConstants.TS_SELENIUM_BASE_URL.replace('devspaces.apps', 'api') + ':6443';
176
+ removeFolder(path: string): ShellString {
177
+ return this.executeCommand('rm -rf ' + path);
144
178
  }
145
- }
146
179
 
147
- export namespace KubernetesCommandLineToolsExecutor {
148
- export class ContainerTerminal extends KubernetesCommandLineToolsExecutor {
149
- constructor(cluster: KubernetesCommandLineToolsExecutor) {
150
- super(cluster.getWorkspaceName, cluster.getNamespace);
151
- }
152
-
153
- ls(path: string = ''): ShellString {
154
- return this.executeCommand('ls ' + path);
155
- }
156
-
157
- pwd(): ShellString {
158
- return this.executeCommand('pwd');
159
- }
160
-
161
- cd(path: string): ShellString {
162
- return this.executeCommand('cd ' + path);
163
- }
164
-
165
- gitClone(repository: string): ShellString {
166
- return this.executeCommand('git clone ' + repository);
167
- }
168
-
169
- removeFolder(path: string): ShellString {
170
- return this.executeCommand('rm -rf ' + path);
171
- }
172
-
173
- getEnvValue(envName: string): string {
174
- envName = envName.replace(/[${}]/g, '');
175
- const output: ShellString = this.executeCommand(`env | grep ${envName}`);
176
- return output.stderr ? output.stderr :
177
- output.stdout
178
- .substring(output.stdout.lastIndexOf('=') + 1)
179
- .replace('\n', '');
180
- }
180
+ getEnvValue(envName: string): string {
181
+ envName = envName.replace(/[${}]/g, '');
182
+ const output: ShellString = this.executeCommand(`env | grep ${envName}`);
183
+ return output.stderr
184
+ ? output.stderr
185
+ : output.stdout
186
+ .substring(output.stdout.lastIndexOf('=') + 1)
187
+ .replace('\n', '');
181
188
  }
189
+ }
182
190
  }
package/utils/Logger.ts CHANGED
@@ -10,82 +10,113 @@
10
10
  import { ReporterConstants } from '../constants/ReporterConstants';
11
11
 
12
12
  export abstract class Logger {
13
+ /**
14
+ * Uses for logging of fatal errors.
15
+ * @param text log text
16
+ * @param indentLevel log level
17
+ */
18
+ static error(text: string = '', indentLevel: number = 1): void {
19
+ this.logText(
20
+ indentLevel,
21
+ `[ERROR] ${this.getCallerInfo()} ${this.separator(text)} ${text}`
22
+ );
23
+ }
13
24
 
14
- /**
15
- * Uses for logging of fatal errors.
16
- * @param text log text
17
- * @param indentLevel log level
18
- */
19
- static error(text: string, indentLevel: number = 1): void {
20
- this.logText(indentLevel, `[ERROR] ${text}`);
25
+ /**
26
+ * Uses for logging of recoverable errors and general warnings.
27
+ * @param text log text
28
+ * @param indentLevel log level
29
+ */
30
+ static warn(text: string = '', indentLevel: number = 1): void {
31
+ if (ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR') {
32
+ return;
21
33
  }
34
+ this.logText(
35
+ indentLevel,
36
+ `[WARN] ${this.getCallerInfo()} ${this.separator(text)} ${text}`
37
+ );
38
+ }
22
39
 
23
- /**
24
- * Uses for logging of recoverable errors and general warnings.
25
- * @param text log text
26
- * @param indentLevel log level
27
- */
28
- static warn(text: string, indentLevel: number = 1): void {
29
- if (ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR') {
30
- return;
31
- }
32
- this.logText(indentLevel, `[WARN] ${text}`);
40
+ /**
41
+ * Uses for logging of the public methods of the pageobjects.
42
+ * @param text log text
43
+ * @param indentLevel log level
44
+ */
45
+ static info(text: string = '', indentLevel: number = 3): void {
46
+ if (
47
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
48
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN'
49
+ ) {
50
+ return;
33
51
  }
52
+ this.logText(
53
+ indentLevel,
54
+ `• ${this.getCallerInfo()} ${this.separator(text)} ${text}`
55
+ );
56
+ }
34
57
 
35
- /**
36
- * Uses for logging of the public methods of the pageobjects.
37
- * @param text log text
38
- * @param indentLevel log level
39
- */
40
- static info(text: string, indentLevel: number = 3): void {
41
- if (ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
42
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN') {
43
- return;
44
- }
45
- this.logText(indentLevel, `• ${text}`);
58
+ /**
59
+ * Uses for logging of the public methods of the pageobjects.
60
+ * @param text log text
61
+ * @param indentLevel log level
62
+ */
63
+ static debug(text: string = '', indentLevel: number = 5): void {
64
+ if (
65
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
66
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN' ||
67
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'INFO'
68
+ ) {
69
+ return;
46
70
  }
71
+ this.logText(
72
+ indentLevel,
73
+ `▼ ${this.getCallerInfo()} ${this.separator(text)} ${text}`
74
+ );
75
+ }
47
76
 
48
- /**
49
- * Uses for logging of the public methods of the pageobjects.
50
- * @param text log text
51
- * @param indentLevel log level
52
- */
53
- static debug(text: string, indentLevel: number = 5): void {
54
- if (ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
55
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN' ||
56
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'INFO') {
57
- return;
58
- }
59
- this.logText(indentLevel, `▼ ${text}`);
77
+ /**
78
+ * Uses for logging of the public methods of the {@link DriverHelper} or
79
+ * private methods inside of pageobjects.
80
+ * @param text log text
81
+ * @param indentLevel log level
82
+ */
83
+ static trace(text: string = '', indentLevel: number = 6): void {
84
+ if (
85
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
86
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN' ||
87
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'INFO' ||
88
+ ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'DEBUG'
89
+ ) {
90
+ return;
60
91
  }
92
+ this.logText(
93
+ indentLevel,
94
+ `‣ ${this.getCallerInfo()} ${this.separator(text)} ${text}`
95
+ );
96
+ }
61
97
 
62
- /**
63
- * Uses for logging of the public methods of the {@link DriverHelper} or
64
- * private methods inside of pageobjects.
65
- * @param text log text
66
- * @param indentLevel log level
67
- */
68
- static trace(text: string, indentLevel: number = 6): void {
69
- if (ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'ERROR' ||
70
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'WARN' ||
71
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'INFO' ||
72
- ReporterConstants.TS_SELENIUM_LOG_LEVEL === 'DEBUG') {
73
- return;
74
- }
75
- this.logText(indentLevel, `‣ ${text}`);
98
+ private static logText(messageIndentationLevel: number, text: string): void {
99
+ // start group for every level
100
+ for (let i: number = 0; i < messageIndentationLevel; i++) {
101
+ console.group();
76
102
  }
77
-
78
- private static logText(messageIndentationLevel: number, text: string): void {
79
- // start group for every level
80
- for (let i: number = 0; i < messageIndentationLevel; i++) {
81
- console.group();
82
- }
83
- // print the trimmed text
84
- // if multiline, the message should be properly padded
85
- console.log(text);
86
- // end group for every level
87
- for (let i: number = 0; i < messageIndentationLevel; i++) {
88
- console.groupEnd();
89
- }
103
+ // print the trimmed text
104
+ // if multiline, the message should be properly padded
105
+ console.log(text);
106
+ // end group for every level
107
+ for (let i: number = 0; i < messageIndentationLevel; i++) {
108
+ console.groupEnd();
90
109
  }
110
+ }
111
+
112
+ private static getCallerInfo(): string {
113
+ const e: Error = new Error();
114
+ const stack: string[] = e.stack ? e.stack.split('\n') : [];
115
+ // " at functionName ( ..." => "functionName"
116
+ return stack[3].replace(/^\s+at\s+(.+?)\s.+/g, '$1');
117
+ }
118
+
119
+ private static separator(text: string): string {
120
+ return text ? '-' : '';
121
+ }
91
122
  }
@@ -8,67 +8,67 @@
8
8
  * SPDX-License-Identifier: EPL-2.0
9
9
  **********************************************************************/
10
10
  import * as fs from 'fs';
11
- import { injectable, inject } from 'inversify';
11
+ import { WriteStream } from 'fs';
12
+ import { inject, injectable } from 'inversify';
12
13
  import { CLASSES } from '../configs/inversify.types';
13
14
  import { DriverHelper } from './DriverHelper';
14
15
  import { error } from 'selenium-webdriver';
15
- import { WriteStream } from 'fs';
16
16
  import { StringUtil } from './StringUtil';
17
17
  import { ReporterConstants } from '../constants/ReporterConstants';
18
18
 
19
19
  @injectable()
20
20
  export class ScreenCatcher {
21
- constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }
21
+ constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }
22
22
 
23
- async catchMethodScreen(methodName: string, methodIndex: number, screenshotIndex: number): Promise<void> {
24
- const executionScreenCastDir: string = `${ReporterConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencast`;
25
- const executionScreenCastErrorsDir: string = `${ReporterConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencastErrors`;
26
- const formattedMethodIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(methodIndex);
27
- const formattedScreenshotIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 5 }).format(screenshotIndex).replace(/,/g, '');
23
+ async catchMethodScreen(methodName: string, methodIndex: number, screenshotIndex: number): Promise<void> {
24
+ const executionScreenCastDir: string = `${ReporterConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencast`;
25
+ const executionScreenCastErrorsDir: string = `${ReporterConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencastErrors`;
26
+ const formattedMethodIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(methodIndex);
27
+ const formattedScreenshotIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 5 }).format(screenshotIndex).replace(/,/g, '');
28
28
 
29
- if (!fs.existsSync(ReporterConstants.TS_SELENIUM_REPORT_FOLDER)) {
30
- fs.mkdirSync(ReporterConstants.TS_SELENIUM_REPORT_FOLDER);
31
- }
29
+ if (!fs.existsSync(ReporterConstants.TS_SELENIUM_REPORT_FOLDER)) {
30
+ fs.mkdirSync(ReporterConstants.TS_SELENIUM_REPORT_FOLDER);
31
+ }
32
32
 
33
- if (!fs.existsSync(executionScreenCastDir)) {
34
- fs.mkdirSync(executionScreenCastDir);
35
- }
33
+ if (!fs.existsSync(executionScreenCastDir)) {
34
+ fs.mkdirSync(executionScreenCastDir);
35
+ }
36
36
 
37
- const date: Date = new Date();
38
- const timeStr: string = date.toLocaleTimeString('en-us', { hour12: false }) + '.' + new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(date.getMilliseconds());
37
+ const date: Date = new Date();
38
+ const timeStr: string = date.toLocaleTimeString('en-us', { hour12: false }) + '.' + new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(date.getMilliseconds());
39
39
 
40
- const screenshotPath: string = `${executionScreenCastDir}/${formattedMethodIndex}-${formattedScreenshotIndex}--(${StringUtil.sanitizeTitle(timeStr)})_${StringUtil.sanitizeTitle(methodName)}.png`;
40
+ const screenshotPath: string = `${executionScreenCastDir}/${formattedMethodIndex}-${formattedScreenshotIndex}--(${StringUtil.sanitizeTitle(timeStr)})_${StringUtil.sanitizeTitle(methodName)}.png`;
41
41
 
42
- try {
43
- await this.catchScreen(screenshotPath);
44
- } catch (err) {
45
- if (!fs.existsSync(executionScreenCastErrorsDir)) {
46
- fs.mkdirSync(executionScreenCastErrorsDir);
47
- }
42
+ try {
43
+ await this.catchScreen(screenshotPath);
44
+ } catch (err) {
45
+ if (!fs.existsSync(executionScreenCastErrorsDir)) {
46
+ fs.mkdirSync(executionScreenCastErrorsDir);
47
+ }
48
48
 
49
- let errorLogFilePath: string = screenshotPath.replace('.png', '.txt');
50
- errorLogFilePath = errorLogFilePath.replace(executionScreenCastDir, executionScreenCastErrorsDir);
51
- if (err instanceof error.IError) {
52
- await this.writeErrorLog(errorLogFilePath, err);
53
- }
54
- }
49
+ let errorLogFilePath: string = screenshotPath.replace('.png', '.txt');
50
+ errorLogFilePath = errorLogFilePath.replace(executionScreenCastDir, executionScreenCastErrorsDir);
51
+ if (err instanceof error.IError) {
52
+ await this.writeErrorLog(errorLogFilePath, err);
53
+ }
55
54
  }
55
+ }
56
56
 
57
- async catchScreen(screenshotPath: string): Promise<void> {
58
- const screenshot: string = await this.driverHelper.getDriver().takeScreenshot();
59
- const screenshotStream: WriteStream = fs.createWriteStream(screenshotPath);
60
- screenshotStream.write(Buffer.from(screenshot, 'base64'));
61
- screenshotStream.end();
62
- }
57
+ async catchScreen(screenshotPath: string): Promise<void> {
58
+ const screenshot: string = await this.driverHelper.getDriver().takeScreenshot();
59
+ const screenshotStream: WriteStream = fs.createWriteStream(screenshotPath);
60
+ screenshotStream.write(Buffer.from(screenshot, 'base64'));
61
+ screenshotStream.end();
62
+ }
63
63
 
64
- async writeErrorLog(errorLogPath: string, err: error.IError): Promise<void> {
65
- console.log(`Failed to save screenshot, additional information in the ${errorLogPath}`);
64
+ async writeErrorLog(errorLogPath: string, err: error.IError): Promise<void> {
65
+ console.log(`Failed to save screenshot, additional information in the ${errorLogPath}`);
66
66
 
67
- if (err.stack) {
68
- const screenshotStream: WriteStream = fs.createWriteStream(errorLogPath);
69
- screenshotStream.write(Buffer.from(err.stack, 'utf8'));
70
- screenshotStream.end();
71
- }
67
+ if (err.stack) {
68
+ const screenshotStream: WriteStream = fs.createWriteStream(errorLogPath);
69
+ screenshotStream.write(Buffer.from(err.stack, 'utf8'));
70
+ screenshotStream.end();
72
71
  }
72
+ }
73
73
 
74
74
  }