diff --git a/tests/e2e/driver/CheReporter.ts b/tests/e2e/driver/CheReporter.ts index 9649e67b214..556718e89d5 100644 --- a/tests/e2e/driver/CheReporter.ts +++ b/tests/e2e/driver/CheReporter.ts @@ -36,7 +36,7 @@ let testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil class CheReporter extends mocha.reporters.Spec { - private static latestWorkspace: string; + private static latestWorkspace: string = ''; public static registerRunningWorkspace(workspaceName: string) { Logger.debug(`CheReporter.registerRunningWorkspace {${workspaceName}}`); @@ -192,7 +192,7 @@ class CheReporter extends mocha.reporters.Spec { // stop and remove running workspace if (TestConstants.DELETE_WORKSPACE_ON_FAILED_TEST) { Logger.warn('Property DELETE_WORKSPACE_ON_FAILED_TEST se to true - trying to stop and delete running workspace.'); - await testWorkspaceUtil.cleanUpRunningWorkspace(CheReporter.latestWorkspace); + await testWorkspaceUtil.stopAndDeleteWorkspaceByName(CheReporter.latestWorkspace); } }); diff --git a/tests/e2e/index.ts b/tests/e2e/index.ts index 83a158f677d..6b51da14082 100644 --- a/tests/e2e/index.ts +++ b/tests/e2e/index.ts @@ -20,6 +20,7 @@ export * from './utils/Sanitizer'; export * from './utils/ScreenCatcher'; export * from './utils/VCS/CheGitApi'; export * from './utils/VCS/github/GitHubUtil'; +export * from './utils/workspace/ApiUrlResolver'; export * from './utils/workspace/ITestWorkspaceUtil'; export * from './utils/WorkspaceNameHandler'; export * from './utils/workspace/TestWorkspaceUtil'; diff --git a/tests/e2e/inversify.config.ts b/tests/e2e/inversify.config.ts index 2bb93986d1d..ddb16453c21 100644 --- a/tests/e2e/inversify.config.ts +++ b/tests/e2e/inversify.config.ts @@ -12,7 +12,6 @@ import { Container } from 'inversify'; import { IDriver } from './driver/IDriver'; import { ChromeDriver } from './driver/ChromeDriver'; import { TYPES, CLASSES } from './inversify.types'; -import { ITestWorkspaceUtil } from './utils/workspace/ITestWorkspaceUtil'; import { TestWorkspaceUtil } from './utils/workspace/TestWorkspaceUtil'; import { IOcpLoginPage } from './pageobjects/login/IOcpLoginPage'; import { OcpUserLoginPage } from './pageobjects/login/OcpUserLoginPage'; @@ -70,13 +69,15 @@ import { AnimationChecker } from './utils/AnimationChecker'; import { WorkspaceNameHandler } from './utils/WorkspaceNameHandler'; import { Sanitizer } from './utils/Sanitizer'; import { NavigationBar } from './pageobjects/ide/NavigationBar'; +import { ApiUrlResolver } from './utils/workspace/ApiUrlResolver'; +import { ITestWorkspaceUtil } from './utils/workspace/ITestWorkspaceUtil'; + const e2eContainer: Container = new Container({ defaultScope: 'Transient' }); e2eContainer.bind(TYPES.Driver).to(ChromeDriver).inSingletonScope(); e2eContainer.bind(TYPES.WorkspaceUtil).to(TestWorkspaceUtil); e2eContainer.bind(TYPES.OcpLogin).to(OcpUserLoginPage); - e2eContainer.bind(TYPES.IAuthorizationHeaderHandler).to(CheMultiuserAuthorizationHeaderHandler); e2eContainer.bind(TYPES.ITokenHandler).to(CheMultiuserTokenHandler); @@ -132,5 +133,6 @@ e2eContainer.bind(CLASSES.GitOauthAppsSettings).to(GitOaut e2eContainer.bind(CLASSES.AnimationChecker).to(AnimationChecker); e2eContainer.bind(CLASSES.Sanitizer).to(Sanitizer); e2eContainer.bind(CLASSES.NavigationBar).to(NavigationBar); +e2eContainer.bind(CLASSES.ApiUrlResolver).to(ApiUrlResolver); export { e2eContainer }; diff --git a/tests/e2e/inversify.types.ts b/tests/e2e/inversify.types.ts index 45828b1392c..57c60fccf86 100644 --- a/tests/e2e/inversify.types.ts +++ b/tests/e2e/inversify.types.ts @@ -66,7 +66,8 @@ const CLASSES = { GitOauthAppsSettings: 'GitOauthAppsSettings', AnimationChecker: 'AnimationChecker', Sanitizer: 'Sanitizer', - NavigationBar: 'NavigationBar' + NavigationBar: 'NavigationBar', + ApiUrlResolver: 'ApiUrlResolver' }; export { TYPES, CLASSES }; diff --git a/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts b/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts index b1ad1c14d29..525a02aa821 100644 --- a/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts +++ b/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts @@ -14,10 +14,10 @@ import 'reflect-metadata'; import { TestConstants } from '../../../TestConstants'; import { By } from 'selenium-webdriver'; import { Ide } from '../../ide/Ide'; -import { ITestWorkspaceUtil } from '../../../utils/workspace/ITestWorkspaceUtil'; import { WorkspaceStatus } from '../../../utils/workspace/WorkspaceStatus'; import { Logger } from '../../../utils/Logger'; import { TimeoutConstants } from '../../../TimeoutConstants'; +import { ITestWorkspaceUtil } from '../../../utils/workspace/ITestWorkspaceUtil'; @injectable() @@ -29,7 +29,7 @@ export class WorkspaceDetails { private static readonly WORKSPACE_DETAILS_LOADER_CSS: string = 'workspace-details-overview md-progress-linear'; constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, - @inject(TYPES.WorkspaceUtil) private readonly testWorkspaceUtil: ITestWorkspaceUtil) { } + @inject(TYPES.WorkspaceUtil) private readonly testWorkspaceUtil: ITestWorkspaceUtil) { } async waitLoaderDisappearance(attempts: number = TestConstants.TS_SELENIUM_DEFAULT_ATTEMPTS, polling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING) { Logger.debug('WorkspaceDetails.waitLoaderDisappearance'); diff --git a/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetailsPlugins.ts b/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetailsPlugins.ts index 5b05316e63a..79423aaf864 100644 --- a/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetailsPlugins.ts +++ b/tests/e2e/pageobjects/dashboard/workspace-details/WorkspaceDetailsPlugins.ts @@ -13,17 +13,17 @@ import 'reflect-metadata'; import { CLASSES, TYPES } from '../../../inversify.types'; import { By } from 'selenium-webdriver'; import { WorkspaceDetails } from './WorkspaceDetails'; -import { ITestWorkspaceUtil } from '../../../utils/workspace/ITestWorkspaceUtil'; import { WorkspaceStatus } from '../../../utils/workspace/WorkspaceStatus'; import { Logger } from '../../../utils/Logger'; import { TimeoutConstants } from '../../../TimeoutConstants'; +import { ITestWorkspaceUtil } from '../../../utils/workspace/ITestWorkspaceUtil'; @injectable() export class WorkspaceDetailsPlugins { constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, - @inject(CLASSES.WorkspaceDetails) private readonly workspaceDetails: WorkspaceDetails, - @inject(TYPES.WorkspaceUtil) private readonly testWorkspaceUtil: ITestWorkspaceUtil) { } + @inject(CLASSES.WorkspaceDetails) private readonly workspaceDetails: WorkspaceDetails, + @inject(TYPES.WorkspaceUtil) private readonly testWorkspaceUtil: ITestWorkspaceUtil) { } async waitPluginListItem(pluginName: string) { Logger.debug(`WorkspaceDetailsPlugins.waitPluginListItem ${pluginName}`); diff --git a/tests/e2e/pageobjects/ide/ProjectTree.ts b/tests/e2e/pageobjects/ide/ProjectTree.ts index d32ef68337e..a7bd04f940d 100644 --- a/tests/e2e/pageobjects/ide/ProjectTree.ts +++ b/tests/e2e/pageobjects/ide/ProjectTree.ts @@ -235,13 +235,16 @@ export class ProjectTree { for (let i = 0; i < attempts; i++) { // do five checks of the item in one fifth of the time given for root folder item (was causing frequent reloads of the workspace) - const isProjectFolderVisible = await this.driverHelper.waitVisibilityBoolean(rootItemLocator, 5, visibilityItemPolling / 5); + const isRootFolderVisible = await this.driverHelper.waitVisibilityBoolean(rootItemLocator, 5, visibilityItemPolling / 5); - if (!isProjectFolderVisible) { + if (!isRootFolderVisible) { Logger.trace(`ProjectTree.waitProjectImported project not located, reloading page.`); await this.browserTabsUtil.refreshPage(); await this.ide.waitWorkspaceAndIde(); await this.openProjectTreeContainer(); + if (i === attempts - 1) { + throw new error.TimeoutError('Exceeded the maximum number of checking attempts, project has not been imported [unable to locate project root folder]'); + } continue; } @@ -250,20 +253,22 @@ export class ProjectTree { await this.waitItemExpanded(rootItem); // do five checks of the item in one fifth of the time given for root folder item (was causing frequent reloads of the workspace) - const isRootSubItemVisible = await this.driverHelper.waitVisibilityBoolean(rootSubitemLocator, 5, visibilityItemPolling / 5); + const isSubfolderVisible = await this.driverHelper.waitVisibilityBoolean(rootSubitemLocator, 5, visibilityItemPolling / 5); - if (!isRootSubItemVisible) { + if (!isSubfolderVisible) { Logger.trace(`ProjectTree.waitProjectImported sub-items not found, reloading page.`); await this.browserTabsUtil.refreshPage(); await this.ide.waitWorkspaceAndIde(); await this.openProjectTreeContainer(); + if (i === attempts - 1) { + throw new error.TimeoutError('Exceeded the maximum number of checking attempts, project has not been imported [unable to locate project subfolder]'); + } continue; } - return; - } - - throw new error.TimeoutError('Exceeded the maximum number of checking attempts, project has not been imported'); + Logger.trace(`ProjectTree.waitProjectImported project successfully imported`); + break; + } } async waitProjectImportedNoSubfolder(projectName: string, diff --git a/tests/e2e/tests/devfiles/CSlashCPlusPlus.spec.ts b/tests/e2e/tests/devfiles/CSlashCPlusPlus.spec.ts index 5a19971e311..abacb6c646a 100644 --- a/tests/e2e/tests/devfiles/CSlashCPlusPlus.spec.ts +++ b/tests/e2e/tests/devfiles/CSlashCPlusPlus.spec.ts @@ -29,17 +29,14 @@ const tabTitle: string = 'hello.cpp'; const buildTaskName: string = 'build'; const runTaskName: string = 'run'; const stack: string = 'C/C++'; -let workspaceName: string; suite(`${stack} test`, async () => { suite(`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadinessNoSubfolder(workspaceSampleName, false); }); @@ -63,7 +60,7 @@ suite(`${stack} test`, async () => { suite('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/devfiles/DevfileSmoke.spec.ts b/tests/e2e/tests/devfiles/DevfileSmoke.spec.ts index 65129fda922..e9d83b213b6 100644 --- a/tests/e2e/tests/devfiles/DevfileSmoke.spec.ts +++ b/tests/e2e/tests/devfiles/DevfileSmoke.spec.ts @@ -9,13 +9,13 @@ **********************************************************************/ import 'reflect-metadata'; import { CLASSES } from '../../inversify.types'; -import CheReporter from '../../driver/CheReporter'; import { e2eContainer } from '../../inversify.config'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { NavigationBar } from '../../pageobjects/ide/NavigationBar'; import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import CheReporter from '../../driver/CheReporter'; const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const preferencesHandler: PreferencesHandler = e2eContainer.get(CLASSES.PreferencesHandler); @@ -26,17 +26,14 @@ const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); const workspaceSampleName: string = 'console-java-simple'; const workspaceRootFolderName: string = 'src'; const stack: string = 'Java Maven'; -let workspaceName: string; suite(`${stack} test`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); test('Set application.confirmExit user preferences to "never"', async () => { @@ -47,7 +44,7 @@ suite(`${stack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { await navigationBar.openNavigationBar(); - await dashboard.stopAndRemoveWorkspaceByUI(workspaceName); + await dashboard.stopAndRemoveWorkspaceByUI(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/DotNetCore.spec.ts b/tests/e2e/tests/devfiles/DotNetCore.spec.ts index a3cf3592740..3518e46cdfd 100644 --- a/tests/e2e/tests/devfiles/DotNetCore.spec.ts +++ b/tests/e2e/tests/devfiles/DotNetCore.spec.ts @@ -32,17 +32,14 @@ const updateDependenciesTaskName: string = 'update dependencies'; const buildTaskName: string = 'build'; const runTaskName: string = 'run'; const runTaskNameExpectedString: string = 'Process 5000-tcp is now listening on port 5000. Open it ?'; -let workspaceName: string; suite(`Test ${stack}`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadinessNoSubfolder(workspaceSampleName, false); }); @@ -75,7 +72,7 @@ suite(`Test ${stack}`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/Go.spec.ts b/tests/e2e/tests/devfiles/Go.spec.ts index 2b51c272e08..232c7a2e54c 100644 --- a/tests/e2e/tests/devfiles/Go.spec.ts +++ b/tests/e2e/tests/devfiles/Go.spec.ts @@ -34,15 +34,14 @@ const taskRunServer: string = 'run-outyet'; const taskStopServer: string = 'stop-outyet'; const taskTestOutyet: string = 'test-outyet'; const notificationText: string = 'Process 8080-tcp is now listening on port 8080. Open it ?'; -let workspaceName: string; suite(`${workspaceStack} test`, async () => { suite(`Create ${workspaceStack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(workspaceStack); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceSubfolderName, false); test('Workaround for issue #16113', async () => { @@ -75,7 +74,7 @@ suite(`${workspaceStack} test`, async () => { suite('Stop and remove workspace', async() => { test(`Stop and remove workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/devfiles/JavaMaven.spec.ts b/tests/e2e/tests/devfiles/JavaMaven.spec.ts index eead15cf652..e15f0234294 100644 --- a/tests/e2e/tests/devfiles/JavaMaven.spec.ts +++ b/tests/e2e/tests/devfiles/JavaMaven.spec.ts @@ -28,17 +28,14 @@ const tabTitle: string = 'HelloWorld.java'; const codeNavigationClassName: string = 'String.class'; const stack : string = 'Java Maven'; const taskName: string = 'maven build'; -let workspaceName: string; suite(`${stack} test`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -61,7 +58,7 @@ suite(`${stack} test`, async () => { suite('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/JavaSpringBoot.spec.ts b/tests/e2e/tests/devfiles/JavaSpringBoot.spec.ts index 2419caa440f..af2b3fb7823 100644 --- a/tests/e2e/tests/devfiles/JavaSpringBoot.spec.ts +++ b/tests/e2e/tests/devfiles/JavaSpringBoot.spec.ts @@ -30,17 +30,14 @@ const codeNavigationClassName: string = 'SpringApplication.class'; const buildTaskName: string = 'maven build'; const runTaskName: string = 'run webapp'; const runTaskExpectedDialogue: string = 'Process 8080-tcp is now listening on port 8080. Open it ?'; -let workspaceName: string; suite(`${stack} test`, async () => { suite(`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -68,7 +65,7 @@ suite(`${stack} test`, async () => { suite('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/JavaVertx.spec.ts b/tests/e2e/tests/devfiles/JavaVertx.spec.ts index 3fd55681008..886cb9a0ec2 100644 --- a/tests/e2e/tests/devfiles/JavaVertx.spec.ts +++ b/tests/e2e/tests/devfiles/JavaVertx.spec.ts @@ -28,17 +28,14 @@ const tabTitle: string = 'HttpApplication.java'; const codeNavigationClassName: string = 'RouterImpl.class'; const buildTaskName: string = 'maven build'; const stack: string = 'Java Vert.x'; -let workspaceName: string; suite(`${stack} test`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -61,7 +58,7 @@ suite(`${stack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/devfiles/NodeJS.spec.ts b/tests/e2e/tests/devfiles/NodeJS.spec.ts index 53bc6be8ac2..5841b59415e 100644 --- a/tests/e2e/tests/devfiles/NodeJS.spec.ts +++ b/tests/e2e/tests/devfiles/NodeJS.spec.ts @@ -30,18 +30,15 @@ const fileName: string = `app.js`; const taskDownloadDependencies: string = 'download dependencies'; const taskRunWebApp: string = 'run the web app'; const taskExpectedDialogText: string = 'Process nodejs is now listening on port 3000. Open it ?'; -let workspaceName: string; suite(`${workspaceStack} test`, async () => { suite(`Create ${workspaceStack}`, async () => { workspaceHandlingTests.createAndOpenWorkspace(workspaceStack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -68,7 +65,7 @@ suite(`${workspaceStack} test`, async () => { suite('Stop and remove workspace', async() => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/PHPSimple.spec.ts b/tests/e2e/tests/devfiles/PHPSimple.spec.ts index 3de48a2551f..cf59ddd7041 100644 --- a/tests/e2e/tests/devfiles/PHPSimple.spec.ts +++ b/tests/e2e/tests/devfiles/PHPSimple.spec.ts @@ -30,17 +30,14 @@ const tabTitle: string = 'index.php'; const depTaskName: string = 'Configure Apache Web Server DocumentRoot'; const buildTaskName: string = 'Start Apache Web Server'; const stack: string = 'PHP Simple'; -let workspaceName: string; suite(`${stack} test`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadinessNoSubfolder(workspaceSampleName, false); }); @@ -67,7 +64,7 @@ suite(`${stack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/devfiles/Python.spec.ts b/tests/e2e/tests/devfiles/Python.spec.ts index d3cc54c52ca..1ea257ff7bf 100644 --- a/tests/e2e/tests/devfiles/Python.spec.ts +++ b/tests/e2e/tests/devfiles/Python.spec.ts @@ -27,18 +27,15 @@ const workspaceSampleName: string = 'python-hello-world'; const taskRunName: string = 'run'; const fileFolderPath: string = `${workspaceSampleName}`; const fileName: string = `hello-world.py`; -let workspaceName: string; suite(`${workspaceStack} test`, async () => { suite(`Create ${workspaceStack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(workspaceStack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadinessNoSubfolder(workspaceSampleName, false); }); @@ -61,7 +58,7 @@ suite(`${workspaceStack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/PythonDjango.spec.ts b/tests/e2e/tests/devfiles/PythonDjango.spec.ts index 74a83365775..70b29bc8766 100644 --- a/tests/e2e/tests/devfiles/PythonDjango.spec.ts +++ b/tests/e2e/tests/devfiles/PythonDjango.spec.ts @@ -29,18 +29,15 @@ const taskRunServer: string = 'run server'; const taskRunServerInDebugMode: string = 'run server in debug mode'; const taskExpectedDialogText: string = 'Process django is now listening on port 7000. Open it ?'; const taskExpectedDialogTextInDebugMode: string = 'A new process is now listening on port 5678 but this port is not a current endpoint. Would you want to add a redirect for this port so it becomes available ?'; -let workspaceName: string; suite(`${workspaceStack} test`, async () => { suite(`Create ${workspaceStack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(workspaceStack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -64,7 +61,7 @@ suite(`${workspaceStack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/Quarkus.spec.ts b/tests/e2e/tests/devfiles/Quarkus.spec.ts index 0516fdcab08..7a963ff6cf0 100644 --- a/tests/e2e/tests/devfiles/Quarkus.spec.ts +++ b/tests/e2e/tests/devfiles/Quarkus.spec.ts @@ -30,17 +30,14 @@ const fileName: string = `GreetingService.java`; const taskPackage: string = 'Package'; const taskPackageNative: string = 'Package Native'; const taskStartNative: string = 'Start Native'; -let workspaceName: string; suite(`${workspaceStack} test`, async () => { suite(`Create ${workspaceStack}`, async () => { workspaceHandlingTests.createAndOpenWorkspace(workspaceStack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -73,7 +70,7 @@ suite(`${workspaceStack} test`, async () => { suite('Stop and remove workspace', async() => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); }); diff --git a/tests/e2e/tests/devfiles/Scala.spec.ts b/tests/e2e/tests/devfiles/Scala.spec.ts index b535198e4a9..95460b340f4 100644 --- a/tests/e2e/tests/devfiles/Scala.spec.ts +++ b/tests/e2e/tests/devfiles/Scala.spec.ts @@ -29,18 +29,15 @@ const compileTaskkName: string = 'sbt compile'; const runTaskName: string = 'sbt run'; const testTaskName: string = 'sbt test'; const stack: string = 'Scala'; -let workspaceName: string; // skipping scala to enable pre-release suite to be easily used for updates until https://github.com/eclipse/che/issues/18662 is fixed suite.skip(`${stack} test`, async () => { suite (`Create ${stack} workspace`, async () => { workspaceHandlingTests.createAndOpenWorkspace(stack); - + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); test('Register running workspace', async () => { - workspaceName = WorkspaceHandlingTests.getWorkspaceName(); - CheReporter.registerRunningWorkspace(workspaceName); + CheReporter.registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); - projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName, false); }); @@ -67,8 +64,7 @@ suite.skip(`${stack} test`, async () => { suite ('Stopping and deleting the workspace', async () => { test(`Stop and remowe workspace`, async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); - }); diff --git a/tests/e2e/tests/e2e/FactoryUrl.spec.ts b/tests/e2e/tests/e2e/FactoryUrl.spec.ts index 4e07934e833..fa90f5827d2 100644 --- a/tests/e2e/tests/e2e/FactoryUrl.spec.ts +++ b/tests/e2e/tests/e2e/FactoryUrl.spec.ts @@ -12,20 +12,18 @@ import { e2eContainer } from '../../inversify.config'; import { CLASSES, TYPES } from '../../inversify.types'; import { TestConstants } from '../../TestConstants'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; -import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); -const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const factoryUrl : string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=https://raw.githubusercontent.com/eclipse/che-devfile-registry/master/devfiles/java-maven/devfile.yaml`; const workspaceSampleName: string = 'console-java-simple'; const workspaceRootFolderName: string = 'src'; -let workspaceName: string; // the suite expect user to be logged in suite('Workspace creation via factory url', async () => { @@ -36,15 +34,13 @@ suite('Workspace creation via factory url', async () => { }); suite('Wait workspace readyness', async () => { + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName); }); suite ('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); - - await testWorkspaceUtils.cleanUpRunningWorkspace(workspaceName); + await testWorkspaceUtils.cleanUpRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/e2e/GitPublishBranch.spec.ts b/tests/e2e/tests/e2e/GitPublishBranch.spec.ts index d6e6a7958ca..15000d63679 100644 --- a/tests/e2e/tests/e2e/GitPublishBranch.spec.ts +++ b/tests/e2e/tests/e2e/GitPublishBranch.spec.ts @@ -18,12 +18,13 @@ import { QuickOpenContainer } from '../../pageobjects/ide/QuickOpenContainer'; import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage'; import { TestConstants } from '../../TestConstants'; import { DriverHelper } from '../../utils/DriverHelper'; -import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; import { TopMenu } from '../../pageobjects/ide/TopMenu'; import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; import { By } from 'selenium-webdriver'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; +import CheReporter from '../../driver/CheReporter'; const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); @@ -34,7 +35,7 @@ const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); const loginPage: ICheLoginPage = e2eContainer.get(TYPES.CheLogin); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); const gitPlugin: GitPlugin = e2eContainer.get(CLASSES.GitPlugin); -const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const workspacePrefixUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/dashboard/#/ide/${TestConstants.TS_SELENIUM_USERNAME}/`; @@ -53,6 +54,7 @@ suite('Publish branch in git extension', async () => { test('Login into workspace', async () => { await browserTabsUtil.navigateTo(workspacePrefixUrl + wsNameGitPublishBranch); await loginPage.login(); + WorkspaceHandlingTests.setWorkspaceName(wsNameGitPublishBranch); CheReporter.registerRunningWorkspace(wsNameGitPublishBranch); await ide.waitWorkspaceAndIde(); await projectTree.openProjectTreeContainer(); diff --git a/tests/e2e/tests/e2e/GitSelfSignCert.spec.ts b/tests/e2e/tests/e2e/GitSelfSignCert.spec.ts index dfdab848a8d..717365d20fb 100644 --- a/tests/e2e/tests/e2e/GitSelfSignCert.spec.ts +++ b/tests/e2e/tests/e2e/GitSelfSignCert.spec.ts @@ -8,68 +8,71 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ - import { e2eContainer } from '../../inversify.config'; - import { CLASSES, TYPES } from '../../inversify.types'; - import { GitPlugin } from '../../pageobjects/ide/plugins/GitPlugin'; - import { Ide } from '../../pageobjects/ide/Ide'; - import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; - import { QuickOpenContainer } from '../../pageobjects/ide/QuickOpenContainer'; - import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage'; - import { TestConstants } from '../../TestConstants'; - import { DriverHelper } from '../../utils/DriverHelper'; - import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; - import { TopMenu } from '../../pageobjects/ide/TopMenu'; - import { TimeoutConstants } from '../../TimeoutConstants'; - import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; - import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; - import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; - import { Editor } from '../../pageobjects/ide/Editor'; +import { e2eContainer } from '../../inversify.config'; +import { CLASSES, TYPES } from '../../inversify.types'; +import { GitPlugin } from '../../pageobjects/ide/plugins/GitPlugin'; +import { Ide } from '../../pageobjects/ide/Ide'; +import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; +import { QuickOpenContainer } from '../../pageobjects/ide/QuickOpenContainer'; +import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage'; +import { TestConstants } from '../../TestConstants'; +import { DriverHelper } from '../../utils/DriverHelper'; +import { TopMenu } from '../../pageobjects/ide/TopMenu'; +import { TimeoutConstants } from '../../TimeoutConstants'; +import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; +import { Editor } from '../../pageobjects/ide/Editor'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import CheReporter from '../../driver/CheReporter'; - const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); - const ide: Ide = e2eContainer.get(CLASSES.Ide); - const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); - const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer); - const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); - const loginPage: ICheLoginPage = e2eContainer.get(TYPES.CheLogin); - const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); - const gitPlugin: GitPlugin = e2eContainer.get(CLASSES.GitPlugin); - const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); - const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); - const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); - const editor: Editor = e2eContainer.get(CLASSES.Editor); +const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); +const ide: Ide = e2eContainer.get(CLASSES.Ide); +const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); +const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer); +const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); +const loginPage: ICheLoginPage = e2eContainer.get(TYPES.CheLogin); +const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); +const gitPlugin: GitPlugin = e2eContainer.get(CLASSES.GitPlugin); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); +const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); +const editor: Editor = e2eContainer.get(CLASSES.Editor); - const workspaceName = 'gitSelfSignCert'; +const workspaceName = 'gitSelfSignCert'; - suite('Checking git + self sign cert', async () => { - const workspacePrefixUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/dashboard/#/ide/${TestConstants.TS_SELENIUM_USERNAME}/`; - const gitProjectUrl = `https://${TestConstants.TS_SELF_HOSTED_GIT_SERVER_URL}/maxura/gitService.git`; - const committedFile = 'README.md'; +suite('Checking git + self sign cert', async () => { + const workspacePrefixUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/dashboard/#/ide/${TestConstants.TS_SELENIUM_USERNAME}/`; + const gitProjectUrl = `https://${TestConstants.TS_SELF_HOSTED_GIT_SERVER_URL}/maxura/gitService.git`; + const committedFile = 'README.md'; - suiteSetup(async function () { - const wsConfig = await testWorkspaceUtils.getBaseDevfile(); - wsConfig.metadata!.name = workspaceName; - await browserTabsUtil.navigateTo(TestConstants.TS_SELENIUM_BASE_URL); - await loginPage.login(); - await testWorkspaceUtils.createWsFromDevFile(wsConfig); - }); + suiteSetup(async function () { + const wsConfig = await testWorkspaceUtils.getBaseDevfile(); + wsConfig.metadata!.name = workspaceName; + WorkspaceHandlingTests.setWorkspaceName(workspaceName); + CheReporter.registerRunningWorkspace(workspaceName); + await browserTabsUtil.navigateTo(TestConstants.TS_SELENIUM_BASE_URL); + await loginPage.login(); + await testWorkspaceUtils.createWsFromDevFile(wsConfig); + }); - test('Wait until created workspace is started', async () => { - await dashboard.waitPage(); - await browserTabsUtil.navigateTo(workspacePrefixUrl + workspaceName); - await ide.waitWorkspaceAndIde(); - await projectTree.openProjectTreeContainer(); - await driverHelper.wait(TimeoutConstants.TS_SELENIUM_LOAD_PAGE_TIMEOUT); - }); + test('Wait until created workspace is started', async () => { + await dashboard.waitPage(); + await browserTabsUtil.navigateTo(workspacePrefixUrl + workspaceName); + await ide.waitWorkspaceAndIde(); + await projectTree.openProjectTreeContainer(); + await driverHelper.wait(TimeoutConstants.TS_SELENIUM_LOAD_PAGE_TIMEOUT); + }); - test('Clone project', async () => { - await cloneTestRepo(gitProjectUrl); + test('Clone project', async () => { + await cloneTestRepo(gitProjectUrl); - await projectTree.waitProjectImportedNoSubfolder('gitService'); - await projectTree.waitItem('gitService/README.md'); - }); + await projectTree.waitProjectImportedNoSubfolder('gitService'); + await projectTree.waitItem('gitService/README.md'); + }); - test('Change commit and push', async function changeCommitAndPushFunc() { + test('Change commit and push', async function changeCommitAndPushFunc() { const currentDate: string = Date.now().toString(); await projectTree.expandPathAndOpenFile('gitService', committedFile); await editor.type(committedFile, currentDate + '\n', 1); @@ -85,23 +88,23 @@ await gitPlugin.waitDataIsSynchronized(); }); - }); +}); - suite('Stopping and deleting the workspace', async () => { +suite('Stopping and deleting the workspace', async () => { test(`Stop and remove workspace`, async () => { await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); }); }); - async function cloneTestRepo(linkToRepo: string) { - const confirmMessage = 'Clone from URL'; +async function cloneTestRepo(linkToRepo: string) { + const confirmMessage = 'Clone from URL'; - await topMenu.selectOption('View', 'Find Command...'); - // workaround - reopen 'Find Command' container - https://github.com/eclipse/che/issues/19793 - await topMenu.selectOption('View', 'Find Command...'); - await quickOpenContainer.typeAndSelectSuggestion('clone', 'Git: Clone'); - await quickOpenContainer.typeAndSelectSuggestion(linkToRepo, confirmMessage); - await gitPlugin.clickOnSelectRepositoryButton(); + await topMenu.selectOption('View', 'Find Command...'); + // workaround - reopen 'Find Command' container - https://github.com/eclipse/che/issues/19793 + await topMenu.selectOption('View', 'Find Command...'); + await quickOpenContainer.typeAndSelectSuggestion('clone', 'Git: Clone'); + await quickOpenContainer.typeAndSelectSuggestion(linkToRepo, confirmMessage); + await gitPlugin.clickOnSelectRepositoryButton(); - await ide.waitAndApplyTrustNotification(); - } + await ide.waitAndApplyTrustNotification(); +} diff --git a/tests/e2e/tests/e2e/GitSsh.spec.ts b/tests/e2e/tests/e2e/GitSsh.spec.ts index 7e59983f19b..323f806dfd0 100644 --- a/tests/e2e/tests/e2e/GitSsh.spec.ts +++ b/tests/e2e/tests/e2e/GitSsh.spec.ts @@ -22,11 +22,12 @@ import { DriverHelper } from '../../utils/DriverHelper'; import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; import { CheGitApi } from '../../utils/VCS/CheGitApi'; import { GitHubUtil } from '../../utils/VCS/github/GitHubUtil'; -import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; import { TopMenu } from '../../pageobjects/ide/TopMenu'; import { TimeoutConstants } from '../../TimeoutConstants'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { Dashboard } from '../..'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import CheReporter from '../../driver/CheReporter'; const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); @@ -39,7 +40,7 @@ const gitHubUtils: GitHubUtil = e2eContainer.get(CLASSES.GitHubUtil) const cheGitAPI: CheGitApi = e2eContainer.get(CLASSES.CheGitApi); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); const gitPlugin: GitPlugin = e2eContainer.get(CLASSES.GitPlugin); -const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); @@ -61,6 +62,7 @@ suite('Git with ssh workflow', async () => { test('Login into workspace and open tree container', async () => { await dashboard.openDashboard(); await browserTabsUtil.navigateTo(workspacePrefixUrl + wsNameCheckGeneratingKeys); + WorkspaceHandlingTests.setWorkspaceName(wsNameCheckGeneratingKeys); CheReporter.registerRunningWorkspace(wsNameCheckGeneratingKeys); await ide.waitWorkspaceAndIde(); await projectTree.openProjectTreeContainer(); @@ -111,7 +113,8 @@ suite('Git with ssh workflow', async () => { await testWorkspaceUtils.createWsFromDevFile(data); await dashboard.openDashboard(); await browserTabsUtil.navigateTo(workspacePrefixUrl + wsNameCheckPropagatingKeys); - CheReporter.registerRunningWorkspace(wsNameCheckPropagatingKeys); + WorkspaceHandlingTests.setWorkspaceName(wsNameCheckPropagatingKeys); + CheReporter.registerRunningWorkspace(wsNameCheckGeneratingKeys); await ide.waitWorkspaceAndIde(); await projectTree.openProjectTreeContainer(); await driverHelper.wait(TimeoutConstants.TS_PROJECT_TREE_TIMEOUT); diff --git a/tests/e2e/tests/e2e/OpenshiftConnector.spec.ts b/tests/e2e/tests/e2e/OpenshiftConnector.spec.ts index f196818efd6..283e2d479da 100644 --- a/tests/e2e/tests/e2e/OpenshiftConnector.spec.ts +++ b/tests/e2e/tests/e2e/OpenshiftConnector.spec.ts @@ -23,15 +23,16 @@ import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage'; import { TestConstants } from '../../TestConstants'; import { DriverHelper } from '../../utils/DriverHelper'; import { PreferencesHandler, TerminalRendererType } from '../../utils/PreferencesHandler'; -import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; import { TimeoutConstants } from '../../TimeoutConstants'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import CheReporter from '../../driver/CheReporter'; const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); const ide: Ide = e2eContainer.get(CLASSES.Ide); const loginPage: ICheLoginPage = e2eContainer.get(TYPES.CheLogin); -const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); const openshiftPlugin: OpenshiftPlugin = e2eContainer.get(CLASSES.OpenshiftPlugin); const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer); @@ -77,6 +78,7 @@ suite('Openshift connector user story', async () => { test('Login into workspace and open plugin', async () => { await dashboard.openDashboard(); await browserTabsUtil.navigateTo(workspacePrefixUrl + wsName); + WorkspaceHandlingTests.setWorkspaceName(wsName); CheReporter.registerRunningWorkspace(wsName); await ide.waitWorkspaceAndIde(); await projectTree.openProjectTreeContainer(); diff --git a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithKeepDirectoryTest.spec.ts b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithKeepDirectoryTest.spec.ts index e89038ca755..407876f6a45 100644 --- a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithKeepDirectoryTest.spec.ts +++ b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithKeepDirectoryTest.spec.ts @@ -12,7 +12,6 @@ import { e2eContainer } from '../../../inversify.config'; import { CLASSES } from '../../../inversify.types'; import { TestConstants } from '../../../TestConstants'; import { ProjectAndFileTests } from '../../../testsLibrary/ProjectAndFileTests'; -import CheReporter from '../../../driver/CheReporter'; import { BrowserTabsUtil } from '../../../utils/BrowserTabsUtil'; import { WorkspaceHandlingTests } from '../../../testsLibrary/WorkspaceHandlingTests'; import { PreferencesHandler } from '../../../utils/PreferencesHandler'; @@ -28,7 +27,6 @@ const workspaceRootFolderName: string = 'src'; const fileName: string = 'pom.xml'; const fileFolderPath: string = `${workspaceSampleName}/${workspaceRootFolderName}/main/java/org/eclipse/che/examples`; const tabTitle: string = 'HelloWorld.java'; -let workspaceName: string = 'console-java-simple'; suite('Workspace creation via factory url', async () => { suite('Open factory URL', async () => { @@ -38,11 +36,10 @@ suite('Workspace creation via factory url', async () => { }); suite('Wait workspace readyness', async () => { + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName); test('Set confirmExit preference to never', async () => { - CheReporter.registerRunningWorkspace(workspaceName); - await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -56,7 +53,7 @@ suite('Workspace creation via factory url', async () => { suite ('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithRootFolderTest.spec.ts b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithRootFolderTest.spec.ts index 403014303e3..f4e5f12f7b0 100644 --- a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithRootFolderTest.spec.ts +++ b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithRootFolderTest.spec.ts @@ -12,7 +12,6 @@ import { e2eContainer } from '../../../inversify.config'; import { CLASSES } from '../../../inversify.types'; import { TestConstants } from '../../../TestConstants'; import { ProjectAndFileTests } from '../../../testsLibrary/ProjectAndFileTests'; -import CheReporter from '../../../driver/CheReporter'; import { BrowserTabsUtil } from '../../../utils/BrowserTabsUtil'; import { WorkspaceHandlingTests } from '../../../testsLibrary/WorkspaceHandlingTests'; import { PreferencesHandler } from '../../../utils/PreferencesHandler'; @@ -27,7 +26,6 @@ const workspaceSampleName: string = 'console-java-simple'; const workspaceRootFolderName: string = 'src'; const fileFolderPath: string = `${workspaceSampleName}/${workspaceRootFolderName}/main/java/org/eclipse/che/examples`; const tabTitle: string = 'HelloWorld.java'; -let workspaceName: string = 'console-java-simple'; suite('Workspace creation via factory url', async () => { suite('Open factory URL', async () => { @@ -37,11 +35,10 @@ suite('Workspace creation via factory url', async () => { }); suite('Wait workspace readyness', async () => { + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName); test('Set confirmExit preference to never', async () => { - CheReporter.registerRunningWorkspace(workspaceName); - await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -53,7 +50,7 @@ suite('Workspace creation via factory url', async () => { suite ('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithSpecificBranchTest.spec.ts b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithSpecificBranchTest.spec.ts index b347f0a8297..111f2e718c1 100644 --- a/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithSpecificBranchTest.spec.ts +++ b/tests/e2e/tests/e2e/factories/DirectUrlFactoryWithSpecificBranchTest.spec.ts @@ -12,7 +12,6 @@ import { e2eContainer } from '../../../inversify.config'; import { CLASSES } from '../../../inversify.types'; import { TestConstants } from '../../../TestConstants'; import { ProjectAndFileTests } from '../../../testsLibrary/ProjectAndFileTests'; -import CheReporter from '../../../driver/CheReporter'; import { BrowserTabsUtil } from '../../../utils/BrowserTabsUtil'; import { WorkspaceHandlingTests } from '../../../testsLibrary/WorkspaceHandlingTests'; import { PreferencesHandler } from '../../../utils/PreferencesHandler'; @@ -27,7 +26,6 @@ const workspaceSampleName: string = 'console-java-simple'; const workspaceRootFolderName: string = 'src'; const fileFolderPath: string = `${workspaceSampleName}/${workspaceRootFolderName}/main/java/org/eclipse/che/examples`; const tabTitle: string = 'HelloWorld.java'; -let workspaceName: string = 'console-java-simple'; suite('Workspace creation via factory url', async () => { suite('Open factory URL', async () => { @@ -37,11 +35,10 @@ suite('Workspace creation via factory url', async () => { }); suite('Wait workspace readyness', async () => { + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); projectAndFileTests.waitWorkspaceReadiness(workspaceSampleName, workspaceRootFolderName); test('Set confirmExit preference to never', async () => { - CheReporter.registerRunningWorkspace(workspaceName); - await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -53,7 +50,7 @@ suite('Workspace creation via factory url', async () => { suite ('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); }); }); diff --git a/tests/e2e/tests/e2e_happy_path/DevWorkspaceHappyPath.spec.ts b/tests/e2e/tests/e2e_happy_path/DevWorkspaceHappyPath.spec.ts index d2646be5e6a..168ec0ffc68 100644 --- a/tests/e2e/tests/e2e_happy_path/DevWorkspaceHappyPath.spec.ts +++ b/tests/e2e/tests/e2e_happy_path/DevWorkspaceHappyPath.spec.ts @@ -24,6 +24,7 @@ import { TimeoutConstants } from '../../TimeoutConstants'; import { TopMenu } from '../../pageobjects/ide/TopMenu'; import * as fs from 'fs'; import axios from 'axios'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import CheReporter from '../../driver/CheReporter'; const ide: Ide = e2eContainer.get(CLASSES.Ide); @@ -65,6 +66,7 @@ suite('Workspace creation via factory url', async () => { }); test('Register running workspace', async () => { + WorkspaceHandlingTests.setWorkspaceName(projectName); CheReporter.registerRunningWorkspace(projectName); }); diff --git a/tests/e2e/tests/e2e_happy_path/HappyPath.spec.ts b/tests/e2e/tests/e2e_happy_path/HappyPath.spec.ts index 011213111f6..ea237f2d887 100644 --- a/tests/e2e/tests/e2e_happy_path/HappyPath.spec.ts +++ b/tests/e2e/tests/e2e_happy_path/HappyPath.spec.ts @@ -28,6 +28,7 @@ import { TimeoutConstants } from '../../TimeoutConstants'; import { Logger } from '../../utils/Logger'; import { RightToolBar } from '../../pageobjects/ide/RightToolBar'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import CheReporter from '../../driver/CheReporter'; const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); @@ -75,11 +76,12 @@ suite('Validation of workspace start', async () => { }); test('Register running workspace', async () => { + WorkspaceHandlingTests.setWorkspaceName(workspaceName); CheReporter.registerRunningWorkspace(workspaceName); }); test('Wait for workspace readiness', async () => { - await ide.waitAndSwitchToIdeFrame(); + // await ide.waitAndSwitchToIdeFrame(); test is outdated, should be deprecated. await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await projectTree.openProjectTreeContainer(); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); @@ -126,7 +128,7 @@ suite('Language server validation', async () => { } catch (err) { Logger.debug('Workaround for the https://github.com/eclipse/che/issues/18974.'); await browserTabsUtil.refreshPage(); - await ide.waitAndSwitchToIdeFrame(); + // await ide.waitAndSwitchToIdeFrame(); test is outdated, should be deprecated. await ide.waitIde(); await editor.waitErrorInLine(30, javaFileName, TimeoutConstants.TS_ERROR_HIGHLIGHTING_TIMEOUT * 2); } @@ -240,10 +242,11 @@ suite('Validation of debug functionality', async () => { }); test('Check content of the launched application', async () => { - await previewWidget.waitAndSwitchToWidgetFrame(); + await previewWidget.waitAndSwitchToWidgetFrame(); // test is outdated, should be deprecated. await previewWidget.waitAndClick(SpringAppLocators.springHomeButtonLocator); await driverHelper.getDriver().switchTo().defaultContent(); - await ide.waitAndSwitchToIdeFrame(); + // await ide.waitAndSwitchToIdeFrame(); test is outdated, should be deprecated. + await ide.waitIde(); }); test('Open debug view', async () => { @@ -280,7 +283,7 @@ suite('Validation of debug functionality', async () => { }); async function checkErrorMessageInApplicationController() { - await previewWidget.waitAndSwitchToWidgetFrame(); + await previewWidget.waitAndSwitchToWidgetFrame(); // test is outdated, should be deprecated. await previewWidget.waitAndClick(SpringAppLocators.springMenuButtonLocator); await previewWidget.waitAndClick(SpringAppLocators.springErrorButtonLocator); @@ -289,15 +292,17 @@ async function checkErrorMessageInApplicationController() { } catch (err) { await driverHelper.getDriver().switchTo().defaultContent(); - await ide.waitAndSwitchToIdeFrame(); + // await ide.waitAndSwitchToIdeFrame(); test is outdated, should be deprecated. + await ide.waitIde(); - await previewWidget.waitAndSwitchToWidgetFrame(); + await previewWidget.waitAndSwitchToWidgetFrame(); // test is outdated, should be deprecated. await previewWidget.waitVisibility(SpringAppLocators.springErrorMessageLocator, 15_000); } await driverHelper.getDriver().switchTo().defaultContent(); - await ide.waitAndSwitchToIdeFrame(); + // await ide.waitAndSwitchToIdeFrame(); test is outdated, should be deprecated. + await ide.waitIde(); } async function checkJavaPathCompletion() { diff --git a/tests/e2e/tests/intelij/IntelijOpenWorkspace.spec.ts b/tests/e2e/tests/intelij/IntelijOpenWorkspace.spec.ts index 0a9c963313f..87fa5e0a330 100644 --- a/tests/e2e/tests/intelij/IntelijOpenWorkspace.spec.ts +++ b/tests/e2e/tests/intelij/IntelijOpenWorkspace.spec.ts @@ -14,8 +14,6 @@ import { CLASSES } from '../../inversify.types'; import { Ide } from '../../pageobjects/ide/Ide'; import { DriverHelper } from '../../utils/DriverHelper'; import { TestConstants } from '../../TestConstants'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; -import CheReporter from '../../driver/CheReporter'; import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; @@ -23,7 +21,6 @@ const ide: Ide = e2eContainer.get(CLASSES.Ide); const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const dashboardUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}`; @@ -35,7 +32,8 @@ suite('The "IntelijOpenWorkspace" userstory', async () => { test('Wait workspace', async () => { await dashboard.waitWorkspaceStartingPage(); - CheReporter.registerRunningWorkspace(await workspaceNameHandler.getNameFromUrl()); + // todo: Fix workspace register in IntelliJ devfile - https://issues.redhat.com/browse/CRW-2954 + /* CheReporter.registerRunningWorkspace(await workspaceNameHandler.getNameFromUrl()); */ await ide.waitAndSwitchToIdeFrame(); await waitIntelijWorkspace(); }); diff --git a/tests/e2e/tests/load_test/LoadTest.spec.ts b/tests/e2e/tests/load_test/LoadTest.spec.ts index 7230d6d78a5..a4a86cfec35 100644 --- a/tests/e2e/tests/load_test/LoadTest.spec.ts +++ b/tests/e2e/tests/load_test/LoadTest.spec.ts @@ -13,16 +13,16 @@ import { CLASSES, TYPES } from '../../inversify.types'; import { Ide } from '../../pageobjects/ide/Ide'; import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage'; -import { TestWorkspaceUtil } from '../../utils/workspace/TestWorkspaceUtil'; import { TestConstants, WorkspaceNameHandler } from '../..'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const ide: Ide = e2eContainer.get(CLASSES.Ide); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); const cheLoginPage: ICheLoginPage = e2eContainer.get(TYPES.CheLogin); -const testWorkspaceUtils: TestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); +const testWorkspaceUtils: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const workspaceName: string = workspaceNameHandler.generateWorkspaceName('wksp-test-', 5); @@ -44,7 +44,7 @@ suite('Load test suite', async () => { }); test('Wait loading workspace and get time', async () => { - CheReporter.registerRunningWorkspace(workspaceName); + WorkspaceHandlingTests.setWorkspaceName(workspaceName); await ide.waitWorkspaceAndIde(); await projectTree.openProjectTreeContainer(); }); diff --git a/tests/e2e/tests/login/LinkCheAndOcpUsers.spec.ts b/tests/e2e/tests/login/LinkCheAndOcpUsers.spec.ts index 880f3cf832c..f4afdc00416 100644 --- a/tests/e2e/tests/login/LinkCheAndOcpUsers.spec.ts +++ b/tests/e2e/tests/login/LinkCheAndOcpUsers.spec.ts @@ -8,14 +8,15 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -import { TestConstants, DriverHelper, CLASSES, TYPES } from '../..'; +import { TestConstants, CLASSES, TYPES } from '../..'; import { e2eContainer } from '../../inversify.config'; import { IOcpLoginPage } from '../../pageobjects/login/IOcpLoginPage'; import { UpdateAccountInformationPage } from '../../pageobjects/login/UpdateAccountInformationPage'; import { TimeoutConstants } from '../../TimeoutConstants'; import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; -const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); +const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const ocpLogin: IOcpLoginPage = e2eContainer.get(TYPES.OcpLogin); const updateAccountInformation: UpdateAccountInformationPage = e2eContainer.get(CLASSES.UpdateAccountInformationPage); const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); @@ -24,7 +25,7 @@ const commonTimeout: number = TimeoutConstants.TS_SELENIUM_LOAD_PAGE_TIMEOUT * 2 suite('Link users', async () => { test('Login to OCP', async () => { - await driverHelper.navigateToUrl(TestConstants.TS_SELENIUM_BASE_URL); + await browserTabsUtil.navigateTo(TestConstants.TS_SELENIUM_BASE_URL); await ocpLogin.login(); await updateAccountInformation.clickToAllowSelectedPermissionsButton(commonTimeout); diff --git a/tests/e2e/tests/plugins/GitHubPullRequestPlugin.spec.ts b/tests/e2e/tests/plugins/GitHubPullRequestPlugin.spec.ts index 9b0257b72da..86b17a5ea61 100644 --- a/tests/e2e/tests/plugins/GitHubPullRequestPlugin.spec.ts +++ b/tests/e2e/tests/plugins/GitHubPullRequestPlugin.spec.ts @@ -24,7 +24,6 @@ import { GitPlugin } from '../../pageobjects/ide/plugins/GitPlugin'; import { TopMenu } from '../../pageobjects/ide/TopMenu'; import { QuickOpenContainer } from '../../pageobjects/ide/QuickOpenContainer'; import { Editor } from '../../pageobjects/ide/Editor'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { Key } from 'selenium-webdriver'; @@ -40,6 +39,7 @@ const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer); const editor: Editor = e2eContainer.get(CLASSES.Editor); const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); +const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const devfileUrl: string = `https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/GitHubPullRequestPlugin.yaml`; const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; @@ -50,7 +50,6 @@ const changedFile: string = 'README.md'; // added call back url, but needs to be re-verified const identityCallbackUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/api/oauth/callback`; const currentDate: string = Date.now().toString(); -let workspaceName: string; suite(`The 'GitHubPullRequestPlugin' test`, async () => { suite('Setup github', async () => { @@ -77,11 +76,9 @@ suite(`The 'GitHubPullRequestPlugin' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); @@ -140,7 +137,7 @@ suite(`The 'GitHubPullRequestPlugin' test`, async () => { suite('Stopping and deleting the workspace', async () => { test(`Stop and remove workspace`, async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandling.stopAndRemoveWorkspace(workspaceName); + await workspaceHandling.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/InstallPluginUsingUI.spec.ts b/tests/e2e/tests/plugins/InstallPluginUsingUI.spec.ts index 9cf5893aac2..9158ac27537 100644 --- a/tests/e2e/tests/plugins/InstallPluginUsingUI.spec.ts +++ b/tests/e2e/tests/plugins/InstallPluginUsingUI.spec.ts @@ -18,8 +18,6 @@ import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { PluginsView } from '../../pageobjects/ide/plugins/PluginsView'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; -import CheReporter from '../../driver/CheReporter'; const ide: Ide = e2eContainer.get(CLASSES.Ide); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); @@ -27,13 +25,12 @@ const pluginsView: PluginsView = e2eContainer.get(CLASSES.PluginsView); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const workspaceHandling: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); +const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const devfileUrl: string = 'https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/InstallPluginUsingUI.yaml'; const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; const pluginTitle: string = 'java11'; -let workspaceName: string; suite(`The 'InstallPluginUsingUI' test`, async () => { suite('Create workspace', async () => { @@ -41,11 +38,9 @@ suite(`The 'InstallPluginUsingUI' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await projectTree.openProjectTreeContainer(); @@ -72,7 +67,7 @@ suite(`The 'InstallPluginUsingUI' test`, async () => { suite('Stopping and deleting the workspace', async () => { test(`Stop and remove workspace`, async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandling.stopAndRemoveWorkspace(workspaceName); + await workspaceHandling.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/JavaPlugin.spec.ts b/tests/e2e/tests/plugins/JavaPlugin.spec.ts index daeac06b93d..d5d84310592 100644 --- a/tests/e2e/tests/plugins/JavaPlugin.spec.ts +++ b/tests/e2e/tests/plugins/JavaPlugin.spec.ts @@ -18,7 +18,6 @@ import { Editor } from '../../pageobjects/ide/Editor'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; @@ -37,7 +36,6 @@ const subRootFolder: string = 'backend'; const fileFolderPath: string = `${projectName}/backend/src/main/java/cloudcode/guestbook/backend`; const tabTitle: string = 'GuestBookEntry.java'; -let workspaceName: string = 'java-guestbook'; suite(`The 'JavaPlugin' test`, async () => { suite('Create workspace', async () => { @@ -45,11 +43,11 @@ suite(`The 'JavaPlugin' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); - test('Wait until created workspace is started', async () => { - CheReporter.registerRunningWorkspace(workspaceName); + projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + test('Set confirmExit preference to never', async () => { await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -91,7 +89,7 @@ suite(`The 'JavaPlugin' test`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/PhpPlugin.spec.ts b/tests/e2e/tests/plugins/PhpPlugin.spec.ts index 58c875b4fc6..d43a7878a5b 100644 --- a/tests/e2e/tests/plugins/PhpPlugin.spec.ts +++ b/tests/e2e/tests/plugins/PhpPlugin.spec.ts @@ -7,7 +7,6 @@ * * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -import { WorkspaceNameHandler } from '../..'; import 'reflect-metadata'; import { e2eContainer } from '../../inversify.config'; import { CLASSES } from '../../inversify.types'; @@ -22,7 +21,6 @@ import { DebugView } from '../../pageobjects/ide/DebugView'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const ide: Ide = e2eContainer.get(CLASSES.Ide); @@ -31,7 +29,6 @@ const editor: Editor = e2eContainer.get(CLASSES.Editor); const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); const debugView: DebugView = e2eContainer.get(CLASSES.DebugView); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const devfileUrl: string = 'https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/PhpPluginTest.yaml'; const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; @@ -40,7 +37,6 @@ const subRootFolder: string = 'README.md'; const fileFolderPath: string = `${projectName}`; const tabTitle: string = 'index.php'; -let workspaceName: string; suite(`The 'PhpPlugin' tests`, async () => { suite('Create workspace', async () => { @@ -48,11 +44,9 @@ suite(`The 'PhpPlugin' tests`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); @@ -111,7 +105,7 @@ suite(`The 'PhpPlugin' tests`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/PythonPlugin.spec.ts b/tests/e2e/tests/plugins/PythonPlugin.spec.ts index ebd3fca1f77..981306c655b 100644 --- a/tests/e2e/tests/plugins/PythonPlugin.spec.ts +++ b/tests/e2e/tests/plugins/PythonPlugin.spec.ts @@ -17,7 +17,6 @@ import { Key } from 'selenium-webdriver'; import { Editor } from '../../pageobjects/ide/Editor'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; @@ -36,7 +35,6 @@ const subRootFolder: string = '.vscode'; const fileFolderPath: string = `${projectName}`; const tabTitle: string = 'hello-world.py'; -let workspaceName: string = 'python-hello-world'; suite(`The 'PythonPlugin' test`, async () => { suite('Create workspace', async () => { @@ -44,11 +42,11 @@ suite(`The 'PythonPlugin' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); - test('Wait until created workspace is started', async () => { - CheReporter.registerRunningWorkspace(workspaceName); + projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + test('Set confirmExit preference to never', async () => { await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -78,7 +76,7 @@ suite(`The 'PythonPlugin' test`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/TypescriptPlugin.spec.ts b/tests/e2e/tests/plugins/TypescriptPlugin.spec.ts index 9053aa1efdd..6a2c7807cb7 100644 --- a/tests/e2e/tests/plugins/TypescriptPlugin.spec.ts +++ b/tests/e2e/tests/plugins/TypescriptPlugin.spec.ts @@ -23,7 +23,6 @@ import { Terminal } from '../../pageobjects/ide/Terminal'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; @@ -49,7 +48,6 @@ const fileFolderPath: string = `${projectName}`; const debugFileFolderPath: string = `${projectName}/app`; const debugFile: string = 'app.js'; const tabTitle: string = 'typescript-node-debug.ts'; -let workspaceName: string = 'typescript-plugin'; suite(`The 'TypescriptPlugin and Node-debug' tests`, async () => { suite('Create workspace', async () => { @@ -57,11 +55,11 @@ suite(`The 'TypescriptPlugin and Node-debug' tests`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); - test('Wait until created workspace is started', async () => { - CheReporter.registerRunningWorkspace(workspaceName); + projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + test('Set confirmExit preference to never', async () => { await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -160,7 +158,7 @@ suite(`The 'TypescriptPlugin and Node-debug' tests`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/VscodeKubernetesPlugin.spec.ts b/tests/e2e/tests/plugins/VscodeKubernetesPlugin.spec.ts index f74275a978a..d7e58f1e594 100644 --- a/tests/e2e/tests/plugins/VscodeKubernetesPlugin.spec.ts +++ b/tests/e2e/tests/plugins/VscodeKubernetesPlugin.spec.ts @@ -17,9 +17,7 @@ import { KubernetesPlugin } from '../../pageobjects/ide/plugins/KubernetesPlugin import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; import { TopMenu } from '../../pageobjects/ide/TopMenu'; import { QuickOpenContainer } from '../../pageobjects/ide/QuickOpenContainer'; import { OpenDialogWidget, Buttons } from '../../pageobjects/ide/OpenDialogWidget'; @@ -29,7 +27,6 @@ const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUti const ide: Ide = e2eContainer.get(CLASSES.Ide); const kubernetesPlugin: KubernetesPlugin = e2eContainer.get(CLASSES.KubernetesPlugin); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu); const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer); const openDialogWidget: OpenDialogWidget = e2eContainer.get(CLASSES.OpenDialogWidget); @@ -38,7 +35,6 @@ const devfileUrl: string = 'https://raw.githubusercontent.com/eclipse/che/main/t const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; const sampleName: string = 'nodejs-web-app'; const subRootFolder: string = 'app'; -let workspaceName: string; suite(`The 'VscodeKubernetesPlugin' test`, async () => { suite('Create workspace', async () => { @@ -46,11 +42,9 @@ suite(`The 'VscodeKubernetesPlugin' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); @@ -79,7 +73,7 @@ suite(`The 'VscodeKubernetesPlugin' test`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/VscodeShellcheckPlugin.spec.ts b/tests/e2e/tests/plugins/VscodeShellcheckPlugin.spec.ts index 3cbd87e7851..a78d960497a 100644 --- a/tests/e2e/tests/plugins/VscodeShellcheckPlugin.spec.ts +++ b/tests/e2e/tests/plugins/VscodeShellcheckPlugin.spec.ts @@ -19,9 +19,7 @@ import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; import { Key } from 'selenium-webdriver'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; import { Logger } from '../../utils/Logger'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); @@ -29,7 +27,6 @@ const ide: Ide = e2eContainer.get(CLASSES.Ide); const preferencesHandler: PreferencesHandler = e2eContainer.get(CLASSES.PreferencesHandler); const editor: Editor = e2eContainer.get(CLASSES.Editor); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const devfileUrl: string = 'https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/VscodeShellcheckPlugin.yaml'; const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; @@ -37,7 +34,6 @@ const sampleName: string = 'nodejs-web-app'; const subRootFolder: string = 'app'; const pathToFile: string = `${sampleName}`; const fileName: string = 'test.sh'; -let workspaceName: string; suite(`The 'VscodeShellcheckPlugin' test`, async () => { suite('Create workspace', async () => { @@ -52,11 +48,9 @@ suite(`The 'VscodeShellcheckPlugin' test`, async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); @@ -96,7 +90,7 @@ suite(`The 'VscodeShellcheckPlugin' test`, async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/VscodeValePlugin.spec.ts b/tests/e2e/tests/plugins/VscodeValePlugin.spec.ts index 5e6698a13d9..a02e592aef4 100644 --- a/tests/e2e/tests/plugins/VscodeValePlugin.spec.ts +++ b/tests/e2e/tests/plugins/VscodeValePlugin.spec.ts @@ -16,11 +16,9 @@ import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; import { Editor } from '../../pageobjects/ide/Editor'; import { TestConstants } from '../../TestConstants'; import { TimeoutConstants } from '../../TimeoutConstants'; -import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler'; import { Terminal } from '../../pageobjects/ide/Terminal'; import { Logger } from '../../utils/Logger'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; const ide: Ide = e2eContainer.get(CLASSES.Ide); @@ -29,14 +27,12 @@ const editor: Editor = e2eContainer.get(CLASSES.Editor); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const terminal: Terminal = e2eContainer.get(CLASSES.Terminal); const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); -const workspaceNameHandler: WorkspaceNameHandler = e2eContainer.get(CLASSES.WorkspaceNameHandler); const devfileUrl: string = 'https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/VscodeValePlugin.yaml'; const factoryUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/f?url=${devfileUrl}`; const projectName: string = 'che-docs'; const pathToFile: string = `${projectName}/modules/administration-guide/partials`; const docFileName: string = 'assembly_authenticating-users.adoc'; -let workspaceName: string = ''; suite('The "VscodeValePlugin" userstory', async () => { suite('Create workspace', async () => { @@ -44,11 +40,9 @@ suite('The "VscodeValePlugin" userstory', async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - test('Wait until created workspace is started', async () => { - await ide.waitAndSwitchToIdeFrame(); - workspaceName = await workspaceNameHandler.getNameFromUrl(); - CheReporter.registerRunningWorkspace(workspaceName); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + test('Wait until created workspace is started', async () => { await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); }); @@ -81,7 +75,7 @@ suite('The "VscodeValePlugin" userstory', async () => { suite('Stopping and deleting the workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/VscodeXmlPlugin.spec.ts b/tests/e2e/tests/plugins/VscodeXmlPlugin.spec.ts index e4afd1a8864..504df8c8b05 100644 --- a/tests/e2e/tests/plugins/VscodeXmlPlugin.spec.ts +++ b/tests/e2e/tests/plugins/VscodeXmlPlugin.spec.ts @@ -10,6 +10,7 @@ import { Key } from 'selenium-webdriver'; import { e2eContainer } from '../../inversify.config'; +import { Ide } from '../../pageobjects/ide/Ide'; import { CLASSES } from '../../inversify.types'; import { ProjectTree } from '../../pageobjects/ide/ProjectTree'; import { Editor } from '../../pageobjects/ide/Editor'; @@ -20,10 +21,12 @@ import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; +import { TimeoutConstants } from '../../TimeoutConstants'; const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree); const editor: Editor = e2eContainer.get(CLASSES.Editor); +const ide: Ide = e2eContainer.get(CLASSES.Ide); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const preferencesHandler: PreferencesHandler = e2eContainer.get(CLASSES.PreferencesHandler); @@ -45,10 +48,23 @@ suite('The "VscodeXmlPlugin" userstory', async () => { projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); test('Wait until created workspace is started', async () => { + WorkspaceHandlingTests.setWorkspaceName(workspaceName); CheReporter.registerRunningWorkspace(workspaceName); await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); + + test('Wait until created workspace is started', async () => { + await ide.waitIde(TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT); + await ide.waitNotificationAndClickOnButton('Do you trust the authors of', 'Yes, I trust', 60_000); + }); + }); + + suite('Check workspace readiness to work', async () => { + test('Wait until project is imported', async () => { + await projectTree.openProjectTreeContainer(); + await projectTree.waitProjectImported(projectName, 'app'); + }); }); suite('Check the "vscode-xml" plugin', async () => { @@ -101,7 +117,7 @@ suite('The "VscodeXmlPlugin" userstory', async () => { suite('Delete workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/tests/plugins/VscodeYamlPlugin.spec.ts b/tests/e2e/tests/plugins/VscodeYamlPlugin.spec.ts index 02c4ebafe3a..9cc30c6af1f 100644 --- a/tests/e2e/tests/plugins/VscodeYamlPlugin.spec.ts +++ b/tests/e2e/tests/plugins/VscodeYamlPlugin.spec.ts @@ -16,7 +16,6 @@ import { Editor } from '../../pageobjects/ide/Editor'; import { TestConstants } from '../../TestConstants'; import { Logger } from '../../utils/Logger'; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests'; -import CheReporter from '../../driver/CheReporter'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { PreferencesHandler } from '../../utils/PreferencesHandler'; import { ProjectAndFileTests } from '../../testsLibrary/ProjectAndFileTests'; @@ -36,19 +35,17 @@ const pathToFile: string = `${projectName}`; const yamlFileName: string = 'routes.yaml'; const yamlSchema = { 'yaml-schema.json': '*.yaml' }; -let workspaceName: string = 'yaml-plugin'; - suite('The "VscodeYamlPlugin" userstory', async () => { suite('Create workspace', async () => { test('Create workspace using factory', async () => { await browserTabsUtil.navigateTo(factoryUrl); }); - projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); - test('Wait until created workspace is started', async () => { - CheReporter.registerRunningWorkspace(workspaceName); + projectAndFileTests.waitWorkspaceReadiness(projectName, subRootFolder); + test('Set confirmExit preference to never', async () => { await preferencesHandler.setPreferenceUsingUI('application.confirmExit', 'never'); }); }); @@ -97,7 +94,7 @@ suite('The "VscodeYamlPlugin" userstory', async () => { suite('Delete workspace', async () => { test('Stop and remove workspace', async () => { if (TestConstants.TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true') { - await workspaceHandlingTests.stopAndRemoveWorkspace(workspaceName); + await workspaceHandlingTests.stopAndRemoveWorkspace(WorkspaceHandlingTests.getWorkspaceName()); return; } diff --git a/tests/e2e/testsLibrary/CodeExecutionTests.ts b/tests/e2e/testsLibrary/CodeExecutionTests.ts index 1f0823d8db0..62dd2250fbd 100644 --- a/tests/e2e/testsLibrary/CodeExecutionTests.ts +++ b/tests/e2e/testsLibrary/CodeExecutionTests.ts @@ -20,6 +20,8 @@ import { DialogWindow } from '../pageobjects/ide/DialogWindow'; import { DriverHelper } from '../utils/DriverHelper'; import { Logger } from '../utils/Logger'; import { QuickOpenContainer } from '../pageobjects/ide/QuickOpenContainer'; +import { WorkspaceHandlingTests } from './WorkspaceHandlingTests'; +import { BrowserTabsUtil } from '../utils/BrowserTabsUtil'; @injectable() export class CodeExecutionTests { @@ -32,7 +34,9 @@ export class CodeExecutionTests { @inject(CLASSES.Ide) private readonly ide: Ide, @inject(CLASSES.DialogWindow) private readonly dialogWindow: DialogWindow, @inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, - @inject(CLASSES.QuickOpenContainer) private readonly quickOpenContainer: QuickOpenContainer) {} + @inject(CLASSES.QuickOpenContainer) private readonly quickOpenContainer: QuickOpenContainer, + @inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil, + @inject(CLASSES.WorkspaceHandlingTests) private readonly workspaceHandlingTests: WorkspaceHandlingTests) {} public runTask(taskName: string, timeout: number) { test(`Run command '${taskName}'`, async () => { @@ -62,6 +66,7 @@ export class CodeExecutionTests { public runTaskWithDialogShellAndOpenLink(taskName: string, expectedDialogText: string, timeout: number) { test(`Run command '${taskName}' expecting dialog shell`, async () => { await this.runTaskUsingQuickOpenContainer(taskName); + this.workspaceHandlingTests.setWindowHandle(await this.browserTabsUtil.getCurrentWindowHandle()); await this.dialogWindow.waitDialogAndOpenLink(expectedDialogText, timeout); }); } @@ -103,6 +108,7 @@ export class CodeExecutionTests { test(`Run command '${taskName}' expecting notification`, async () => { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotification(notificationText, timeout); + this.workspaceHandlingTests.setWindowHandle(await this.browserTabsUtil.getCurrentWindowHandle()); await this.ide.clickOnNotificationButton(notificationText, buttonText); await this.driverHelper.wait(5_000); CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); @@ -116,6 +122,7 @@ export class CodeExecutionTests { test(`Run command '${taskName}' expecting notification`, async () => { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotification(notificationText, timeout); + this.workspaceHandlingTests.setWindowHandle(await this.browserTabsUtil.getCurrentWindowHandle()); await this.ide.clickOnNotificationButton(notificationText, 'Open In Preview'); await this.driverHelper.wait(5_000); CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); @@ -126,6 +133,7 @@ export class CodeExecutionTests { test(`Run command '${taskName}' expecting notification with unexposed port`, async () => { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotificationAndConfirm(notificationText, timeout); + this.workspaceHandlingTests.setWindowHandle(await this.browserTabsUtil.getCurrentWindowHandle()); await this.ide.waitNotificationAndOpenLink(portOpenText, timeout); await this.driverHelper.wait(5_000); CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); diff --git a/tests/e2e/testsLibrary/WorkspaceHandlingTests.ts b/tests/e2e/testsLibrary/WorkspaceHandlingTests.ts index 385fbaed570..adcd238185b 100644 --- a/tests/e2e/testsLibrary/WorkspaceHandlingTests.ts +++ b/tests/e2e/testsLibrary/WorkspaceHandlingTests.ts @@ -15,46 +15,109 @@ import { Dashboard } from '../pageobjects/dashboard/Dashboard'; import { CreateWorkspace } from '../pageobjects/dashboard/CreateWorkspace'; import { Workspaces } from '../pageobjects/dashboard/Workspaces'; import { BrowserTabsUtil } from '../utils/BrowserTabsUtil'; -import { Logger } from '..'; +import { Logger } from '../utils/Logger'; +import { ApiUrlResolver } from '../utils/workspace/ApiUrlResolver'; +import { TimeoutConstants } from '../TimeoutConstants'; +import { DriverHelper } from '../utils/DriverHelper'; +import { Ide } from '../pageobjects/ide/Ide'; +import { By, error } from 'selenium-webdriver'; @injectable() export class WorkspaceHandlingTests { + private static START_WORKSPACE_PAGE_NAME_LOCATOR: By = By.xpath(`//div[@class="ui-container"]/div[@class="pf-c-page"]//div[@class="pf-c-content"]/h1`); private static workspaceName: string = 'undefined'; + private static parentGUID: string; public static getWorkspaceName(): string { return WorkspaceHandlingTests.workspaceName; } + public static setWorkspaceName(workspaceName: string) { + WorkspaceHandlingTests.workspaceName = workspaceName; + } + + public setWindowHandle(guid: string) { + WorkspaceHandlingTests.parentGUID = guid; + } + + public getWindowHandle(): string { + return WorkspaceHandlingTests.parentGUID; + } + constructor( @inject(CLASSES.Dashboard) private readonly dashboard: Dashboard, @inject(CLASSES.CreateWorkspace) private readonly createWorkspace: CreateWorkspace, @inject(CLASSES.Workspaces) private readonly workspaces: Workspaces, - @inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil) {} + @inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil, + @inject(CLASSES.ApiUrlResolver) private readonly apiUrlResolver: ApiUrlResolver, + @inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, + @inject(CLASSES.Ide) private readonly ide: Ide) {} public createAndOpenWorkspace(stack: string) { - test(`Open 'New Workspace' page`, async () => { + test(`Create and open new workspace, stack:${stack}`, async () => { await this.dashboard.waitPage(); + Logger.debug(`Fetching user kubernetes namespace, storing auth token by getting workspaces API URL.`); + await this.apiUrlResolver.getWorkspacesApiUrl(); await this.dashboard.clickCreateWorkspaceButton(); await this.createWorkspace.waitPage(); - const parentGUID = await this.browserTabsUtil.getCurrentWindowHandle(); + WorkspaceHandlingTests.parentGUID = await this.browserTabsUtil.getCurrentWindowHandle(); await this.createWorkspace.clickOnSample(stack); - await this.browserTabsUtil.switchToWindow(parentGUID); - WorkspaceHandlingTests.workspaceName = await this.dashboard.getRecentWorkspaceName(10000); - Logger.debug(`Workspace Name is: ${WorkspaceHandlingTests.workspaceName}`); - await this.browserTabsUtil.waitAndSwitchToAnotherWindow(parentGUID, 10000); + await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TimeoutConstants.TS_IDE_LOAD_TIMEOUT); }); } public openExistingWorkspace(workspaceName: string) { - test('Start workspace', async () => { + test('Open and start existing workspace', async () => { await this.dashboard.waitPage(); + Logger.debug(`Fetching user kubernetes namespace, storing auth token by getting workspaces API URL.`); + await this.apiUrlResolver.getWorkspacesApiUrl(); await this.dashboard.clickWorkspacesButton(); await this.workspaces.waitPage(); await this.workspaces.clickOpenButton(workspaceName); }); } + public obtainWorkspaceNameFromStartingPage() { + test('Obtain workspace name from workspace loader page', async() => { + try { + await this.driverHelper.waitVisibility(WorkspaceHandlingTests.START_WORKSPACE_PAGE_NAME_LOCATOR, TimeoutConstants.TS_WAIT_LOADER_PRESENCE_TIMEOUT); + // it takes a while to update the element with the workspace name + await this.driverHelper.wait(TimeoutConstants.TS_IDE_LOAD_TIMEOUT); + let startingWorkspaceLineContent = await this.driverHelper.getDriver().findElement(WorkspaceHandlingTests.START_WORKSPACE_PAGE_NAME_LOCATOR).getAttribute('innerHTML'); + // cutting away leading text + WorkspaceHandlingTests.workspaceName = startingWorkspaceLineContent.substring('Starting workspace '.length).trim(); + Logger.info(`Obtained workspace name from workspace loader page: ${WorkspaceHandlingTests.workspaceName}`); + } catch (err) { + Logger.error(`Failed to obtain workspace name from workspace loader page: ${err}`); + throw err; + } + }); + } + + public switchBackToFirstOpenIdeTabFromLeftToRight() { + test('WorkspaceHandlingTests.switchBackToIdeTab', async () => { + let tabs = await this.driverHelper.getDriver().getAllWindowHandles(); + Logger.trace(`WorkspaceHandlingTests.switchBackToIdeTab Found ${tabs.length} window handles, iterating...`); + for (let i = 0; i < tabs.length; i++) { + await this.browserTabsUtil.switchToWindow(tabs[i]); + try { + await this.ide.waitIde(TimeoutConstants.TS_IDE_LOAD_TIMEOUT); + Logger.debug(`WorkspaceHandlingTests.switchBackToIdeTab located and switched to IDE tab`); + return; + } catch (err) { + if (err instanceof error.TimeoutError) { + Logger.warn(`WorkspaceHandlingTests.switchBackToIdeTab Locator timed out, trying with another window handle.`); + continue; + } + Logger.error(`WorkspaceHandlingTests.switchBackToIdeTab Received unexpected exception while trying to locate IDE tab:${err}`); + throw err; + } + } + Logger.error(`WorkspaceHandlingTests.switchBackToIdeTab Failed to locate IDE tab, out of window handles.`); + }); + } + public async stopWorkspace(workspaceName: string) { await this.dashboard.openDashboard(); await this.dashboard.stopWorkspaceByUI(workspaceName); diff --git a/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts b/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts index 96efb3d12bc..528a4636d02 100644 --- a/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts +++ b/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts @@ -100,7 +100,7 @@ export class CheApiRequestHandler { } async patch(relativeUrl: string, patchParams: object): Promise { - return await axios.patch(this.assembleUrl(relativeUrl), patchParams, await this.headerHandler.get()); + return await axios.patch(this.assembleUrl(relativeUrl), patchParams, await this.headerHandler.get()); } private assembleUrl(relativeUrl: string): string { diff --git a/tests/e2e/utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler.ts b/tests/e2e/utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler.ts index a192a46ddc0..746875f64fb 100644 --- a/tests/e2e/utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler.ts +++ b/tests/e2e/utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler.ts @@ -12,13 +12,28 @@ import { IAuthorizationHeaderHandler } from './IAuthorizationHeaderHandler'; import { inject, injectable } from 'inversify'; import { DriverHelper } from '../../DriverHelper'; import { CLASSES } from '../../../inversify.types'; +import { Logger } from '../../Logger'; @injectable() export class CheMultiuserAuthorizationHeaderHandler implements IAuthorizationHeaderHandler { + private authorizationToken: string = ''; + constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { } async get(): Promise { - let token = await this.driverHelper.getDriver().manage().getCookie('_oauth_proxy'); - return { headers: { 'cookie': `_oauth_proxy=${token.value}` } }; + try { + let token = await this.driverHelper.getDriver().manage().getCookie('_oauth_proxy'); + if (this.authorizationToken !== token.value) { + this.authorizationToken = token.value; + } + } catch (err) { + if (this.authorizationToken.length > 0) { + Logger.warn(`Could not obtain _oauth_proxy cookie from chromedriver, browser session may have been killed. Using stored value.`); + } else { + throw new Error(`Could not obtain _oauth_proxy cookie from chromedriver, browser session may have been killed. No stored token present!`); + } + } + + return { headers: { 'cookie': `_oauth_proxy=${this.authorizationToken}` } }; } } diff --git a/tests/e2e/utils/workspace/ApiUrlResolver.ts b/tests/e2e/utils/workspace/ApiUrlResolver.ts new file mode 100644 index 00000000000..7ce86bfc3b8 --- /dev/null +++ b/tests/e2e/utils/workspace/ApiUrlResolver.ts @@ -0,0 +1,50 @@ +/********************************************************************* + * Copyright (c) 2019 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +import { inject, injectable } from 'inversify'; +import { CLASSES } from '../../inversify.types'; +import { Logger } from '../Logger'; +import { CheApiRequestHandler } from '../requestHandlers/CheApiRequestHandler'; + +@injectable() +export class ApiUrlResolver { + private static readonly DASHBOARD_API_URL: string = 'dashboard/api/namespace'; + private static readonly KUBERNETES_API_URL: string = 'api/kubernetes/namespace'; + + private userNamespace: string = ''; + + constructor(@inject(CLASSES.CheApiRequestHandler) private readonly processRequestHandler: CheApiRequestHandler) {} + + public async getWorkspaceApiUrl(workspaceName: string): Promise { + return `${await this.getWorkspacesApiUrl()}/${workspaceName}`; + } + + public async getWorkspacesApiUrl(): Promise { + const namespace = await this.obtainUserNamespace(); + return `${ApiUrlResolver.DASHBOARD_API_URL}/${namespace}/devworkspaces`; + } + + public getKubernetesApiUrl(): string { + return ApiUrlResolver.KUBERNETES_API_URL; + } + + private async obtainUserNamespace() : Promise { + Logger.debug(`ApiUrlResolver.obtainUserNamespace ${this.userNamespace}`); + if (this.userNamespace.length === 0) { + Logger.trace(`ApiUrlResolver.obtainUserNamespace USER_NAMESPACE.length = 0, calling kubernetes API`); + const kubernetesResponse = await this.processRequestHandler.get(ApiUrlResolver.KUBERNETES_API_URL); + if (kubernetesResponse.status !== 200) { + throw new Error(`Cannot get user namespace from kubernetes API. Code: ${kubernetesResponse.status} Data: ${kubernetesResponse.data}`); + } + this.userNamespace = kubernetesResponse.data[0].name; + Logger.debug(`ApiUrlResolver.obtainUserNamespace kubeapi success: ${this.userNamespace}`); + } + return this.userNamespace; + } +} diff --git a/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts b/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts index ea4402b6473..2fffab4cd28 100644 --- a/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts +++ b/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts @@ -12,15 +12,87 @@ import { WorkspaceStatus } from './WorkspaceStatus'; import { che } from '@eclipse-che/api'; export interface ITestWorkspaceUtil { + waitWorkspaceStatus(namespace: string, workspaceName: string, expectedWorkspaceStatus: WorkspaceStatus) : void; + + stopWorkspaceByName(workspaceName: string) : void; + + /** + * Delete a worksapce without stopping phase (similar with force deleting) + */ + deleteWorkspaceByName(workspaceName: string) : void; + + /** + * Stop workspace before deleting with checking stopping phase + */ + stopAndDeleteWorkspaceByName(workspaceName: string) : void; + + /** + * Stop all run workspaces in the namespace + */ + stopAllRunningWorkspaces(namespace: string) : void; + + /** + * Stop all run workspaces, check statused and remove the workspaces + */ + stopAndDeleteAllRunningWorkspaces(namespace: string) : void; + + /** + * Stop all run workspaces without stopping and waiting for of 'Stopped' phase + * Similar with 'force' deleting + */ + deleteAllWorkspaces(namespace: string) : void; + + /*===================== + * DEPRECATED METHODS * + *====================*/ + + /** + * @deprecated Method deprecated. Works with CHE server only + */ cleanUpAllWorkspaces() : void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ cleanUpRunningWorkspace(workspaceName: string) : void; - waitWorkspaceStatus(namespace: string, workspaceName: string, expectedWorkspaceStatus: WorkspaceStatus) : void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ waitPluginAdding(namespace: string, workspaceName: string, pluginId: string) : void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ removeWorkspaceById(id: string) : void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ stopWorkspaceById(id: string) : void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ getIdOfRunningWorkspace(workspaceName: string): Promise; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ getIdOfRunningWorkspaces(): Promise>; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ createWsFromDevFile(customTemplate: che.workspace.devfile.Devfile): void; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ getBaseDevfile(): Promise; + + /** + * @deprecated Method deprecated. Works with CHE server only + */ startWorkspace(workspaceId: string): void; } diff --git a/tests/e2e/utils/workspace/TestWorkspaceUtil.ts b/tests/e2e/utils/workspace/TestWorkspaceUtil.ts index 84dde831a5d..aeac663114b 100644 --- a/tests/e2e/utils/workspace/TestWorkspaceUtil.ts +++ b/tests/e2e/utils/workspace/TestWorkspaceUtil.ts @@ -8,38 +8,38 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ +import 'reflect-metadata'; import { che } from '@eclipse-che/api'; import { TestConstants } from '../../TestConstants'; import { injectable, inject } from 'inversify'; import { DriverHelper } from '../DriverHelper'; -import 'reflect-metadata'; import { WorkspaceStatus } from './WorkspaceStatus'; -import { ITestWorkspaceUtil } from './ITestWorkspaceUtil'; import { error } from 'selenium-webdriver'; import { CheApiRequestHandler } from '../requestHandlers/CheApiRequestHandler'; import { CLASSES } from '../../inversify.types'; import { Logger } from '../Logger'; import axios from 'axios'; +import { ITestWorkspaceUtil } from './ITestWorkspaceUtil'; +import { ApiUrlResolver } from './ApiUrlResolver'; @injectable() export class TestWorkspaceUtil implements ITestWorkspaceUtil { - - static readonly WORKSPACE_API_URL: string = 'dashboard/api/namespace'; readonly attempts: number = TestConstants.TS_SELENIUM_WORKSPACE_STATUS_ATTEMPTS; readonly polling: number = TestConstants.TS_SELENIUM_WORKSPACE_STATUS_POLLING; + constructor( @inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, - @inject(CLASSES.CheApiRequestHandler) private readonly processRequestHandler: CheApiRequestHandler + @inject(CLASSES.CheApiRequestHandler) private readonly processRequestHandler: CheApiRequestHandler, + @inject(CLASSES.ApiUrlResolver) private readonly apiUrlResolver: ApiUrlResolver ) { } - public async waitWorkspaceStatus(namespace: string, workspaceName: string, expectedWorkspaceStatus: WorkspaceStatus) { + public async waitWorkspaceStatus(workspaceName: string, expectedWorkspaceStatus: WorkspaceStatus) { Logger.debug('TestWorkspaceUtil.waitWorkspaceStatus'); - const workspaceStatusApiUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${namespace}-che/devworkspaces/${workspaceName}`; let workspaceStatus: string = ''; let expectedStatus: boolean = false; for (let i = 0; i < this.attempts; i++) { - const response = await this.processRequestHandler.get(workspaceStatusApiUrl); + const response = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspaceApiUrl(workspaceName)); if (response.status !== 200) { throw new Error(`Can not get status of a workspace. Code: ${response.status} Data: ${response.data}`); @@ -61,10 +61,10 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { } } - public async stopWorkspaceByName(namespace: string, workspaceName: string) { + public async stopWorkspaceByName(workspaceName: string) { Logger.debug('TestWorkspaceUtil.stopWorkspaceByName'); - const stopWorkspaceApiUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${namespace}-che/devworkspaces/${workspaceName}`; + const stopWorkspaceApiUrl: string = await this.apiUrlResolver.getWorkspaceApiUrl(workspaceName); let stopWorkspaceResponse; try { @@ -78,14 +78,14 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { throw new Error(`Cannot stop workspace. Code: ${stopWorkspaceResponse.status} Data: ${stopWorkspaceResponse.data}`); } - await this.waitWorkspaceStatus(namespace, workspaceName, WorkspaceStatus.STOPPED); + await this.waitWorkspaceStatus(workspaceName, WorkspaceStatus.STOPPED); } // delete a worksapce without stopping phase (similar with force deleting) - public async deleteWorkspaceByName(namespace: string, workspaceName: string) { - Logger.debug('TestWorkspaceUtil.deleteWorkspaceByName'); + public async deleteWorkspaceByName(workspaceName: string) { + Logger.debug(`TestWorkspaceUtil.deleteWorkspaceByName ${workspaceName}` ); - const deleteWorkspaceApiUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${namespace}-che/devworkspaces/${workspaceName}`; + const deleteWorkspaceApiUrl: string = await this.apiUrlResolver.getWorkspaceApiUrl(workspaceName); let deleteWorkspaceResponse; let deleteWorkspaceStatus: boolean = false; try { @@ -95,16 +95,15 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { Logger.error(`The workspace :${workspaceName} not found`); throw error; } - Logger.error(`Stop workspace call failed. URL used: ${deleteWorkspaceStatus}`); + Logger.error(`Delete workspace call failed. URL used: ${deleteWorkspaceStatus}`); throw error; } if (deleteWorkspaceResponse.status !== 204) { - throw new Error(`Can not stop workspace. Code: ${deleteWorkspaceResponse.status} Data: ${deleteWorkspaceResponse.data}`); + throw new Error(`Can not delete workspace. Code: ${deleteWorkspaceResponse.status} Data: ${deleteWorkspaceResponse.data}`); } for (let i = 0; i < this.attempts; i++) { - try { deleteWorkspaceResponse = await this.processRequestHandler.get(deleteWorkspaceApiUrl); } catch (error) { @@ -122,11 +121,44 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { } // stop workspace before deleting with checking stopping phase - public async stopAndDeleteWorkspaceByName(namespace: string, workspaceName: string) { + public async stopAndDeleteWorkspaceByName(workspaceName: string) { Logger.debug('TestWorkspaceUtil.stopAndDeleteWorkspaceByName'); - await this.stopWorkspaceByName(namespace, workspaceName); - await this.deleteWorkspaceByName(namespace, workspaceName); + await this.stopWorkspaceByName(workspaceName); + await this.deleteWorkspaceByName(workspaceName); + } + + // stop all run workspaces in the namespace + public async stopAllRunningWorkspaces(namespace: string) { + Logger.debug('TestWorkspaceUtil.stopAllRunProjects'); + let response = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspacesApiUrl()); + for (let i = 0; i < response.data.items.length; i++) { + Logger.info('The project is being stopped: ' + response.data.items[i].metadata.name); + await this.stopWorkspaceByName(response.data.items[i].metadata.name); + } + } + + // stop all run workspaces, check statused and remove the workspaces + public async stopAndDeleteAllRunningWorkspaces(namespace: string) { + Logger.debug('TestWorkspaceUtil.stopAndDeleteAllRunProjects'); + let response = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspacesApiUrl()); + await this.stopAllRunningWorkspaces(namespace); + for (let i = 0; i < response.data.items.length; i++) { + Logger.info('The project is being deleted: ' + response.data.items[i].metadata.name); + await this.deleteWorkspaceByName(response.data.items[i].metadata.name); + } + } + + // stop all run workspaces without stopping and waiting for of 'Stopped' phase + // similar with 'force' deleting + public async deleteAllWorkspaces(namespace: string) { + Logger.debug('TestWorkspaceUtil.deleteAllRunProjects'); + let response = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspacesApiUrl()); + + for (let i = 0; i < response.data.items.length; i++) { + Logger.info('The project is being deleted .......: ' + response.data.items[i].metadata.name); + await this.deleteWorkspaceByName(response.data.items[i].metadata.name); + } } /** @@ -135,7 +167,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { public async waitPluginAdding(namespace: string, workspaceName: string, pluginName: string) { Logger.debug('TestWorkspaceUtil.waitPluginAdding'); - const workspaceStatusApiUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${namespace}:${workspaceName}`; + const workspaceStatusApiUrl: string = `${await this.apiUrlResolver.getWorkspacesApiUrl()}/${namespace}:${workspaceName}`; const attempts: number = TestConstants.TS_SELENIUM_PLUGIN_PRECENCE_ATTEMPTS; const polling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING; @@ -168,7 +200,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { public async getListOfWorkspaceId(): Promise { Logger.debug('TestWorkspaceUtil.getListOfWorkspaceId'); - const getAllWorkspacesResponse = await this.processRequestHandler.get(TestWorkspaceUtil.WORKSPACE_API_URL); + const getAllWorkspacesResponse = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspacesApiUrl()); interface IMyObj { id: string; @@ -192,7 +224,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { public async getIdOfRunningWorkspace(wsName: string): Promise { Logger.debug('TestWorkspaceUtil.getIdOfRunningWorkspace'); - const getWorkspacesByNameResponse = await this.processRequestHandler.get(`${TestWorkspaceUtil.WORKSPACE_API_URL}/:${wsName}`); + const getWorkspacesByNameResponse = await this.processRequestHandler.get(`${await this.apiUrlResolver.getWorkspacesApiUrl()}/:${wsName}`); return getWorkspacesByNameResponse.data.id; } @@ -204,7 +236,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { Logger.debug('TestWorkspaceUtil.getIdOfRunningWorkspaces'); try { - const getAllWorkspacesResponse = await this.processRequestHandler.get(TestWorkspaceUtil.WORKSPACE_API_URL); + const getAllWorkspacesResponse = await this.processRequestHandler.get(await this.apiUrlResolver.getWorkspacesApiUrl()); interface IMyObj { id: string; @@ -222,7 +254,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { return idOfRunningWorkspace; } catch (err) { - console.log(`Getting id of running workspaces failed. URL used: ${TestWorkspaceUtil.WORKSPACE_API_URL}`); + console.log(`Getting id of running workspaces failed. URL used: ${await this.apiUrlResolver.getWorkspacesApiUrl()}`); throw err; } } @@ -233,7 +265,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { public async removeWorkspaceById(id: string) { Logger.debug('TestWorkspaceUtil.removeWorkspaceById'); - const workspaceIdUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${id}`; + const workspaceIdUrl: string = `${await this.apiUrlResolver.getWorkspacesApiUrl()}/${id}`; try { const deleteWorkspaceResponse = await this.processRequestHandler.delete(workspaceIdUrl); if (deleteWorkspaceResponse.status !== 204) { @@ -251,7 +283,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { public async stopWorkspaceById(id: string) { Logger.debug('TestWorkspaceUtil.stopWorkspaceById'); - const stopWorkspaceApiUrl: string = `${TestWorkspaceUtil.WORKSPACE_API_URL}/${id}`; + const stopWorkspaceApiUrl: string = `${await this.apiUrlResolver.getWorkspacesApiUrl()}/${id}`; let stopWorkspaceResponse; try { @@ -306,16 +338,16 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { */ public async cleanUpRunningWorkspace(workspaceName: string) { if (workspaceName === undefined || workspaceName.length === 0) { - Logger.warn(`Could nod delete workspace because workspaceName is undefined or empty`); - return; + Logger.warn(`Could nod delete workspace because workspaceName is undefined or empty`); + return; } Logger.debug(`TestWorkspaceUtil.cleanUpRunningWorkspace ${workspaceName}`); const workspaceID: string = await this.getIdOfRunningWorkspace(workspaceName); if (workspaceID === undefined || workspaceID.length === 0) { - Logger.error(`Could nod delete workspace with name ${workspaceName} because workspaceID is undefined or empty`); - return; + Logger.error(`Could nod delete workspace with name ${workspaceName} because workspaceID is undefined or empty`); + return; } Logger.trace(`TestWorkspaceUtil.cleanUpRunningWorkspace Stopping workspace:${workspaceName} with ID:${workspaceID}`); @@ -331,7 +363,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { Logger.debug('TestWorkspaceUtil.createWsFromDevFile'); try { - await this.processRequestHandler.post(TestWorkspaceUtil.WORKSPACE_API_URL + '/devfile', customTemplate); + await this.processRequestHandler.post(await this.apiUrlResolver.getWorkspacesApiUrl() + '/devfile', customTemplate); } catch (error) { console.error(error); throw error; @@ -361,7 +393,7 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { Logger.debug('TestWorkspaceUtil.startWorkspace'); try { - await this.processRequestHandler.post(`${TestWorkspaceUtil.WORKSPACE_API_URL}/${workspaceId}/runtime`); + await this.processRequestHandler.post(`${await this.apiUrlResolver.getWorkspacesApiUrl()}/${workspaceId}/runtime`); } catch (error) { console.error(error); throw error; diff --git a/tests/e2e/utils/workspace/WorkspaceStatus.ts b/tests/e2e/utils/workspace/WorkspaceStatus.ts index d7e04ccfcb2..e83038b02d9 100644 --- a/tests/e2e/utils/workspace/WorkspaceStatus.ts +++ b/tests/e2e/utils/workspace/WorkspaceStatus.ts @@ -8,7 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ - export enum WorkspaceStatus { +export enum WorkspaceStatus { RUNNING = 'Running', STOPPED = 'Stopped', STARTING = 'Starting'