Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"DevConsole integration" regression test case automation #22181

Merged
merged 4 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/e2e/constants/TestConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const TestConstants: any = {
*/
TS_SELENIUM_BASE_URL: getBaseUrl(),

TS_SELENIUM_OPENSHIFT_CONSOLE_URL(): string {
return process.env.TS_SELENIUM_OPENSHIFT_CONSOLE_URL || TestConstants.TS_SELENIUM_BASE_URL.replace('devspaces', 'console-openshift-console');
},

/**
* Run browser in "Headless" (hidden) mode, "false" by default.
*/
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/pageobjects/openshift/OcpImportFromGitPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import { CLASSES } from '../../configs/inversify.types';
import { By } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { OcpApplicationPage } from './OcpApplicationPage';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { e2eContainer } from '../../configs/inversify.config';

@injectable()
export class OcpImportFromGitPage {

constructor(
@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper,
@inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil) {
@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) {
}

async enterGitRepoUrl(gitRepoUrl: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/pageobjects/openshift/OcpLoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ export class OcpLoginPage {
async waitDisappearanceOpenShiftLoginWelcomePage(): Promise<void> {
Logger.debug('OcpLoginPage.waitDisappearanceOpenShiftLoginWelcomePage');

await this.driverHelper.waitDisappearance(By.xpath(OcpLoginPage.LOGIN_PAGE_OPENSHIFT_XPATH), TestConstants.TS_SELENIUM_DEFAULT_ATTEMPTS * 10);
await this.driverHelper.waitDisappearance(By.xpath(OcpLoginPage.LOGIN_PAGE_OPENSHIFT_XPATH));
}
}
1 change: 0 additions & 1 deletion tests/e2e/pageobjects/openshift/OcpMainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { By } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TimeoutConstants } from '../../constants/TimeoutConstants';
import { OcpImportFromGitPage } from './OcpImportFromGitPage';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { e2eContainer } from '../../configs/inversify.config';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ suite(`Check if recommended extensions installed for ${samples}`, async function
test(`Let extensions complete installation`, async function (): Promise<void> {
Logger.info(`Time for extensions installation TimeoutConstants.TS_COMMON_PLUGIN_TEST_TIMEOUT=${TimeoutConstants.TS_COMMON_PLUGIN_TEST_TIMEOUT}`);
await driverHelper.wait(TimeoutConstants.TS_COMMON_PLUGIN_TEST_TIMEOUT);
browserTabsUtil.refreshPage();
await browserTabsUtil.refreshPage();
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { Logger } from '../../utils/Logger';
import { expect } from 'chai';
import { TestConstants } from '../../constants/TestConstants';
import { OcpMainPage } from '../../pageobjects/openshift/OcpMainPage';
Expand Down Expand Up @@ -86,7 +85,7 @@ suite(`DevConsole Integration`, async function (): Promise<void> {

test('Check if project and files imported', async function (): Promise<void> {
const applicationSourceProjectName: string = GitUtil.getProjectNameFromGitUrl(gitImportRepo);
const projectSection: ViewSection = await new SideBarView().getContent().getSection(applicationSourceProjectName as unknown as string);
const projectSection: ViewSection = await new SideBarView().getContent().getSection(applicationSourceProjectName);
const isFileImported: ViewItem | undefined = await projectSection.findItem(TestConstants.TS_SELENIUM_PROJECT_ROOT_FILE_NAME);
expect(isFileImported).not.eqls(undefined);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/factory/Factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite(`Create a workspace via launching a factory from the ${TestConstants.TS_SE

test('Check if a project folder has been created', async function (): Promise<void> {
Logger.debug(`new SideBarView().getContent().getSection: get ${testRepoProjectName}`);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName as unknown as string);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName);
});

test('Check if the project files were imported', async function (): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/factory/NoSetupRepoFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ suite(`Create a workspace via launching a factory from the ${TestConstants.TS_SE

test('Check if a project folder has been created', async function (): Promise<void> {
Logger.debug(`new SideBarView().getContent().getSection: get ${testRepoProjectName}`);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName as unknown as string);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName);
});

test('Accept the project as a trusted one', async function (): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/factory/RefusedOAuthFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ suite(`Create a workspace via launching a factory from the ${TestConstants.TS_SE

test('Check if a project folder has been created', async function (): Promise<void> {
Logger.debug(`new SideBarView().getContent().getSection: get ${testRepoProjectName}`);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName as unknown as string);
projectSection = await new SideBarView().getContent().getSection(testRepoProjectName);
});

test('Accept the project as a trusted one', async function (): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/tests-library/LoginTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class LoginTests {

public loginIntoOcpConsole(): void {
test('Login into ocp console', async () => {
await this.browserTabsUtil.navigateTo(TestConstants.TS_SELENIUM_OPENSHIFT_CONSOLE_URL());
const openshiftConsoleUrl: string = TestConstants.TS_SELENIUM_BASE_URL.replace('devspaces', 'console-openshift-console');
await this.browserTabsUtil.navigateTo(openshiftConsoleUrl);
await this.ocpLoginPage.login();
await this.browserTabsUtil.maximize();
});
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/utils/DriverHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,17 @@ export class DriverHelper {
await element.click();
return;
} catch (err) {
if (err instanceof error.StaleElementReferenceError || (err instanceof error.ElementClickInterceptedError && i !== attempts - 1)) {
function isElementClickInterceptedOnLastAttempt(err: Error, i: number): boolean {
return err instanceof error.ElementClickInterceptedError && i === attempts - 1;
}

if (err instanceof error.StaleElementReferenceError || err instanceof error.ElementClickInterceptedError) {
Logger.debug(`DriverHelper.waitAndClick - ${elementLocator} - ${err}`);
await this.wait(polling);
continue;
}

if (err instanceof error.ElementClickInterceptedError && i === attempts - 1) {
if (isElementClickInterceptedOnLastAttempt(err, i)) {
Logger.debug(`DriverHelper.waitAndClick - Element is not clickable, try to perform pointer click`);
await this.getAction()
.move({
Expand Down
10 changes: 8 additions & 2 deletions tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.OC) {
Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: Login to the "OC" client.`);
const url: string = this.getServerUrl();
const isUserLoggedIn: ShellString = this.execWithLog('oc whoami && oc whoami --show-server=true');
if (isUserLoggedIn.stdout.includes(TestConstants.TS_SELENIUM_OCP_USERNAME) && isUserLoggedIn.stdout.includes(url)) {
if (this.isUserLoggedIn()) {
Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: User already logged`);
} else {
Logger.debug(`${this.getLoggingName(this.loginToOcp.name)}: Login ${url}, ${TestConstants.TS_SELENIUM_OCP_USERNAME}`);
Expand Down Expand Up @@ -59,6 +58,7 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
Logger.debug(`${this.getLoggingName(this.deleteDevWorkspace.name)}: Delete '${this.workspaceName}' workspace`);
this.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`);
this.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} delete dw ${this.workspaceName} -n ${this.namespace} || true`);
this.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} delete dwt ${TestConstants.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`);
}

applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
Expand Down Expand Up @@ -115,6 +115,12 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
this.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete project ${projectName} -n ${this.namespace} && sleep 5s`);
}

private isUserLoggedIn(): boolean {
const whoamiCommandOutput: ShellString = this.execWithLog('oc whoami && oc whoami --show-server=true');
dmytro-ndp marked this conversation as resolved.
Show resolved Hide resolved

return whoamiCommandOutput.stdout.includes(TestConstants.TS_SELENIUM_OCP_USERNAME) && whoamiCommandOutput.stdout.includes(this.getServerUrl());
}

private getLoggingName(methodName: string): string {
return `${this.constructor.name}.${methodName} - ${(this.KUBERNETES_COMMAND_LINE_TOOL)}`;
}
Expand Down