[Happy Path] Check application readiness before opening the link by the "DialogWindow.waitDialogAndOpenLink" method (#15553)

* Check application readiness before opening the link by the "DialogWindow.waitDialogAndOpenLink" method

Signed-off-by: Ihor Okhrimenko <iokhrime@redhat.com>
7.20.x
Igor Ohrimenko 2019-12-20 12:17:21 +02:00 committed by GitHub
parent d749c88176
commit 05dc11a9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -13,13 +13,15 @@ import { DriverHelper } from '../../utils/DriverHelper';
import { By } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TestConstants } from '../../TestConstants';
import { Ide } from './Ide';
@injectable()
export class DialogWindow {
private static readonly DIALOG_BODY_XPATH_LOCATOR: string = '//div[@id=\'theia-dialog-shell\']//div[@class=\'dialogBlock\']';
private static readonly CLOSE_BUTTON_XPATH_LOCATOR: string = `${DialogWindow.DIALOG_BODY_XPATH_LOCATOR}//button[text()='close']`;
constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }
constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper,
@inject(CLASSES.Ide) private readonly ide: Ide) { }
async dialogDisplayes(): Promise<boolean> {
Logger.debug('DialogWindow.dialogDisplayes');
@ -73,6 +75,7 @@ export class DialogWindow {
Logger.debug('DialogWindow.waitDialogAndOpenLink');
await this.waitDialog(timeout, dialogText);
await this.ide.waitApllicationIsReady(await this.getApplicationUrlFromDialog(dialogText));
await this.clickToOpenLinkButton();
await this.waitDialogDissappearance();
}
@ -83,4 +86,17 @@ export class DialogWindow {
await this.driverHelper.waitDisappearanceWithTimeout(By.xpath(DialogWindow.CLOSE_BUTTON_XPATH_LOCATOR));
}
async getApplicationUrlFromDialog(dialogWindowText: string) {
const notificationTextLocator: By = By.xpath(`${DialogWindow.DIALOG_BODY_XPATH_LOCATOR}//span[contains(text(), '${dialogWindowText}')]`);
let dialogWindow = await this.driverHelper.waitAndGetText(notificationTextLocator);
let regexp: RegExp = new RegExp('^.*(https?://.*)$');
if (!regexp.test(dialogWindow)) {
throw new Error('Cannot obtaine url from notification message');
}
return dialogWindow.split(regexp)[1];
}
}