From f3d5a89bd027454dbf8e655da89df4d1602b46d7 Mon Sep 17 00:00:00 2001 From: Igor Ohrimenko Date: Tue, 3 Mar 2020 19:24:29 +0200 Subject: [PATCH] Create "Get Started" page object in E2E typescript selenium tests (#16213) Signed-off-by: Ihor Okhrimenko --- tests/e2e/inversify.config.ts | 2 + tests/e2e/inversify.types.ts | 3 +- tests/e2e/pageobjects/dashboard/GetStarted.ts | 90 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/pageobjects/dashboard/GetStarted.ts diff --git a/tests/e2e/inversify.config.ts b/tests/e2e/inversify.config.ts index 9eebadb975..dc7ee0785b 100644 --- a/tests/e2e/inversify.config.ts +++ b/tests/e2e/inversify.config.ts @@ -54,6 +54,7 @@ import { ITokenHandler } from './utils/requestHandlers/tokens/ITokenHandler'; import { CheApiRequestHandler } from './utils/requestHandlers/CheApiRequestHandler'; import { CheGitApi } from './utils/VCS/CheGitApi'; import { GitHubUtil } from './utils/VCS/github/GitHubUtil'; +import { GetStarted } from './pageobjects/dashboard/GetStarted'; const e2eContainer: Container = new Container({ defaultScope: 'Transient' }); @@ -105,5 +106,6 @@ e2eContainer.bind(CLASSES.PreferencesHandler).to(Preferences e2eContainer.bind(CLASSES.CheApiRequestHandler).to(CheApiRequestHandler); e2eContainer.bind(CLASSES.CheGitApi).to(CheGitApi); e2eContainer.bind(CLASSES.GitHubUtil).to(GitHubUtil); +e2eContainer.bind(CLASSES.GetStarted).to(GetStarted); export { e2eContainer }; diff --git a/tests/e2e/inversify.types.ts b/tests/e2e/inversify.types.ts index 71e521f998..b9fa21ca76 100644 --- a/tests/e2e/inversify.types.ts +++ b/tests/e2e/inversify.types.ts @@ -50,7 +50,8 @@ const CLASSES = { TestWorkspaceUtil: 'TestWorkspaceUtil', NotificationCenter: 'NotificationCenter', PreferencesHandler: 'PreferencesHandler', - CheApiRequestHandler: 'CheApiRequestHandler' + CheApiRequestHandler: 'CheApiRequestHandler', + GetStarted: 'GetStarted' }; export { TYPES, CLASSES }; diff --git a/tests/e2e/pageobjects/dashboard/GetStarted.ts b/tests/e2e/pageobjects/dashboard/GetStarted.ts new file mode 100644 index 0000000000..bb4e0ddc0a --- /dev/null +++ b/tests/e2e/pageobjects/dashboard/GetStarted.ts @@ -0,0 +1,90 @@ +/********************************************************************* + * Copyright (c) 2019 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +import { injectable, inject } from 'inversify'; +import { CLASSES } from '../../inversify.types'; +import { DriverHelper } from '../../utils/DriverHelper'; +import { TestConstants } from '../../TestConstants'; +import { By } from 'selenium-webdriver'; +import { Logger } from '../../utils/Logger'; + +@injectable() +export class GetStarted { + constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { } + + async waitTitleContains(expectedText: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.waitTitleContains text: "${expectedText}"`); + + const pageTitleLocator: By = By.xpath(`//div[contains(@che-title, '${expectedText}')]`); + + await this.driverHelper.waitVisibility(pageTitleLocator, timeout); + } + + async waitPage(timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug('GetStarted.waitPage'); + + await this.waitTitleContains('Getting Started', timeout); + } + + async waitSample(sampleName: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.waitSample sampleName: "${sampleName}"`); + + const sampleLocator: By = this.getSampleLocator(sampleName); + + await this.driverHelper.waitVisibility(sampleLocator, timeout); + } + + async clickOnSample(sampleName: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.clickOnSample sampleName: "${sampleName}"`); + + const sampleLocator: By = this.getSampleLocator(sampleName); + + await this.driverHelper.waitAndClick(sampleLocator, timeout); + } + + async selectSample(sampleName: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.selectSample sampleName: "${sampleName}"`); + + await this.clickOnSample(sampleName, timeout); + await this.waitSampleSelected(sampleName, timeout); + } + + async waitSampleSelected(sampleName: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.waitSampleSelected sampleName: "${sampleName}"`); + + const selectedSampleLocator: By = + By.xpath(`//div[contains(@class, 'get-started-template') and contains(@class, 'selected')]//span[text()='${sampleName}']`); + + await this.driverHelper.waitVisibility(selectedSampleLocator, timeout); + } + + async waitSampleUnselected(sampleName: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug(`GetStarted.waitSampleUnselected sampleName: "${sampleName}"`); + + const unselectedSampleLocator: By = + By.xpath(`//div[contains(@class, 'get-started-template') and not(contains(@class, 'selected'))]//span[text()='${sampleName}']`); + + await this.driverHelper.waitVisibility(unselectedSampleLocator, timeout); + } + + async clickCreateAndOpenButton(timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) { + Logger.debug('GetStarted.clickCreateAndOpenButton'); + const createAndOpenButtonXpath: string = '(//che-button-save-flat[@che-button-title=\'Create & Open\'][@aria-disabled=\'false\']/button)[1]'; + + await this.driverHelper.waitAndClick(createAndOpenButtonXpath, timeout); + } + + private getSampleLocator(sampleName: string): By { + Logger.trace(`GetStarted.getSampleLocator sampleName: ${sampleName}`); + + return By.xpath(`//div[contains(@class, 'get-started-template')]//span[text()='${sampleName}']`); + } + +}