Skip to content

Commit

Permalink
add FactoryWithGitRepoOptions test (#23086)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkorikSergey authored Aug 14, 2024
1 parent 732d965 commit 245bb11
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/constants/TIMEOUT_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------

Expand Down
21 changes: 19 additions & 2 deletions tests/e2e/pageobjects/dashboard/CreateWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<void> {
async importFromGitUsingUI(
factoryUrl: string,
branchName?: string,
timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT
): Promise<void> {
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<void> {
Expand Down
77 changes: 77 additions & 0 deletions tests/e2e/specs/factory/FactoryWithGitRepoOptions.spec.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await loginTests.loginIntoChe();
});
test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl, expectedBranchName);
});
test('Obtain workspace name from workspace loader page', async function (): Promise<void> {
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
});
test('Register running workspace', function (): void {
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});
test('Wait workspace readiness', async function (): Promise<void> {
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
});
test('Check a project folder has been created', async function (): Promise<void> {
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<void> {
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<void> {
const branchName: string = await projectAndFileTests.getBranchName();

expect(branchName, 'Branch name error').equals(expectedBranchName);
});
test('Stop the workspace by UI', async function (): Promise<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await browserTabsUtil.closeAllTabsExceptCurrent();
});
test('Delete the workspace by UI', async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});
});
17 changes: 16 additions & 1 deletion tests/e2e/tests-library/ProjectAndFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -136,4 +138,17 @@ export class ProjectAndFileTests {

return projectTreeItem;
}

/**
* @returns {string} Branch name of cloned repository
*/

async getBranchName(): Promise<string> {
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();
}
}
4 changes: 2 additions & 2 deletions tests/e2e/tests-library/WorkspaceHandlingTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ export class WorkspaceHandlingTests {
await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
}

async createAndOpenWorkspaceFromGitRepository(factoryUrl: string): Promise<void> {
async createAndOpenWorkspaceFromGitRepository(factoryUrl: string, branchName?: string): Promise<void> {
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);
}

Expand Down

0 comments on commit 245bb11

Please sign in to comment.