diff --git a/tests/e2e/constants/TIMEOUT_CONSTANTS.ts b/tests/e2e/constants/TIMEOUT_CONSTANTS.ts index 3c7d42552cc..93eb6f9b321 100644 --- a/tests/e2e/constants/TIMEOUT_CONSTANTS.ts +++ b/tests/e2e/constants/TIMEOUT_CONSTANTS.ts @@ -97,7 +97,7 @@ export const TIMEOUT_CONSTANTS: { /** * timeout for interactions with editor tab - wait, click, select, "8 000" by default. */ - TS_EDITOR_TAB_INTERACTION_TIMEOUT: Number(process.env.TS_OPEN_PROJECT_TREE_TIMEOUT) || 8_000, + TS_EDITOR_TAB_INTERACTION_TIMEOUT: Number(process.env.TS_OPEN_PROJECT_TREE_TIMEOUT) || 20_000, // -------------------------------------------- IDE -------------------------------------------- diff --git a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts index 110e18ad70b..4a509556f50 100644 --- a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts +++ b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts @@ -19,6 +19,10 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; @injectable() export class CreateWorkspace { private static readonly FACTORY_URL: By = By.xpath('//input[@id="git-repo-url"]'); + private static readonly GIT_REPO_OPTIONS: By = By.xpath('//span[text()="Git Repo Options"]'); + private static readonly GIT_BRANCH_NAME: By = By.xpath('//input[@aria-label="Git Branch"]'); + private static readonly PATH_TO_DEVFILE: By = By.xpath('//input[@aria-label="Path to Devfile"]'); + private static readonly CREATE_AND_OPEN_BUTTON: By = By.xpath('//button[@id="create-and-open-button"]'); constructor( @inject(CLASSES.DriverHelper) @@ -62,11 +66,24 @@ export class CreateWorkspace { await this.driverHelper.waitAndClick(sampleLocator, timeout); } - async importFromGitUsingUI(factoryUrl: string, timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise { + async importFromGitUsingUI( + factoryUrl: string, + branchName?: string, + timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT + ): Promise { Logger.debug(`factoryUrl: "${factoryUrl}"`); await this.driverHelper.waitVisibility(CreateWorkspace.FACTORY_URL, timeout); - await this.driverHelper.type(CreateWorkspace.FACTORY_URL, Key.chord(factoryUrl, Key.ENTER), timeout); + await this.driverHelper.type(CreateWorkspace.FACTORY_URL, Key.chord(factoryUrl), timeout); + + if (branchName) { + await this.driverHelper.waitAndClick(CreateWorkspace.GIT_REPO_OPTIONS, timeout); + + await this.driverHelper.waitVisibility(CreateWorkspace.GIT_BRANCH_NAME, timeout); + await this.driverHelper.type(CreateWorkspace.GIT_BRANCH_NAME, Key.chord(branchName, Key.ENTER), timeout); + } + + await this.driverHelper.waitAndClick(CreateWorkspace.CREATE_AND_OPEN_BUTTON, timeout); } async clickOnEditorsDropdownListButton(sampleName: string, timeout: number): Promise { diff --git a/tests/e2e/specs/factory/FactoryWithGitRepoOptions.spec.ts b/tests/e2e/specs/factory/FactoryWithGitRepoOptions.spec.ts new file mode 100644 index 00000000000..b9de237d12a --- /dev/null +++ b/tests/e2e/specs/factory/FactoryWithGitRepoOptions.spec.ts @@ -0,0 +1,77 @@ +/** ******************************************************************* + * copyright (c) 2024 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 { ViewSection } from 'monaco-page-objects'; +import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; +import { CLASSES } from '../../configs/inversify.types'; +import { e2eContainer } from '../../configs/inversify.config'; +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; +import { registerRunningWorkspace } from '../MochaHooks'; +import { LoginTests } from '../../tests-library/LoginTests'; +import { StringUtil } from '../../utils/StringUtil'; +import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { expect } from 'chai'; +import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; + +suite(`The FactoryWithGitRepoOptions userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { + const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); + const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); + const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); + const factoryUrl: string = + FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || 'https://github.com/che-incubator/quarkus-api-example.git'; + const expectedBranchName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_BRANCH || 'main'; + let projectSection: ViewSection; + suite(`Create workspace from factory:${factoryUrl}`, function (): void { + suiteSetup('Login', async function (): Promise { + await loginTests.loginIntoChe(); + }); + test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise { + await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl, expectedBranchName); + }); + test('Obtain workspace name from workspace loader page', async function (): Promise { + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + }); + test('Register running workspace', function (): void { + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + }); + test('Wait workspace readiness', async function (): Promise { + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); + }); + test('Check a project folder has been created', async function (): Promise { + const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || StringUtil.getProjectNameFromGitUrl(factoryUrl); + projectSection = await projectAndFileTests.getProjectViewSession(); + expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not + .undefined; + }); + test('Check the project files was imported', async function (): Promise { + expect( + await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME), + 'Project files were not imported' + ).not.undefined; + await projectAndFileTests.performTrustAuthorDialog(); + }); + test('Check expected branch name', async function (): Promise { + const branchName: string = await projectAndFileTests.getBranchName(); + + expect(branchName, 'Branch name error').equals(expectedBranchName); + }); + test('Stop the workspace by UI', async function (): Promise { + await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + await browserTabsUtil.closeAllTabsExceptCurrent(); + }); + test('Delete the workspace by UI', async function (): Promise { + await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + }); + suiteTeardown('Unregister running workspace', function (): void { + registerRunningWorkspace(''); + }); + }); +}); diff --git a/tests/e2e/tests-library/ProjectAndFileTests.ts b/tests/e2e/tests-library/ProjectAndFileTests.ts index 8368da5b800..c7a312a09af 100644 --- a/tests/e2e/tests-library/ProjectAndFileTests.ts +++ b/tests/e2e/tests-library/ProjectAndFileTests.ts @@ -15,10 +15,12 @@ import { CLASSES } from '../configs/inversify.types'; import { Logger } from '../utils/Logger'; import { TIMEOUT_CONSTANTS } from '../constants/TIMEOUT_CONSTANTS'; import { CheCodeLocatorLoader } from '../pageobjects/ide/CheCodeLocatorLoader'; -import { SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects'; +import { By, SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects'; @injectable() export class ProjectAndFileTests { + private static BRANCH_NAME_XPATH: By = By.xpath('//a[contains(@aria-label,"Checkout Branch/Tag...")]'); + constructor( @inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, @@ -136,4 +138,17 @@ export class ProjectAndFileTests { return projectTreeItem; } + + /** + * @returns {string} Branch name of cloned repository + */ + + async getBranchName(): Promise { + Logger.debug(); + + await this.driverHelper.waitVisibility(ProjectAndFileTests.BRANCH_NAME_XPATH, TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT); + const output: string = await this.driverHelper.waitAndGetText(ProjectAndFileTests.BRANCH_NAME_XPATH); + + return output.trimStart(); + } } diff --git a/tests/e2e/tests-library/WorkspaceHandlingTests.ts b/tests/e2e/tests-library/WorkspaceHandlingTests.ts index 6dfebb021df..e92702b725e 100644 --- a/tests/e2e/tests-library/WorkspaceHandlingTests.ts +++ b/tests/e2e/tests-library/WorkspaceHandlingTests.ts @@ -58,14 +58,14 @@ export class WorkspaceHandlingTests { await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); } - async createAndOpenWorkspaceFromGitRepository(factoryUrl: string): Promise { + async createAndOpenWorkspaceFromGitRepository(factoryUrl: string, branchName?: string): Promise { 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(); WorkspaceHandlingTests.parentGUID = await this.browserTabsUtil.getCurrentWindowHandle(); - await this.createWorkspace.importFromGitUsingUI(factoryUrl); + await this.createWorkspace.importFromGitUsingUI(factoryUrl, branchName); await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); }