Skip to content

Commit

Permalink
Stabilize devconsole integration tests (#23247)
Browse files Browse the repository at this point in the history
* stabilize devconsole integration tests
  • Loading branch information
musienko-maxim authored Nov 14, 2024
1 parent 4787042 commit 8898b7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
14 changes: 12 additions & 2 deletions tests/e2e/pageobjects/openshift/OcpMainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<void> {
Expand Down Expand Up @@ -82,6 +85,14 @@ export class OcpMainPage {
await this.driverHelper.waitAndClick(this.getProjectDropdownItemLocator(projectName));
}

async clickOnAppLauncherAndDevSpaceItem(): Promise<void> {
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}"]`);
}
Expand All @@ -95,7 +106,6 @@ export class OcpMainPage {

await this.driverHelper.waitAndClick(this.getRoleLocator(role));
}

private async tryToSkipWebTour(): Promise<void> {
Logger.debug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<void> {
parentGUID = await browserTabsUtil.getCurrentWindowHandle();
await ocpMainPage.selectDeveloperRole();
await ocpMainPage.selectProject(projectName);
});
Expand Down Expand Up @@ -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<void> {
await dashboard.openDashboard();
test('Check redirection to DevSpaces from App launcher', async function (): Promise<void> {
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 {
Expand Down

0 comments on commit 8898b7d

Please sign in to comment.