Skip to content

Commit

Permalink
Fixing preview widget removal (#21396)
Browse files Browse the repository at this point in the history
* Deprecating PreviewWidget fragment and testsLibraries that use it

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

* Fixing package-lock.json (update by npm i)

Signed-off-by: Tibor Dancs <tdancs@redhat.com>

* Close tab locator fix suggested by @mmusien

Signed-off-by: Tibor Dancs <tdancs@redhat.com>
  • Loading branch information
ScrewTSW authored May 13, 2022
1 parent 29d4f0d commit 8e6670a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/e2e/pageobjects/ide/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/pageobjects/ide/PreviewWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
61 changes: 39 additions & 22 deletions tests/e2e/testsLibrary/CodeExecutionTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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();
});
}

Expand All @@ -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;
}
}
}
});
Expand All @@ -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.`);
});
}

Expand Down

0 comments on commit 8e6670a

Please sign in to comment.