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

Added getLoaderAlert() method and getAllCreatedWorkspacesNames() into page objects. #22020

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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']`);
}

}