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

Add user story for testing WTO under regular user #22763

Merged
merged 2 commits into from
Jan 14, 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
74 changes: 68 additions & 6 deletions tests/e2e/pageobjects/webterminal/WebTerminalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { By, Key } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';

export enum TimeUnits {
Seconds = 'Seconds',
Minutes = 'Minutes',
Hours = 'Hours'
}
@injectable()
export class WebTerminalPage {
private static readonly TIMEOUT_BUTTON: By = By.xpath('//button[(text()="Timeout")]');
Expand All @@ -24,8 +29,18 @@ export class WebTerminalPage {
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 TERMINAL_INACTIVITY_MESS: By = By.xpath('//div[contains(text(),"The terminal connection has closed")]');
private static readonly RESTART_BUTTON: By = By.xpath('//button[text()="Restart terminal"]');
private static readonly PROJECT_NAMESPACE_DROP_DAWN: By = By.css('button#form-ns-dropdown-namespace-field');
private static readonly PROJECT_SELECTION_FIELD: By = By.css('input[data-test-id="dropdown-text-filter"]');
private static readonly PROJECT_NAME_FIELD: By = By.css('input#form-input-newNamespace-field');
private static readonly TIMEOUT_INPUT: By = By.css(
'input[aria-describedby="form-resource-limit-advancedOptions-timeout-limit-field-helper"]'
);
private static readonly INCREMENT_TIMEOUT_BTN: By = By.css('button[data-test-id="Decrement"]');
private static readonly DECREMENT_TIMEOUT_BTN: By = By.css('button[data-test-id="Increment');
private static readonly TIME_UNIT_DROP_DAWN: By = By.css('div.request-size-input__unit button');

constructor(
@inject(CLASSES.DriverHelper)
private readonly driverHelper: DriverHelper
Expand All @@ -39,7 +54,7 @@ export class WebTerminalPage {
Logger.debug();
await this.driverHelper.waitPresence(WebTerminalPage.WEB_TERMINAL_PAGE, TIMEOUT_CONSTANTS.TS_WAIT_LOADER_ABSENCE_TIMEOUT);
}
async clickOnStartWebTerminalIcon(): Promise<void> {
async clickOnStartWebTerminalButton(): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WebTerminalPage.START_WT_COMMAND_LINE_TERMINAL_BUTTON);
}
Expand All @@ -53,7 +68,7 @@ export class WebTerminalPage {
async openWebTerminal(): Promise<void> {
Logger.debug();
await this.clickOnWebTerminalIcon();
await this.clickOnStartWebTerminalIcon();
await this.clickOnStartWebTerminalButton();
await this.waitTerminalIsStarted();
}
async waitDisabledProjectFieldAndGetProjectName(): Promise<string> {
Expand Down Expand Up @@ -112,8 +127,55 @@ export class WebTerminalPage {
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);
async waitTerminalInactivity(customTimeout?: number): Promise<void> {
await this.driverHelper.waitVisibility(
WebTerminalPage.TERMINAL_INACTIVITY_MESS,
TIMEOUT_CONSTANTS.TS_COMMON_PLUGIN_TEST_TIMEOUT || customTimeout
);

await this.driverHelper.waitVisibility(WebTerminalPage.RESTART_BUTTON);
}
async waitWebTerminalProjectNameField(): Promise<void> {
await this.driverHelper.waitPresence(WebTerminalPage.PROJECT_NAMESPACE_DROP_DAWN);
}
async typeProjectName(projectName: string): Promise<void> {
await this.waitWebTerminalProjectNameField();
await this.driverHelper.type(WebTerminalPage.PROJECT_NAME_FIELD, projectName, TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM);
}
async openProjectDropDawn(): Promise<void> {
await this.driverHelper.waitAndClick(WebTerminalPage.PROJECT_NAMESPACE_DROP_DAWN);
}
async typeProjectNameForSelecting(projectName: string): Promise<void> {
await this.driverHelper.type(WebTerminalPage.PROJECT_SELECTION_FIELD, projectName);
}

async selectProjectFromDropDawnList(projectName: string): Promise<void> {
await this.driverHelper.waitAndClick(By.xpath(`//span[@class="pf-c-menu__item-text" and text()="${projectName}"]`));
}

async findAndSelectProject(projectName: string): Promise<void> {
await this.openProjectDropDawn();
await this.typeProjectNameForSelecting(projectName);
await this.selectProjectFromDropDawnList(projectName);
}
async clickOnTimeoutButton(): Promise<void> {
await this.driverHelper.waitAndClick(WebTerminalPage.TIMEOUT_BUTTON);
}
async setTimeoutByEntering(timeValue: number): Promise<void> {
await this.driverHelper.type(WebTerminalPage.TIMEOUT_INPUT, timeValue.toString());
}
async clickOnPlusBtn(): Promise<void> {
await this.driverHelper.waitAndClick(WebTerminalPage.INCREMENT_TIMEOUT_BTN);
}

async clickOnMinutesBtn(): Promise<void> {
await this.driverHelper.waitAndClick(WebTerminalPage.DECREMENT_TIMEOUT_BTN);
}

async clickOnTimeUnitDropDown(): Promise<void> {
await this.driverHelper.waitAndClick(WebTerminalPage.TIME_UNIT_DROP_DAWN);
}
async selectTimeUnit(timeUnits: TimeUnits): Promise<void> {
await this.driverHelper.waitAndClick(By.xpath(`//button[@data-test-id='dropdown-menu' and text()='${timeUnits}']`));
}
}
13 changes: 7 additions & 6 deletions tests/e2e/specs/web-terminal/WebTerminalUnderAdmin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,31 @@ suite(`Login to Openshift console and start WebTerminal ${BASE_TEST_CONSTANTS.TE
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);

const defaultWTOProjectNameForAdmin: string = 'openshift-terminal';
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const webTerminalToolContainerName: string = 'web-terminal-tooling';
const fileForVerificationTerminalCommands: string = 'result.txt';

suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp('admin');
});

suiteTeardown(function (): void {
shellExecutor.executeArbitraryShellScript(`oc delete dw --all -n ${defaultWTOProjectNameForAdmin}`);
});
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');
expect(await webTerminal.waitDisabledProjectFieldAndGetProjectName()).equal(defaultWTOProjectNameForAdmin);
});
test('Check starting Web Terminal under admin', async function (): Promise<void> {
kubernetesCommandLineToolsExecutor.namespace = await webTerminal.getAdminProjectName();
await webTerminal.clickOnStartWebTerminalIcon();
await webTerminal.clickOnStartWebTerminalButton();
await webTerminal.waitTerminalIsStarted();
await webTerminal.typeAndEnterIntoWebTerminal(`oc whoami > ${fileForVerificationTerminalCommands}`);
const devWorkspaceYaml: string = shellExecutor.executeArbitraryShellScript(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/** *******************************************************************
* 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 { TimeUnits, WebTerminalPage } from '../../pageobjects/webterminal/WebTerminalPage';
import { expect } from 'chai';
import YAML from 'yaml';
import { afterEach } from 'mocha';
import { By } from 'selenium-webdriver';

suite(`Login to Openshift console and check WebTerminal ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const webTerminalToolContainerName: string = 'web-terminal-tooling';
const testProjectName: string = 'wto-under-regular-user-test';
const fileForVerificationTerminalCommands: string = 'result.txt';
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);

suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
});

suiteTeardown(function (): void {
kubernetesCommandLineToolsExecutor.deleteProject(testProjectName);
});

afterEach(function (): void {
try {
shellExecutor.executeArbitraryShellScript(`oc delete dw --all -n ${testProjectName}`);
} catch (e) {
console.log(`cannot delete the ${testProjectName} under regular user:`, e);
}
});

loginTests.loginIntoOcpConsole();

test('Open WebTerminal after first installation', async function (): Promise<void> {
await ocpMainPage.waitOpenMainPage();
await driverHelper.refreshPage();
await webTerminal.clickOnWebTerminalIcon();
});

test('Check WebTerminal with creating new Openshift Project', async function (): Promise<void> {
kubernetesCommandLineToolsExecutor.namespace = testProjectName;
await webTerminal.typeProjectName(testProjectName);
await webTerminal.clickOnStartWebTerminalButton();
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
);
const currentUserName: string = await driverHelper.waitAndGetText(By.css('span[data-test="username"]'));
expect(commandResult).contains(currentUserName);
});

test('Check running WebTerminal in the existed Project with custom timeout', async function (): Promise<void> {
await webTerminal.findAndSelectProject(testProjectName);
await webTerminal.clickOnTimeoutButton();
await webTerminal.clickOnTimeUnitDropDown();
await webTerminal.selectTimeUnit(TimeUnits.Seconds);
await webTerminal.setTimeoutByEntering(20);
await webTerminal.clickOnStartWebTerminalButton();
await webTerminal.waitTerminalIsStarted();
await webTerminal.waitTerminalInactivity();
});
});
Loading