Skip to content

Commit

Permalink
Added getLoaderAlert() method and getAllCreatedWorkspacesNames() into…
Browse files Browse the repository at this point in the history
… page objects.

Signed-off-by: mdolhalo <mdolhalo@redhat.com>
  • Loading branch information
Maryna Dolhalova committed Feb 28, 2023
1 parent 28be3f1 commit 8fd0486
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
15 changes: 11 additions & 4 deletions tests/e2e/pageobjects/dashboard/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { Logger } from '../../utils/Logger';
export class Dashboard {
private static readonly WORKSPACES_BUTTON_XPATH: string = `//div[@id='page-sidebar']//a[contains(text(), 'Workspaces (')]`;
private static readonly CREATE_WORKSPACE_BUTTON_XPATH: string = `//div[@id='page-sidebar']//a[text()='Create Workspace']`;
private static readonly LOADER_PAGE_CSS: string = '.main-page-loader';
private static readonly LOADER_PAGE_STEP_TITLES_XPATH: string = '//*[@data-testid="step-title"]';
private static readonly WORKSPACE_STARTING_PAGE_CSS: string = '.ide-loader-page';
private static readonly LOADER_ALERT_XPATH = '//*[@data-testid="loader-alert"]';

constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper,
@inject(CLASSES.Workspaces) private readonly workspaces: Workspaces) { }
@inject(CLASSES.Workspaces) private readonly workspaces: Workspaces) { }

async stopWorkspaceByUI(workspaceName: string) {
Logger.debug(`Dashboard.stopWorkspaceByUI "${workspaceName}"`);
Expand Down Expand Up @@ -84,16 +85,22 @@ export class Dashboard {
await this.driverHelper.waitAndClick(By.xpath(Dashboard.CREATE_WORKSPACE_BUTTON_XPATH), timeout);
}

async getLoaderAlert(timeout: number = TimeoutConstants.TS_WAIT_LOADER_PRESENCE_TIMEOUT) {
Logger.debug('Dashboard.getLoaderAlert');

return await this.driverHelper.waitAndGetText(By.xpath(Dashboard.LOADER_ALERT_XPATH), timeout);
}

async waitLoader(timeout: number = TimeoutConstants.TS_WAIT_LOADER_PRESENCE_TIMEOUT) {
Logger.debug('Dashboard.waitLoader');

await this.driverHelper.waitVisibility(By.css(Dashboard.LOADER_PAGE_CSS), timeout);
await this.driverHelper.waitAllPresence(By.xpath(Dashboard.LOADER_PAGE_STEP_TITLES_XPATH), timeout);
}

async waitLoaderDisappearance(timeout: number = TimeoutConstants.TS_WAIT_LOADER_ABSENCE_TIMEOUT) {
Logger.debug('Dashboard.waitLoaderDisappearance');

await this.driverHelper.waitDisappearance(By.css(Dashboard.LOADER_PAGE_CSS), timeout);
await this.driverHelper.waitDisappearance(By.xpath(Dashboard.LOADER_PAGE_STEP_TITLES_XPATH), timeout);
}

async waitDisappearanceNavigationMenu(timeout: number = TimeoutConstants.TS_COMMON_DASHBOARD_WAIT_TIMEOUT) {
Expand Down
26 changes: 23 additions & 3 deletions tests/e2e/pageobjects/dashboard/Workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { injectable, inject } from 'inversify';
import { DriverHelper } from '../../utils/DriverHelper';
import { CLASSES } from '../../inversify.types';
import { By } from 'selenium-webdriver';
import { By, WebElement } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TimeoutConstants } from '../../TimeoutConstants';

Expand All @@ -23,8 +23,10 @@ export enum WorkspaceStatusUI {
@injectable()
export class Workspaces {
private static readonly ADD_WORKSPACE_BUTTON_XPATH: string = `//button[text()='Add Workspace']`;
private static readonly WORKSPACE_ITEM_TABLE_NAME_SECTION_XPATH: string = `//td[@data-label="Name"]/span/a`;

constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }
constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) {
}

async waitPage(timeout: number = TimeoutConstants.TS_SELENIUM_LOAD_PAGE_TIMEOUT) {
Logger.debug('Workspaces.waitPage');
Expand Down Expand Up @@ -168,6 +170,25 @@ export class Workspaces {
await this.driverHelper.waitDisappearance(workspaceListItemLocator, timeout);
}

async getAllCreatedWorkspacesNames(timeout: number = TimeoutConstants.TS_COMMON_DASHBOARD_WAIT_TIMEOUT) {
Logger.debug('Workspaces.getAllCreatedWorkspacesNames');

const workspaceNames: string[] = [];
try {
const workspaceItems: WebElement[] = await this.driverHelper.waitAllPresence(By.xpath(Workspaces.WORKSPACE_ITEM_TABLE_NAME_SECTION_XPATH), timeout);
for (let item of workspaceItems) {
Logger.debug(`Workspaces.getAllCreatedWorkspacesNames - try to get ${workspaceItems.indexOf(item)} items name`);
workspaceNames.push(await item.getText());
Logger.debug(`Workspaces.getAllCreatedWorkspacesNames - workspace name is "${workspaceNames[workspaceNames.length - 1]}"`);
}
} catch (e) {
Logger.debug(`Workspaces.getAllCreatedWorkspacesNames - ${e}`);
}

Logger.debug(`Workspaces.getAllCreatedWorkspacesNames - ${workspaceNames.length} workspaces have been created in DevSpaces`);
return workspaceNames;
}

private getWorkspaceListItemLocator(workspaceName: string): string {
return `//tr[td/span/a[text()='${workspaceName}']]`;
}
Expand All @@ -191,5 +212,4 @@ export class Workspaces {
private getOpenButtonLocator(workspaceName: string) {
return By.xpath(`${this.getWorkspaceListItemLocator(workspaceName)}//td[@data-key=5]//a[text()='Open']`);
}

}

0 comments on commit 8fd0486

Please sign in to comment.