From 8898b7d23aca0845eafc7541dfac7860f79a5f2a Mon Sep 17 00:00:00 2001 From: Maksym Musiienko Date: Thu, 14 Nov 2024 20:43:17 +0200 Subject: [PATCH] Stabilize devconsole integration tests (#23247) * stabilize devconsole integration tests --- .../e2e/pageobjects/openshift/OcpMainPage.ts | 14 +++++++-- .../DevConsoleIntegration.spec.ts | 31 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tests/e2e/pageobjects/openshift/OcpMainPage.ts b/tests/e2e/pageobjects/openshift/OcpMainPage.ts index 41dcd8f4ac2..e37f82581be 100644 --- a/tests/e2e/pageobjects/openshift/OcpMainPage.ts +++ b/tests/e2e/pageobjects/openshift/OcpMainPage.ts @@ -16,6 +16,7 @@ import { Logger } from '../../utils/Logger'; import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; import { OcpImportFromGitPage } from './OcpImportFromGitPage'; import { e2eContainer } from '../../configs/inversify.config'; +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; @injectable() export class OcpMainPage { @@ -29,7 +30,9 @@ export class OcpMainPage { constructor( @inject(CLASSES.DriverHelper) - private readonly driverHelper: DriverHelper + private readonly driverHelper: DriverHelper, + @inject(CLASSES.BrowserTabsUtil) + private readonly browserTabsUtil: BrowserTabsUtil ) {} async waitOpenMainPage(): Promise { @@ -82,6 +85,14 @@ export class OcpMainPage { await this.driverHelper.waitAndClick(this.getProjectDropdownItemLocator(projectName)); } + async clickOnAppLauncherAndDevSpaceItem(): Promise { + Logger.debug('click on app launcher menu'); + const parentGUID: string = await this.browserTabsUtil.getCurrentWindowHandle(); + await this.driverHelper.waitAndClick(By.css('nav[data-test-id="application-launcher"]')); + await this.driverHelper.waitAndClick(By.xpath('//span[contains(.,"Red Hat OpenShift Dev Spaces")]')); + await this.browserTabsUtil.waitAndSwitchToAnotherWindow(parentGUID, TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT); + } + private getRoleLocator(role: string): By { return By.xpath(`//a//*[text()="${role}"]`); } @@ -95,7 +106,6 @@ export class OcpMainPage { await this.driverHelper.waitAndClick(this.getRoleLocator(role)); } - private async tryToSkipWebTour(): Promise { Logger.debug(); diff --git a/tests/e2e/specs/devconsole-intergration/DevConsoleIntegration.spec.ts b/tests/e2e/specs/devconsole-intergration/DevConsoleIntegration.spec.ts index 856c1797d90..fb8daf1ea0a 100644 --- a/tests/e2e/specs/devconsole-intergration/DevConsoleIntegration.spec.ts +++ b/tests/e2e/specs/devconsole-intergration/DevConsoleIntegration.spec.ts @@ -25,15 +25,19 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; +import { Logger } from '../../utils/Logger'; +import { ShellExecutor } from '../../utils/ShellExecutor'; +import { ShellString } from 'shelljs'; suite(`DevConsole Integration ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { let ocpImportPage: OcpImportFromGitPage; let ocpApplicationPage: OcpApplicationPage; - + let parentGUID: string = ''; const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); + const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); const ocpMainPage: OcpMainPage = e2eContainer.get(CLASSES.OcpMainPage); const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( @@ -47,12 +51,18 @@ suite(`DevConsole Integration ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function suiteSetup('Create new empty project using ocp', function (): void { kubernetesCommandLineToolsExecutor.loginToOcp(); + // delete the test project on a cluster if it has not been deleted properly in the previous run + const expectedProject: ShellString = shellExecutor.executeCommand(`oc get project ${projectName}`); + if (expectedProject.stderr.length === 0) { + kubernetesCommandLineToolsExecutor.deleteProject(projectName); + } kubernetesCommandLineToolsExecutor.createProject(projectName); }); loginTests.loginIntoOcpConsole(); test('Select test project and Developer role on DevConsole', async function (): Promise { + parentGUID = await browserTabsUtil.getCurrentWindowHandle(); await ocpMainPage.selectDeveloperRole(); await ocpMainPage.selectProject(projectName); }); @@ -106,16 +116,27 @@ suite(`DevConsole Integration ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function ).not.undefined; }); - suiteTeardown('Open dashboard and close all other tabs', async function (): Promise { - await dashboard.openDashboard(); + test('Check redirection to DevSpaces from App launcher', async function (): Promise { + await browserTabsUtil.switchToWindow(parentGUID); await browserTabsUtil.closeAllTabsExceptCurrent(); + await ocpMainPage.clickOnAppLauncherAndDevSpaceItem(); + await loginTests.loginIntoChe(); + await dashboard.waitPage(); }); suiteTeardown('Delete project using ocp', function (): void { kubernetesCommandLineToolsExecutor.workspaceName = WorkspaceHandlingTests.getWorkspaceName() !== '' ? WorkspaceHandlingTests.getWorkspaceName() : 'spring-music'; - kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); - kubernetesCommandLineToolsExecutor.deleteProject(projectName); + try { + kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); + } catch (err) { + Logger.error(`Error while deleting workspace: ${err}`); + } + try { + kubernetesCommandLineToolsExecutor.deleteProject(projectName); + } catch (err) { + Logger.error(`Cannot delete the project: ${err}`); + } }); suiteTeardown('Unregister running workspace', function (): void {