diff --git a/tests/e2e/tests/devfiles/PythonDjango.spec.ts b/tests/e2e/tests/devfiles/PythonDjango.spec.ts index fe22eb89475..874d83a960b 100644 --- a/tests/e2e/tests/devfiles/PythonDjango.spec.ts +++ b/tests/e2e/tests/devfiles/PythonDjango.spec.ts @@ -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'; @@ -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 () => { @@ -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() => { diff --git a/tests/e2e/testsLibrary/CodeExecutionTests.ts b/tests/e2e/testsLibrary/CodeExecutionTests.ts index 11063651a83..3cd1c8c8db8 100644 --- a/tests/e2e/testsLibrary/CodeExecutionTests.ts +++ b/tests/e2e/testsLibrary/CodeExecutionTests.ts @@ -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 () => { @@ -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);