Skip to content

Commit

Permalink
Added workaround for preview page not being displayed
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Dancs <tdancs@redhat.com>
  • Loading branch information
ScrewTSW committed Feb 20, 2020
1 parent 534dd3e commit c98fc20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
14 changes: 2 additions & 12 deletions tests/e2e/tests/devfiles/PythonDjango.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { NameGenerator } from '../../utils/NameGenerator';
import { error } from 'selenium-webdriver';
import 'reflect-metadata';
import * as codeExecutionHelper from '../../testsLibrary/CodeExecutionTests';
import * as workspaceHandler from '../../testsLibrary/WorksapceHandlingTests';
import * as projectManager from '../../testsLibrary/ProjectAndFileTests';
import { Logger } from '../../utils/Logger';

const workspaceName: string = NameGenerator.generate('wksp-test-', 5);
const workspaceStack: string = 'Python Django';
Expand All @@ -24,6 +22,7 @@ const taskInstallDependencies: string = 'install dependencies';
const taskMigrate: string = 'migrate';
const taskRunServer: string = 'run server';
const taskExpectedDialogText: string = 'A process is now listening on port 7000';
const taskCustomUrlSubpath: string = '/api/';

suite(`${workspaceStack} test`, async () => {

Expand All @@ -43,16 +42,7 @@ suite(`${workspaceStack} test`, async () => {
});

suite('Run django server', async () => {
//todo: fix try catch block. exception is not being caught for some reason
try {
codeExecutionHelper.runTaskWithDialogShellAndOpenLink(taskRunServer, taskExpectedDialogText, 30_000);
} catch (err) {
Logger.debug(`Caught an exception while trying to run the Django example application server.`);
if (err instanceof error.TimeoutError) {
console.log(` ⚠️ Python Django failed to load deployed example application server.`);
console.log(` ⚠️ This issue is being reported here: `);
} else { throw err; }
}
codeExecutionHelper.runTaskWithDialogShellDjangoWorkaround(taskRunServer, taskExpectedDialogText, taskCustomUrlSubpath, 30_000);
});

suite('Stop and remove workspace', async() => {
Expand Down
23 changes: 22 additions & 1 deletion tests/e2e/testsLibrary/CodeExecutionTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { CLASSES, Terminal, TopMenu, Ide, DialogWindow } from '..';
import { CLASSES, Terminal, TopMenu, Ide, DialogWindow, DriverHelper } from '..';
import { e2eContainer } from '../inversify.config';
import Axios from 'axios';
import https from 'https';

const terminal: Terminal = e2eContainer.get(CLASSES.Terminal);
const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu);
const ide: Ide = e2eContainer.get(CLASSES.Ide);
const dialogWindow: DialogWindow = e2eContainer.get(CLASSES.DialogWindow);
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);

export function runTask(taskName: string, timeout: number) {
test(`Run command '${taskName}'`, async () => {
Expand All @@ -30,6 +33,24 @@ export function runTaskWithDialogShellAndOpenLink(taskName: string, expectedDial
});
}

export function runTaskWithDialogShellDjangoWorkaround(taskName: string, expectedDialogText: string, urlSubPath: string, timeout: number) {
test(`Run command '${taskName}' expecting dialog shell`, async () => {
await topMenu.runTask(taskName);
await dialogWindow.waitDialog(timeout, expectedDialogText);
const dialogRedirectUrl: string = await dialogWindow.getApplicationUrlFromDialog(expectedDialogText);
const augmentedPreviewUrl: string = dialogRedirectUrl + urlSubPath;
await dialogWindow.closeDialog();
await dialogWindow.waitDialogDissappearance();
await driverHelper.getDriver().wait(async () => {
try {
const agent = new https.Agent({ rejectUnauthorized: false });
const res = await Axios.get(augmentedPreviewUrl, { httpsAgent: agent });
if (res.status === 200) { return true; }
} catch (error) { await driverHelper.wait(1_000); }
}, timeout);
});
}

export function runTaskWithDialogShellAndClose(taskName: string, expectedDialogText: string, timeout: number) {
test(`Run command '${taskName}' expecting dialog shell`, async () => {
await topMenu.runTask(taskName);
Expand Down

0 comments on commit c98fc20

Please sign in to comment.