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

Rewrite test userstory for WTO under admin #22748

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion tests/e2e/configs/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { Main as Generator } from '@eclipse-che/che-devworkspace-generator/lib/m
import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../utils/ShellExecutor';
import { UserPreferences } from '../pageobjects/dashboard/UserPreferences';
import { WebTerminalPage } from "../pageobjects/webterminal/WebTerminalPage";

const e2eContainer: Container = new Container({ defaultScope: 'Transient', skipBaseClassChecks: true });

Expand Down Expand Up @@ -85,8 +86,8 @@ e2eContainer.bind<DevfilesRegistryHelper>(CLASSES.DevfilesRegistryHelper).to(Dev
e2eContainer.bind<KubernetesCommandLineToolsExecutor>(CLASSES.KubernetesCommandLineToolsExecutor).to(KubernetesCommandLineToolsExecutor);
e2eContainer.bind<ShellExecutor>(CLASSES.ShellExecutor).to(ShellExecutor);
e2eContainer.bind<ContainerTerminal>(CLASSES.ContainerTerminal).to(ContainerTerminal);
e2eContainer.bind<WebTerminalPage>(CLASSES.WebTerminalPage).to(WebTerminalPage);
e2eContainer.bind<UserPreferences>(CLASSES.UserPreferences).to(UserPreferences);

e2eContainer.bind<Generator>(EXTERNAL_CLASSES.Generator).to(Generator);
e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader);

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/configs/inversify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const CLASSES: any = {
KubernetesCommandLineToolsExecutor: 'KubernetesCommandLineToolsExecutor',
ShellExecutor: 'ShellExecutor',
ContainerTerminal: 'ContainerTerminal',
UserPreferences: 'UserPreferences'
UserPreferences: 'UserPreferences',
WebTerminalPage: 'WebTerminalPage'
};

const EXTERNAL_CLASSES: any = {
Expand Down
16 changes: 10 additions & 6 deletions tests/e2e/constants/REPORTER_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MOCHA_CONSTANTS } from './MOCHA_CONSTANTS';

export const REPORTER_CONSTANTS: {
DELETE_SCREENCAST_IF_TEST_PASS: boolean;
RP_ENDPOINT(): string;
RP_ENDPOINT(): string | undefined;
RP_IS_LOCAL_SERVER: boolean;
REPORTERS_ENABLED(): string;
RP_API_KEY: string;
Expand Down Expand Up @@ -124,14 +124,18 @@ export const REPORTER_CONSTANTS: {
/**
* url with endpoints where ReportPortal is
*/
RP_ENDPOINT: (): string => {
return process.env.RP_ENDPOINT || REPORTER_CONSTANTS.RP_IS_LOCAL_SERVER
? 'http://localhost:8080/api/v1'
: 'https://reportportal-crw.apps.ocp-c1.prod.psi.redhat.com/api/v1';
RP_ENDPOINT: (): string | undefined => {
if (process.env.RP_ENDPOINTRP_IS_LOCAL_SERVER) {
return 'http://localhost:8080/api/v1';
}
if (process.env.RP_ENDPOINT !== '') {
return process.env.RP_ENDPOINT;
}
return 'https://reportportal-crw.apps.ocp-c1.prod.psi.redhat.com/api/v1';
},

/**
* use personal project to save launch, if false launch will be send to devspaces or che project, true by default
* use personal project to save launch, if false launch will be sent to devspaces or che project, true by default
*/
RP_USE_PERSONAL: process.env.RP_USE_PERSONAL !== 'false',

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * from './utils/workspace/TestWorkspaceUtil';
export * from './utils/workspace/WorkspaceStatus';
export * from './pageobjects/dashboard/CreateWorkspace';
export * from './pageobjects/dashboard/Dashboard';
export * from './pageobjects/dashboard/UserPreferences';
export * from './pageobjects/dashboard/workspace-details/WorkspaceDetails';
export * from './pageobjects/dashboard/Workspaces';
export * from './pageobjects/git-providers/OauthPage';
Expand All @@ -40,6 +41,7 @@ export * from './pageobjects/login/openshift/RegularUserOcpCheLoginPage';
export * from './pageobjects/openshift/OcpApplicationPage';
export * from './pageobjects/openshift/OcpImportFromGitPage';
export * from './pageobjects/openshift/OcpMainPage';
export * from './pageobjects/webterminal/WebTerminalPage';
export * from './tests-library/LoginTests';
export * from './tests-library/ProjectAndFileTests';
export * from './tests-library/WorkspaceHandlingTests';
Expand Down
19 changes: 0 additions & 19 deletions tests/e2e/pageobjects/openshift/OcpMainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export class OcpMainPage {
private static readonly SELECT_PROJECT_DROPDOWN: By = By.xpath('//div[@class="co-namespace-dropdown"]//button');
private static readonly PROJECT_FILTER_INPUT: By = By.xpath('//*[@data-test="dropdown-text-filter"]');
private static readonly SKIP_TOUR_BUTTON: By = By.xpath('//*[text()="Skip tour"]');
private static readonly WEB_TERMINAL_BUTTON: By = By.xpath('//button[@data-quickstart-id="qs-masthead-cloudshell"]');
private static readonly WEB_TERMINAL_PAGE: By = By.xpath('//*[@class="xterm-helper-textarea"]');
private static readonly START_WT_COMMAND_LINE_TERMINAL_BUTTON: By = By.xpath('//*[@data-test-id="submit-button"]');

constructor(
@inject(CLASSES.DriverHelper)
Expand Down Expand Up @@ -85,22 +82,6 @@ export class OcpMainPage {
await this.driverHelper.waitAndClick(this.getProjectDropdownItemLocator(projectName));
}

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

await this.waitOpenMainPage();
await this.driverHelper.waitAndClick(OcpMainPage.WEB_TERMINAL_BUTTON);
await this.driverHelper.waitAndClick(OcpMainPage.START_WT_COMMAND_LINE_TERMINAL_BUTTON);
await this.driverHelper.waitPresence(OcpMainPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_WAIT_LOADER_ABSENCE_TIMEOUT);
}

async typeToWebTerminal(text: string): Promise<void> {
Logger.debug();

await this.driverHelper.waitPresence(OcpMainPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
await this.driverHelper.typeToInvisible(OcpMainPage.WEB_TERMINAL_PAGE, text);
}

private getRoleLocator(role: string): By {
return By.xpath(`//a//*[text()="${role}"]`);
}
Expand Down
119 changes: 119 additions & 0 deletions tests/e2e/pageobjects/webterminal/WebTerminalPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/** *******************************************************************
* copyright (c) 2019-2023 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 'reflect-metadata';
import { inject, injectable } from 'inversify';
import { DriverHelper } from '../../utils/DriverHelper';
import { CLASSES } from '../../configs/inversify.types';
import { By, Key } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';

@injectable()
export class WebTerminalPage {
private static readonly TIMEOUT_BUTTON: By = By.xpath('//button[(text()="Timeout")]');
private static readonly IMAGE_BUTTON: By = By.xpath('//button[(text()="Image")]');
private static readonly WEB_TERMINAL_BUTTON: By = By.xpath('//button[@data-quickstart-id="qs-masthead-cloudshell"]');
private static readonly WEB_TERMINAL_PAGE: By = By.xpath('//*[@class="xterm-helper-textarea"]');
private static readonly START_WT_COMMAND_LINE_TERMINAL_BUTTON: By = By.css('button[data-test-id="submit-button"]');
private static readonly WEB_TERMINAL_PROJECT_SELECTION_DROPDOWN: By = By.css('input#form-input-namespace-field');
private static readonly WEB_TERMINAL_PROJECT_CANCEL_BUTTON: By = By.css('button[data-test-id="reset-button"]');
private static readonly TERMINAL_INACTIVITY_MESS: By = By.xpath('//div[text()="The terminal connection has closed."]');
private static readonly RESTART_BUTTON: By = By.xpath('//button[text()="Restart terminal"]');
constructor(
@inject(CLASSES.DriverHelper)
private readonly driverHelper: DriverHelper
) {}

async clickOnWebTerminalIcon(): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WebTerminalPage.WEB_TERMINAL_BUTTON, TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL);
}
async waitTerminalIsStarted(): Promise<void> {
Logger.debug();
await this.driverHelper.waitPresence(WebTerminalPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_WAIT_LOADER_ABSENCE_TIMEOUT);
}
async clickOnStartWebTerminalIcon(): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WebTerminalPage.START_WT_COMMAND_LINE_TERMINAL_BUTTON);
}
async getAdminProjectName(): Promise<string> {
Logger.debug();
return await this.driverHelper.waitAndGetValue(
By.css('input#form-input-namespace-field'),
TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL
);
}
async openWebTerminal(): Promise<void> {
Logger.debug();
await this.clickOnWebTerminalIcon();
await this.clickOnStartWebTerminalIcon();
await this.waitTerminalIsStarted();
}
async waitDisabledProjectFieldAndGetProjectName(): Promise<string> {
Logger.debug();
return await this.driverHelper.waitAndGetElementAttribute(WebTerminalPage.WEB_TERMINAL_PROJECT_SELECTION_DROPDOWN, 'value');
}
async typeIntoWebTerminal(text: string): Promise<void> {
Logger.debug();
await this.driverHelper.waitPresence(WebTerminalPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
await this.driverHelper.typeToInvisible(WebTerminalPage.WEB_TERMINAL_PAGE, text);
}

async typeAndEnterIntoWebTerminal(text: string): Promise<void> {
Logger.debug();
await this.driverHelper.waitPresence(WebTerminalPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
await this.driverHelper.typeToInvisible(WebTerminalPage.WEB_TERMINAL_PAGE, text + Key.ENTER);
}
async clickOnProjectListDropDown(): Promise<void> {
Logger.debug();
{
await this.driverHelper.waitPresence(
WebTerminalPage.WEB_TERMINAL_PROJECT_SELECTION_DROPDOWN,
TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT
);
}
}
async waitTimeoutButton(): Promise<void> {
Logger.debug();
{
await this.driverHelper.waitPresence(WebTerminalPage.TIMEOUT_BUTTON);
}
}
async waitImageButton(): Promise<void> {
Logger.debug();
{
await this.driverHelper.waitPresence(WebTerminalPage.IMAGE_BUTTON);
}
}
async waitStartButton(): Promise<void> {
Logger.debug();
{
await this.driverHelper.waitPresence(WebTerminalPage.START_WT_COMMAND_LINE_TERMINAL_BUTTON);
}
}

async waitCancelButton(): Promise<void> {
Logger.debug();
{
await this.driverHelper.waitPresence(WebTerminalPage.WEB_TERMINAL_PROJECT_CANCEL_BUTTON);
}
}
async waitTerminalWidget(): Promise<void> {
Logger.debug();
await this.waitStartButton();
await this.waitCancelButton();
await this.waitTimeoutButton();
await this.waitImageButton();
}
async waitTerminalInactivity(): Promise<void> {
await this.driverHelper.waitPresence(WebTerminalPage.TERMINAL_INACTIVITY_MESS, TIMEOUT_CONSTANTS.TS_COMMON_PLUGIN_TEST_TIMEOUT);
await this.driverHelper.waitPresence(WebTerminalPage.RESTART_BUTTON);
}
}
4 changes: 3 additions & 1 deletion tests/e2e/specs/web-terminal/WebTerminalTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../../utils/ShellExecutor';
import { expect } from 'chai';
import { WebTerminalPage } from '../../pageobjects/webterminal/WebTerminalPage';

suite(`Login to Openshift console and start WebTerminal ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const webTerminal: WebTerminalPage = e2eContainer.get(CLASSES.WebTerminalPage);
const ocpMainPage: OcpMainPage = e2eContainer.get(CLASSES.OcpMainPage);
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
Expand All @@ -33,7 +35,7 @@ suite(`Login to Openshift console and start WebTerminal ${BASE_TEST_CONSTANTS.TE

test('Open Web Terminal', async function (): Promise<void> {
await ocpMainPage.waitOpenMainPage();
await ocpMainPage.openWebTerminal();
await webTerminal.openWebTerminal();
});

test('Check username is correct', function (): void {
Expand Down
92 changes: 92 additions & 0 deletions tests/e2e/specs/web-terminal/WebTerminalUnderAdmin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/** *******************************************************************
* 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 { CLASSES } from '../../configs/inversify.types';
import { e2eContainer } from '../../configs/inversify.config';
import { LoginTests } from '../../tests-library/LoginTests';
import { OcpMainPage } from '../../pageobjects/openshift/OcpMainPage';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../../utils/ShellExecutor';
import { DriverHelper } from '../../utils/DriverHelper';
import { WebTerminalPage } from '../../pageobjects/webterminal/WebTerminalPage';
import { expect } from 'chai';
import YAML from 'yaml';

suite(`Login to Openshift console and start WebTerminal ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const ocpMainPage: OcpMainPage = e2eContainer.get(CLASSES.OcpMainPage);
const webTerminal: WebTerminalPage = e2eContainer.get(CLASSES.WebTerminalPage);
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor);
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);

const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const webTerminalToolContainerName: string = 'web-terminal-tooling';
const fileForVerificationTerminalCommands: string = 'result.txt';
suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp('admin');
});

loginTests.loginIntoOcpConsole();
test('Open Web Terminal after first installation', async function (): Promise<void> {
await ocpMainPage.waitOpenMainPage();
await driverHelper.refreshPage();
await webTerminal.clickOnWebTerminalIcon();
});
test('Verify inactivity dropdown menu for admin user', async function (): Promise<void> {
await webTerminal.clickOnProjectListDropDown();
});
test('Verify first started WTO widget and disabled state Project field under admin user', async function (): Promise<void> {
await webTerminal.waitTerminalWidget();
expect(await webTerminal.waitDisabledProjectFieldAndGetProjectName()).equal('openshift-terminal');
});
test('Check starting Web Terminal under admin', async function (): Promise<void> {
kubernetesCommandLineToolsExecutor.namespace = await webTerminal.getAdminProjectName();
await webTerminal.clickOnStartWebTerminalIcon();
await webTerminal.waitTerminalIsStarted();
await webTerminal.typeAndEnterIntoWebTerminal(`oc whoami > ${fileForVerificationTerminalCommands}`);
const devWorkspaceYaml: string = shellExecutor.executeArbitraryShellScript(
`oc get dw -n ${kubernetesCommandLineToolsExecutor.namespace} -o yaml`
);
kubernetesCommandLineToolsExecutor.workspaceName = YAML.parse(devWorkspaceYaml).items[0].metadata.name;
kubernetesCommandLineToolsExecutor.getPodAndContainerNames();
const commandResult: string = kubernetesCommandLineToolsExecutor.execInContainerCommand(
`cat /home/user/${fileForVerificationTerminalCommands}`,
webTerminalToolContainerName
);
expect(commandResult).contains('admin');
});
test('Verify help command under admin user', async function (): Promise<void> {
const helpCommandExpectedResult: string =
'oc \\d+\\.\\d+\\.\\d+ OpenShift CLI\n' +
'kubectl \\d+\\.\\d+\\.\\d+ Kubernetes CLI\n' +
'kustomize \\d+\\.\\d+\\.\\d+ Kustomize CLI \\(built-in to kubectl\\)\n' +
'helm \\d+\\.\\d+\\.\\d+ Helm CLI\n' +
'kn \\d+\\.\\d+\\.\\d+ KNative CLI\n' +
'tkn \\d+\\.\\d+\\.\\d+ Tekton CLI\n' +
'subctl \\d+\\.\\d+\\.\\d+ Submariner CLI\n' +
'odo \\d+\\.\\d+\\.\\d+ Red Hat OpenShift Developer CLI\n' +
'virtctl \\d+\\.\\d+\\.\\d+ KubeVirt CLI\n' +
'jq \\d+\\.\\d+ jq';

await webTerminal.typeAndEnterIntoWebTerminal(`help > ${fileForVerificationTerminalCommands}`);
const commandResult: string = kubernetesCommandLineToolsExecutor.execInContainerCommand(
`cat /home/user/${fileForVerificationTerminalCommands}`,
webTerminalToolContainerName
);
expect(commandResult).to.match(new RegExp(helpCommandExpectedResult));
});

test('Verify help command under admin user', async function (): Promise<void> {
await webTerminal.typeAndEnterIntoWebTerminal('wtoctl set timeout 30s');
await webTerminal.waitTerminalInactivity();
});
});
Loading