From 8e6670a9d0800780f7452d0381b676e8179af6cf Mon Sep 17 00:00:00 2001 From: Tibor Dancs Date: Fri, 13 May 2022 16:09:37 +0200 Subject: [PATCH] Fixing preview widget removal (#21396) * Deprecating PreviewWidget fragment and testsLibraries that use it Signed-off-by: Tibor Dancs * Fixing package-lock.json (update by npm i) Signed-off-by: Tibor Dancs * Close tab locator fix suggested by @mmusien Signed-off-by: Tibor Dancs --- tests/e2e/package-lock.json | 2 +- tests/e2e/pageobjects/ide/Editor.ts | 2 +- tests/e2e/pageobjects/ide/PreviewWidget.ts | 3 + tests/e2e/testsLibrary/CodeExecutionTests.ts | 61 +++++++++++++------- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.json index 9dc44c4bcf7..cbf870e94e3 100644 --- a/tests/e2e/package-lock.json +++ b/tests/e2e/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@eclipse-che/che-e2e", - "version": "7.45.0-SNAPSHOT", + "version": "7.48.0-SNAPSHOT", "license": "ISC", "dependencies": { "@eclipse-che/api": "latest", diff --git a/tests/e2e/pageobjects/ide/Editor.ts b/tests/e2e/pageobjects/ide/Editor.ts index 8c885a6e8ca..cb543baec76 100644 --- a/tests/e2e/pageobjects/ide/Editor.ts +++ b/tests/e2e/pageobjects/ide/Editor.ts @@ -183,7 +183,7 @@ export class Editor { async closeTab(tabTitle: string, timeout: number = TimeoutConstants.TS_EDITOR_TAB_INTERACTION_TIMEOUT) { Logger.debug(`Editor.closeTab "${tabTitle}"`); - const tabCloseButtonLocator: By = By.xpath(`//div[text()='${tabTitle}']/parent::li//div[contains(@class, 'p-TabBar-tabCloseIcon')]`); + const tabCloseButtonLocator: By = By.xpath(`//li[contains(@id,'${tabTitle}')]//div[contains(@class, 'p-TabBar-tabCloseIcon')]`); await this.driverHelper.waitAndClick(tabCloseButtonLocator, timeout); } diff --git a/tests/e2e/pageobjects/ide/PreviewWidget.ts b/tests/e2e/pageobjects/ide/PreviewWidget.ts index f493c9e15aa..08a3aecdb3c 100644 --- a/tests/e2e/pageobjects/ide/PreviewWidget.ts +++ b/tests/e2e/pageobjects/ide/PreviewWidget.ts @@ -17,6 +17,9 @@ import { Ide } from './Ide'; import { Logger } from '../../utils/Logger'; import { TimeoutConstants } from '../../TimeoutConstants'; +/** + * @deprecated Preview widget is no longer a valid page fragment. + */ @injectable() export class PreviewWidget { private static readonly WIDGET_LOCATOR: By = By.css('div.theia-mini-browser'); diff --git a/tests/e2e/testsLibrary/CodeExecutionTests.ts b/tests/e2e/testsLibrary/CodeExecutionTests.ts index c975580c3d3..d6b469bd432 100644 --- a/tests/e2e/testsLibrary/CodeExecutionTests.ts +++ b/tests/e2e/testsLibrary/CodeExecutionTests.ts @@ -18,10 +18,10 @@ import { Terminal } from '../pageobjects/ide/Terminal'; import { TopMenu } from '../pageobjects/ide/TopMenu'; import { DialogWindow } from '../pageobjects/ide/DialogWindow'; import { DriverHelper } from '../utils/DriverHelper'; -import { PreviewWidget } from '../pageobjects/ide/PreviewWidget'; -import { RightToolBar } from '../pageobjects/ide/RightToolBar'; import { Logger } from '../utils/Logger'; import { QuickOpenContainer } from '../pageobjects/ide/QuickOpenContainer'; +import { BrowserTabsUtil } from '../utils/BrowserTabsUtil'; +import { WorkspaceHandlingTests } from './WorkspaceHandlingTests'; @injectable() export class CodeExecutionTests { @@ -34,9 +34,9 @@ export class CodeExecutionTests { @inject(CLASSES.Ide) private readonly ide: Ide, @inject(CLASSES.DialogWindow) private readonly dialogWindow: DialogWindow, @inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper, - @inject(CLASSES.PreviewWidget) private readonly previewWidget: PreviewWidget, - @inject(CLASSES.RightToolBar) private readonly rightToolBar: RightToolBar, - @inject(CLASSES.QuickOpenContainer) private readonly quickOpenContainer: QuickOpenContainer) {} + @inject(CLASSES.QuickOpenContainer) private readonly quickOpenContainer: QuickOpenContainer, + @inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil, + @inject(CLASSES.WorkspaceHandlingTests) private readonly workspaceHandlingTests: WorkspaceHandlingTests) {} public runTask(taskName: string, timeout: number) { test(`Run command '${taskName}'`, async () => { @@ -108,16 +108,21 @@ export class CodeExecutionTests { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotification(notificationText, timeout); await this.ide.clickOnNotificationButton(notificationText, buttonText); - CodeExecutionTests.lastApplicationUrl = await this.previewWidget.getUrl(); + await this.driverHelper.wait(5_000); + CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); }); } + /** + * @deprecated This method should not be used, preview widget is no longer a valid page fragment. + */ public runTaskWithNotificationAndOpenLinkPreviewNoUrl(taskName: string, notificationText: string, timeout: number) { test(`Run command '${taskName}' expecting notification`, async () => { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotification(notificationText, timeout); await this.ide.clickOnNotificationButton(notificationText, 'Open In Preview'); - CodeExecutionTests.lastApplicationUrl = await this.previewWidget.getUrl(); + await this.driverHelper.wait(5_000); + CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); }); } @@ -126,23 +131,30 @@ export class CodeExecutionTests { await this.runTaskUsingQuickOpenContainer(taskName); await this.ide.waitNotificationAndConfirm(notificationText, timeout); await this.ide.waitNotificationAndOpenLink(portOpenText, timeout); - CodeExecutionTests.lastApplicationUrl = await this.previewWidget.getUrl(); + await this.driverHelper.wait(5_000); + CodeExecutionTests.lastApplicationUrl = await this.driverHelper.getDriver().getCurrentUrl(); }); } public verifyRunningApplication(locator: By, applicationCheckTimeout: number, polling: number) { test(`Verify running application by locator: '${locator}'`, async () => { - await this.previewWidget.waitApplicationOpened(CodeExecutionTests.lastApplicationUrl, applicationCheckTimeout); - try { - await this.previewWidget.waitContentAvailable(locator, applicationCheckTimeout, polling); - } catch (err) { - // fix for preloader / application not available in preview widget - // https://issues.redhat.com/browse/CRW-2175 - if (err instanceof error.TimeoutError) { - Logger.warn(`CodeExecutionTests.verifyRunningApplication application not located, probably blocked by preloader or content not available. Retrying.`); - await this.ide.waitIde(); - await this.previewWidget.refreshPage(); - await this.previewWidget.waitContentAvailable(locator, applicationCheckTimeout, polling); + let timeout: number = applicationCheckTimeout / polling; + let attempts: number = applicationCheckTimeout / timeout; + for (let i = 0; i < attempts; i++) { + try { + await this.driverHelper.waitPresence(locator, timeout); + } catch (err) { + if (err instanceof error.TimeoutError) { + if (i === attempts - 1) { + Logger.error(`CodeExecutionTests.verifyRunningApplication out of retries to wait for ${locator} presence.`); + throw err; + } else { + Logger.trace(`CodeExecutionTests.verifyRunningApplication timed out waiting for ${locator} presence. Retrying ${i}.`); + } + } else { + Logger.error(`CodeExecutionTests.verifyRunningApplication failed with unexpected exception.`); + throw err; + } } } }); @@ -152,16 +164,21 @@ export class CodeExecutionTests { return CodeExecutionTests.lastApplicationUrl; } + /** + * @deprecated This method should not be used, preview widget is no longer a valid page fragment. + */ public refreshPreviewWindow() { test('Refreshing preview widget', async () => { - await this.previewWidget.refreshPage(); + Logger.warn(`Method is deprecated.`); }); } + /** + * @deprecated This method should not be used, preview widget is no longer a valid page fragment. + */ public closePreviewWidget() { test('Close preview widget', async () => { - await this.rightToolBar.clickOnToolIcon('Preview'); - await this.previewWidget.waitPreviewWidgetAbsence(); + Logger.warn(`Method is deprecated.`); }); }