From 437b87bda1bf031c8de77a67072a56da6733abe8 Mon Sep 17 00:00:00 2001 From: Tibor Dancs Date: Tue, 4 Aug 2020 14:28:17 +0200 Subject: [PATCH] Adding basic PHP Simple deftile test Signed-off-by: Tibor Dancs --- tests/e2e/pageobjects/ide/ProjectTree.ts | 28 +++++++ tests/e2e/tests/devfiles/PHPSimple.spec.ts | 78 +++++++++++++++++++ tests/e2e/testsLibrary/ProjectAndFileTests.ts | 11 +++ .../testsLibrary/WorksapceHandlingTests.ts | 5 ++ 4 files changed, 122 insertions(+) create mode 100644 tests/e2e/tests/devfiles/PHPSimple.spec.ts diff --git a/tests/e2e/pageobjects/ide/ProjectTree.ts b/tests/e2e/pageobjects/ide/ProjectTree.ts index 6265c396cf..552ba41004 100644 --- a/tests/e2e/pageobjects/ide/ProjectTree.ts +++ b/tests/e2e/pageobjects/ide/ProjectTree.ts @@ -299,6 +299,34 @@ export class ProjectTree { throw new error.TimeoutError('Exceeded the maximum number of checking attempts, project has not been imported'); } + async waitProjectImportedNoSubfolder(projectName: string, + attempts: number = TestConstants.TS_SELENIUM_DEFAULT_ATTEMPTS, + visibilityItemPolling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING * 5, + triesPolling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING * 30) { + + Logger.debug(`ProjectTree.waitProjectImportedNoSubfolder "${projectName}"`); + + const rootItemLocator: By = By.css(this.getTreeItemCssLocator(`${projectName}`)); + + for (let i = 0; i < attempts; i++) { + const isProjectFolderVisible = await this.driverHelper.waitVisibilityBoolean(rootItemLocator, 1, visibilityItemPolling); + + if (!isProjectFolderVisible) { + Logger.trace(`ProjectTree.waitProjectImportedNoSubfolder project not located, reloading page.`); + await this.driverHelper.reloadPage(); + await this.driverHelper.wait(triesPolling); + await this.ide.waitAndSwitchToIdeFrame(); + await this.ide.waitIde(); + await this.openProjectTreeContainer(); + continue; + } + + return; + } + + throw new error.TimeoutError('Exceeded the maximum number of checking attempts, project has not been imported'); + } + private async getWorkspacePathEntry(): Promise { const nodeAttribute: string = 'data-node-id'; const splitDelimeter = ':'; diff --git a/tests/e2e/tests/devfiles/PHPSimple.spec.ts b/tests/e2e/tests/devfiles/PHPSimple.spec.ts new file mode 100644 index 0000000000..b8ac8bc850 --- /dev/null +++ b/tests/e2e/tests/devfiles/PHPSimple.spec.ts @@ -0,0 +1,78 @@ +/********************************************************************* + * Copyright (c) 2020 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 'reflect-metadata'; +import * as projectAndFileTests from '../../testsLibrary/ProjectAndFileTests'; +import * as workspaceHandling from '../../testsLibrary/WorksapceHandlingTests'; +import * as commonLsTests from '../../testsLibrary/LsTests'; +import * as codeExecutionTests from '../../testsLibrary/CodeExecutionTests'; +import { e2eContainer } from '../../inversify.config'; +import { WorkspaceNameHandler, Editor, CLASSES } from '../..'; + +const editor: Editor = e2eContainer.get(CLASSES.Editor); + +const workspaceSampleName: string = 'php-web-simple'; +const fileFolderPath: string = `${workspaceSampleName}`; +const tabTitle: string = 'index.php'; +// const codeNavigationClassName: string = 'RouterImpl.class'; +const depTaskName: string = 'Configure Apache Web Server DocumentRoot'; +const buildTaskName: string = 'Start Apache Web Server'; +const buildTaskLinkExpectedText: string = 'A process is now listening on port 8080.'; +const stack: string = 'PHP Simple'; + +suite(`${stack} test`, async () => { + suite (`Create ${stack} workspace`, async () => { + workspaceHandling.createAndOpenWorkspace(stack); + projectAndFileTests.waitWorkspaceReadinessNoSubfolder(workspaceSampleName); + }); + + suite('Test opening file', async () => { + // opening file that soon should give time for LS to initialize + projectAndFileTests.openFile(fileFolderPath, tabTitle); + prepareEditorForLSTests(); + }); + + suite('Configuration of dependencies', async () => { + codeExecutionTests.runTask(depTaskName, 30_000); + }); + + suite('Language server validation', async () => { + commonLsTests.errorHighlighting(tabTitle, `error_text;`, 14); + commonLsTests.suggestionInvoking(tabTitle, 14, 26, '$test'); + commonLsTests.autocomplete(tabTitle, 15, 5, 'phpinfo'); + // commonLsTests.codeNavigation(tabTitle, 19, 7, codeNavigationClassName); // there is no codenavigation in the php simple stack (no object oriented code) + }); + + suite('Validation of project build', async () => { + codeExecutionTests.runTaskWithDialogShellAndOpenLink(buildTaskName, buildTaskLinkExpectedText, 30_000); + }); + + suite ('Stopping and deleting the workspace', async () => { + let workspaceName = 'not defined'; + suiteSetup( async () => { + workspaceName = await WorkspaceNameHandler.getNameFromUrl(); + }); + test (`Stop worksapce`, async () => { + await workspaceHandling.stopWorkspace(workspaceName); + }); + test (`Remove workspace`, async () => { + await workspaceHandling.removeWorkspace(workspaceName); + }); + }); + +}); + +export function prepareEditorForLSTests() { + test(`Prepare file for LS tests`, async () => { + await editor.moveCursorToLineAndChar(tabTitle, 12, 4); + await editor.performKeyCombination(tabTitle, '\n$test = " test";'); + await editor.moveCursorToLineAndChar(tabTitle, 14, 20); + await editor.performKeyCombination(tabTitle, ' . $test;\nphpinfo();'); + }); +} diff --git a/tests/e2e/testsLibrary/ProjectAndFileTests.ts b/tests/e2e/testsLibrary/ProjectAndFileTests.ts index d008892a88..c18b3f02dc 100644 --- a/tests/e2e/testsLibrary/ProjectAndFileTests.ts +++ b/tests/e2e/testsLibrary/ProjectAndFileTests.ts @@ -26,6 +26,17 @@ export function waitWorkspaceReadiness(sampleName : string, folder: string) { }); } +export function waitWorkspaceReadinessNoSubfolder(sampleName : string) { + test('Wait for workspace readiness', async () => { + await ide.waitAndSwitchToIdeFrame(); + await ide.waitPreloaderVisible(); + await ide.waitPreloaderAbsent(); + await ide.waitIde(); + await projectTree.openProjectTreeContainer(); + await projectTree.waitProjectImportedNoSubfolder(sampleName); + }); +} + export function openFile(filePath: string, fileName: string) { test('Expand project and open file in editor', async () => { await projectTree.expandPathAndOpenFileInAssociatedWorkspace(filePath, fileName); diff --git a/tests/e2e/testsLibrary/WorksapceHandlingTests.ts b/tests/e2e/testsLibrary/WorksapceHandlingTests.ts index b2ffcb8059..2f2bd60e85 100644 --- a/tests/e2e/testsLibrary/WorksapceHandlingTests.ts +++ b/tests/e2e/testsLibrary/WorksapceHandlingTests.ts @@ -11,15 +11,20 @@ import { CLASSES, Dashboard } from '..'; import { e2eContainer } from '../inversify.config'; import { GetStarted } from '../pageobjects/dashboard/GetStarted'; +import { Logger } from '../utils/Logger'; const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); const getStarted: GetStarted = e2eContainer.get(CLASSES.GetStarted); export function createAndOpenWorkspace(stack: string) { test(`Open 'New Workspace' page`, async () => { + Logger.trace(`WorkspaceHandlingTests.createAndOpenWorkspace wait for dashboard`); await dashboard.waitPage(); + Logger.trace(`WorkspaceHandlingTests.createAndOpenWorkspace click get started button`); await dashboard.clickGetStartedButton(); + Logger.trace(`WorkspaceHandlingTests.createAndOpenWorkspace wait for getting started page`); await getStarted.waitPage(); + Logger.trace(`WorkspaceHandlingTests.createAndOpenWorkspace click on sample ${stack}`); await getStarted.clickOnSample(stack); }); }