Skip to content

Commit

Permalink
Add url resolver and new methods (#21488) (#21508)
Browse files Browse the repository at this point in the history
* Add url resolver and new methods (#21488)

* add removing list of workspaces and URL resolver

* Fixing ApiUrlResolver, inversify.types, TestWorkspaceUtil and CheReporter

Apply suggestions, reomove ITestWorkspaceUtil

change types for binding in inversify config

WIP: Fixing ApiUrlResolver, inversify.types, TestWorkspaceUtil and CheReporter

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

* Cherry-picking Fixing upstream test logic to be compatible with Devfile V2 (part 1) (#21355)

* Added extra methods, fixed broken logic

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

* Fixed and refactored workspace name obtaining logic

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

* Fixing missing workspace registration logic

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

Co-authored-by: Maksym Musiienko <mmusiien@redhat.com>
  • Loading branch information
ScrewTSW and musienko-maxim authored Jun 29, 2022
1 parent d6432ff commit 6e4c4fe
Show file tree
Hide file tree
Showing 52 changed files with 528 additions and 339 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/driver/CheReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}`);
Expand Down Expand Up @@ -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);
}

});
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<IDriver>(TYPES.Driver).to(ChromeDriver).inSingletonScope();
e2eContainer.bind<ITestWorkspaceUtil>(TYPES.WorkspaceUtil).to(TestWorkspaceUtil);
e2eContainer.bind<IOcpLoginPage>(TYPES.OcpLogin).to(OcpUserLoginPage);

e2eContainer.bind<IAuthorizationHeaderHandler>(TYPES.IAuthorizationHeaderHandler).to(CheMultiuserAuthorizationHeaderHandler);
e2eContainer.bind<ITokenHandler>(TYPES.ITokenHandler).to(CheMultiuserTokenHandler);

Expand Down Expand Up @@ -132,5 +133,6 @@ e2eContainer.bind<GitOauthAppsSettings>(CLASSES.GitOauthAppsSettings).to(GitOaut
e2eContainer.bind<AnimationChecker>(CLASSES.AnimationChecker).to(AnimationChecker);
e2eContainer.bind<Sanitizer>(CLASSES.Sanitizer).to(Sanitizer);
e2eContainer.bind<NavigationBar>(CLASSES.NavigationBar).to(NavigationBar);
e2eContainer.bind<ApiUrlResolver>(CLASSES.ApiUrlResolver).to(ApiUrlResolver);

export { e2eContainer };
3 changes: 2 additions & 1 deletion tests/e2e/inversify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const CLASSES = {
GitOauthAppsSettings: 'GitOauthAppsSettings',
AnimationChecker: 'AnimationChecker',
Sanitizer: 'Sanitizer',
NavigationBar: 'NavigationBar'
NavigationBar: 'NavigationBar',
ApiUrlResolver: 'ApiUrlResolver'
};

export { TYPES, CLASSES };
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
21 changes: 13 additions & 8 deletions tests/e2e/pageobjects/ide/ProjectTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/tests/devfiles/CSlashCPlusPlus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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());
});
});

Expand Down
11 changes: 4 additions & 7 deletions tests/e2e/tests/devfiles/DevfileSmoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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());
});
});
});
9 changes: 3 additions & 6 deletions tests/e2e/tests/devfiles/DotNetCore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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());
});
});
});
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/tests/devfiles/Go.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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());
});
});

Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/tests/devfiles/JavaMaven.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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());
});
});
});
9 changes: 3 additions & 6 deletions tests/e2e/tests/devfiles/JavaSpringBoot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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());
});
});
});
9 changes: 3 additions & 6 deletions tests/e2e/tests/devfiles/JavaVertx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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());
});
});

Expand Down
Loading

0 comments on commit 6e4c4fe

Please sign in to comment.