Skip to content

Commit

Permalink
Merge pull request #6504 from gouyang/open_console_in_new_window
Browse files Browse the repository at this point in the history
Bug 1875274: Add test for open vnc in new window
  • Loading branch information
openshift-merge-robot committed Sep 8, 2020
2 parents 34f5a8b + 000b60e commit ab32634
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
@@ -1,7 +1,8 @@
import { browser, ExpectedConditions as until, Key } from 'protractor';
import { execSync } from 'child_process';
import { appHost, testName } from '@console/internal-integration-tests/protractor.conf';
import { testName } from '@console/internal-integration-tests/protractor.conf';
import {
click,
createResource,
deleteResource,
selectDropdownOption,
Expand All @@ -17,6 +18,7 @@ import {
serialConsole,
sendCommandToConsole,
vncConsole,
openInNewWindow,
} from '../views/consolesView';
import {
PAGE_LOAD_TIMEOUT_SECS,
Expand All @@ -30,11 +32,13 @@ import { getVMManifest } from './mocks/mocks';

describe('KubeVirt VM console - VNC/Serial', () => {
const vmResource = getVMManifest(ProvisionSource.URL, testName, 'cirros-vm');
const vm = new VirtualMachine(vmResource.metadata);
const testVM = new VirtualMachine(vmResource.metadata);
const cirrosUsername = 'cirros';
const cirrosPassword = 'gocubsgo';
const serialTestFile = 'serialTestFile';
const serialTestFile1 = 'serialTestFile1';
const vncTestFile = 'vncTestFile';
const vncTestFile1 = 'vncTestFile1';
const expectLoginScriptPath = `${KUBEVIRT_SCRIPTS_PATH}/expect-login.sh`;
const expectFileExistsScriptPath = `${KUBEVIRT_SCRIPTS_PATH}/expect-file-exists.sh`;

Expand All @@ -45,23 +49,30 @@ describe('KubeVirt VM console - VNC/Serial', () => {
await sendCommandToConsole(consoleCanvas, cirrosPassword);
};

const extractResult = (output: string) =>
output.split('\n').find((line) => line === 'SUCCESS' || line === 'FAILURE');
const checkTouchedFile = async (vm: VirtualMachine, consoleType: string, file: string) => {
await logIntoConsole(consoleType);
await sendCommandToConsole(consoleType, `touch ${file}`);
await sendCommandToConsole(consoleType, 'exit');

const output = execSync(
`expect ${expectFileExistsScriptPath} ${vm.name} ${vm.namespace} ${file}`,
)
.toString()
.replace(/[\r]+/gm, '');

const result = output.split('\n').find((line) => line === 'SUCCESS' || line === 'FAILURE');
expect(result).toEqual('SUCCESS');
};

beforeAll(async () => {
createResource(vmResource);
await vm.detailViewAction(VM_ACTION.Start);
await testVM.detailViewAction(VM_ACTION.Start);
// wait for the VM to boot up
execSync(`expect ${expectLoginScriptPath} ${vm.name} ${vm.namespace}`);
await vm.navigateToConsole();
execSync(`expect ${expectLoginScriptPath} ${testVM.name} ${testVM.namespace}`);
await testVM.navigateToConsole();
}, VM_BOOTUP_TIMEOUT_SECS);

afterAll(async () => {
await browser.get(appHost);
await browser
.switchTo()
.alert()
.accept();
deleteResource(vmResource);
});

Expand All @@ -77,16 +88,8 @@ describe('KubeVirt VM console - VNC/Serial', () => {
await browser.wait(until.elementToBeClickable(serialDisconnectButton), PAGE_LOAD_TIMEOUT_SECS);

await browser.wait(until.presenceOf(serialConsole), PAGE_LOAD_TIMEOUT_SECS);
await logIntoConsole(serialConsole);
await sendCommandToConsole(serialConsole, `touch ${serialTestFile}`);
await sendCommandToConsole(serialConsole, 'exit');
const out = execSync(
`expect ${expectFileExistsScriptPath} ${vm.name} ${vm.namespace} ${serialTestFile}`,
)
.toString()
.replace(/[\r]+/gm, '');

expect(extractResult(out)).toEqual('SUCCESS');
await checkTouchedFile(testVM, serialConsole, serialTestFile);
});

it('ID(CNV-872) VNC Console connects', async () => {
Expand All @@ -96,15 +99,39 @@ describe('KubeVirt VM console - VNC/Serial', () => {
await browser.wait(until.invisibilityOf(vncConnectingBar));
await browser.wait(until.presenceOf(vncSendKeyButton), PAGE_LOAD_TIMEOUT_SECS);

await logIntoConsole(vncConsole);
await sendCommandToConsole(vncConsole, `touch ${vncTestFile}`);
await checkTouchedFile(testVM, vncConsole, vncTestFile);
});

const out = execSync(
`expect ${expectFileExistsScriptPath} ${vm.name} ${vm.namespace} ${vncTestFile}`,
)
.toString()
.replace(/[\r]+/gm, '');
it('ID(CNV-4660) Open VNC Console in new window', async () => {
await click(openInNewWindow);

const consoleWinHandles = await browser.getAllWindowHandles();
const parentHandle = consoleWinHandles[0];
const popUpHandle = consoleWinHandles[1];

await browser.switchTo().window(popUpHandle);
const getPopUpHandle = browser.getWindowHandle();
expect(getPopUpHandle).toEqual(popUpHandle);

// verify it's connecting to vnc console in the new window.
await browser.wait(until.invisibilityOf(vncConnectingBar));
await browser.wait(until.presenceOf(vncSendKeyButton), PAGE_LOAD_TIMEOUT_SECS);
await checkTouchedFile(testVM, vncConsole, vncTestFile1);

// verify it's connecting to serial console in the new window.
await selectDropdownOption(consoleTypeSelectorId, 'Serial Console');
await browser.wait(waitForStringNotInElement(serialConsoleWrapper, 'Loading'));
await browser.wait(until.presenceOf(serialReconnectButton), PAGE_LOAD_TIMEOUT_SECS);
await browser.wait(until.presenceOf(serialDisconnectButton), PAGE_LOAD_TIMEOUT_SECS);
await browser.wait(until.elementToBeClickable(serialDisconnectButton), PAGE_LOAD_TIMEOUT_SECS);
await browser.wait(until.presenceOf(serialConsole), PAGE_LOAD_TIMEOUT_SECS);

await checkTouchedFile(testVM, serialConsole, serialTestFile1);

await browser.close();

expect(extractResult(out)).toEqual('SUCCESS');
await browser.switchTo().window(parentHandle);
const getParentHandle = browser.getWindowHandle();
expect(getParentHandle).toEqual(parentHandle);
});
});
Expand Up @@ -2,6 +2,7 @@ import { $, $$, element, by, browser, ExpectedConditions as until, Key } from 'p
import { PAGE_LOAD_TIMEOUT_SECS } from '../tests/utils/constants/common';

export const consoleTypeSelectorId = '#console-type-selector';
export const openInNewWindow = element(by.buttonText('Open Console in new Window'));
export const consoleTypeSelector = $(consoleTypeSelectorId);
export const rdpServiceNotConfiguredElem = $('.kubevirt-vm-consoles__rdp'); // this class is used just for this informative elemenet
export const networkSelectorId = '#network-dropdown';
Expand Down

0 comments on commit ab32634

Please sign in to comment.