Skip to content

Commit

Permalink
Improve WebTerminalTest e2e test to check more test steps
Browse files Browse the repository at this point in the history
  • Loading branch information
SkorikSergey authored Nov 8, 2023
1 parent 220e13e commit c527b61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/e2e/pageobjects/openshift/OcpMainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class OcpMainPage {

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

async typeToWebTerminal(text: string): Promise<void> {
Expand Down
29 changes: 29 additions & 0 deletions tests/e2e/specs/web-terminal/WebTerminalTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,44 @@ 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 { expect } from 'chai';

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 kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor);

suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp('admin');
shellExecutor.executeCommand('oc project openshift-operators');
});

loginTests.loginIntoOcpConsole();

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

test('Check username is correct', async function (): Promise<void> {
const userUid = shellExecutor.executeCommand('oc get user $(oc whoami) -o jsonpath={.metadata.uid}').replace(/\n/g, '');

// label selector for Web Terminal workspaces owned by the currently-logged in user
const labelSelector = 'console.openshift.io/terminal=true,controller.devfile.io/creator=' + userUid;
// namespace of this users web terminal
const namespace = shellExecutor.executeCommand(`oc get dw -A -l ${labelSelector} -o jsonpath='{.items[0].metadata.namespace}'`);
// devWorkspace ID for this users web terminal
const termDwId = shellExecutor.executeCommand(`oc get dw -A -l ${labelSelector} -o jsonpath='{.items[0].status.devworkspaceId}'`);
// use oc exec to run oc whoami inside this user's terminal
const user = shellExecutor
.executeCommand(`oc exec -n ${namespace} deploy/${termDwId} -c web-terminal-tooling -- oc whoami`)
.replace(/\n/g, '');
// above should output current user's username:
expect(user).to.equal(shellExecutor.executeCommand('oc whoami').replace(/\n/g, ''));
});
});

0 comments on commit c527b61

Please sign in to comment.