Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HappyPath] Make checking running application more stable #14284

Merged
merged 7 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"ts-node": "^8.0.3",
"tslint": "5.10.0",
"typed-rest-client": "^1.2.0",
"typescript": "^3.4.3"
"typescript": "^3.4.3",
"axios": "0.17.1"
},
"dependencies": {
"inversify": "^5.0.1",
Expand Down
34 changes: 34 additions & 0 deletions e2e/pageobjects/ide/Ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import axios from 'axios';
import { DriverHelper } from '../../utils/DriverHelper';
import { injectable, inject } from 'inversify';
import { CLASSES } from '../../inversify.types';
Expand Down Expand Up @@ -74,6 +75,7 @@ export class Ide {
}

async waitNotificationAndOpenLink(notificationText: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
await this.waitApplicationReadyToUse(await this.getApplicationUrl(notificationText));
await this.waitNotificationAndClickOnButton(notificationText, 'Open Link', timeout);
}

Expand Down Expand Up @@ -229,6 +231,38 @@ export class Ide {
await this.driverHelper.waitVisibility(selectedRightToolbarButtonLocator, timeout);
}

async getApplicationUrl(notificationText: string) {
const notificationTextLocator: By = By.xpath(`//div[@class='theia-Notification']//p[contains(@id,'${notificationText}')]`);

let notification = await this.driverHelper.waitAndGetText(notificationTextLocator);
let regexp: RegExp = new RegExp('^.*(https?://.*)$');

if (!regexp.test(notification)) {
throw new Error('Cannot obtaine url from notification message');
}

return notification.split(regexp)[1];
}

async waitApplicationReadyToUse(url: string,
timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {

await this.driverHelper.getDriver().wait(async () => {
try {
let res = await axios.get(url);

if (res.status === 200) {
console.log('Application is ready for use.');
return true;
}
} catch (error) {
console.log('Application is not yet ready for use');
}

await this.driverHelper.wait(TestConstants.TS_SELENIUM_DEFAULT_POLLING);
}, timeout);
}

private getSelectedRightToolbarButtonLocator(buttonTitle: string): By {
return By.xpath(`//div[@id='theia-left-content-panel']//ul[@class='p-TabBar-content']` +
`//li[@title='${buttonTitle}' and contains(@id, 'shell-tab')] and contains(@class, 'p-mod-current')`);
Expand Down