From c48026cac148f06c1a3f4a5e831b193fd1a2d12a Mon Sep 17 00:00:00 2001 From: Dmytro Nochevnov Date: Thu, 15 Aug 2024 02:42:50 +0300 Subject: [PATCH] Support 'trust author' popup in E2E tests (#23088) Signed-off-by: Dmytro Nochevnov --- tests/e2e/configs/inversify.config.ts | 3 ++ tests/e2e/configs/inversify.types.ts | 3 +- .../e2e/constants/CHROME_DRIVER_CONSTANTS.ts | 2 +- tests/e2e/index.ts | 11 ++--- .../pageobjects/dashboard/CreateWorkspace.ts | 18 +++++++- .../pageobjects/dashboard/TrustAuthorPopup.ts | 42 +++++++++++++++++++ .../tests-library/WorkspaceHandlingTests.ts | 2 + 7 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 tests/e2e/pageobjects/dashboard/TrustAuthorPopup.ts diff --git a/tests/e2e/configs/inversify.config.ts b/tests/e2e/configs/inversify.config.ts index 9f647c6de54..4bb89cf6e52 100644 --- a/tests/e2e/configs/inversify.config.ts +++ b/tests/e2e/configs/inversify.config.ts @@ -53,6 +53,7 @@ import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../utils/ import { ShellExecutor } from '../utils/ShellExecutor'; import { UserPreferences } from '../pageobjects/dashboard/UserPreferences'; import { WebTerminalPage } from '../pageobjects/webterminal/WebTerminalPage'; +import { TrustAuthorPopup } from '../pageobjects/dashboard/TrustAuthorPopup'; const e2eContainer: Container = new Container({ defaultScope: 'Transient', skipBaseClassChecks: true }); @@ -90,6 +91,8 @@ e2eContainer.bind(CLASSES.WebTerminalPage).to(WebTerminalPage); e2eContainer.bind(CLASSES.UserPreferences).to(UserPreferences); e2eContainer.bind(EXTERNAL_CLASSES.Generator).to(Generator); e2eContainer.bind(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader); +e2eContainer.bind(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader); +e2eContainer.bind(CLASSES.TrustAuthorPopup).to(TrustAuthorPopup); if (BASE_TEST_CONSTANTS.TS_PLATFORM === Platform.OPENSHIFT) { if (OAUTH_CONSTANTS.TS_SELENIUM_VALUE_OPENSHIFT_OAUTH) { diff --git a/tests/e2e/configs/inversify.types.ts b/tests/e2e/configs/inversify.types.ts index dd44525a41e..ab89535896f 100644 --- a/tests/e2e/configs/inversify.types.ts +++ b/tests/e2e/configs/inversify.types.ts @@ -50,7 +50,8 @@ const CLASSES: any = { ContainerTerminal: 'ContainerTerminal', UserPreferences: 'UserPreferences', WebTerminalPage: 'WebTerminalPage', - RevokeOauthPage: 'RevokeOauthPage' + RevokeOauthPage: 'RevokeOauthPage', + TrustAuthorPopup: 'TrustAuthorPopup' }; const EXTERNAL_CLASSES: any = { diff --git a/tests/e2e/constants/CHROME_DRIVER_CONSTANTS.ts b/tests/e2e/constants/CHROME_DRIVER_CONSTANTS.ts index 98ffa32a819..a6e67c65850 100644 --- a/tests/e2e/constants/CHROME_DRIVER_CONSTANTS.ts +++ b/tests/e2e/constants/CHROME_DRIVER_CONSTANTS.ts @@ -44,5 +44,5 @@ export const CHROME_DRIVER_CONSTANTS: { /** * run browser with proxy settings */ - TS_SELENIUM_PROXY_SERVER: process.env.TS_SELENIUM_PROXY_SERVER || '', + TS_SELENIUM_PROXY_SERVER: process.env.TS_SELENIUM_PROXY_SERVER || '' }; diff --git a/tests/e2e/index.ts b/tests/e2e/index.ts index 990e6e578a0..9f91e26cd3e 100644 --- a/tests/e2e/index.ts +++ b/tests/e2e/index.ts @@ -5,28 +5,29 @@ export * from './configs/mocharc'; export * from './driver/ChromeDriver'; export * from './driver/IDriver'; export * from './utils/BrowserTabsUtil'; -export * from './utils/DevWorkspaceConfigurationHelper'; export * from './utils/DevfilesRegistryHelper'; +export * from './utils/DevWorkspaceConfigurationHelper'; export * from './utils/DriverHelper'; export * from './utils/IContextParams'; export * from './utils/IKubernetesCommandLineToolsExecutor'; export * from './utils/KubernetesCommandLineToolsExecutor'; export * from './utils/Logger'; -export * from './utils/ScreenCatcher'; -export * from './utils/ShellExecutor'; -export * from './utils/StringUtil'; export * from './utils/request-handlers/CheApiRequestHandler'; export * from './utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler'; export * from './utils/request-handlers/headers/IAuthorizationHeaderHandler'; +export * from './utils/ScreenCatcher'; +export * from './utils/ShellExecutor'; +export * from './utils/StringUtil'; export * from './utils/workspace/ApiUrlResolver'; export * from './utils/workspace/ITestWorkspaceUtil'; export * from './utils/workspace/TestWorkspaceUtil'; export * from './utils/workspace/WorkspaceStatus'; export * from './pageobjects/dashboard/CreateWorkspace'; export * from './pageobjects/dashboard/Dashboard'; +export * from './pageobjects/dashboard/TrustAuthorPopup'; export * from './pageobjects/dashboard/UserPreferences'; -export * from './pageobjects/dashboard/Workspaces'; export * from './pageobjects/dashboard/workspace-details/WorkspaceDetails'; +export * from './pageobjects/dashboard/Workspaces'; export * from './pageobjects/git-providers/OauthPage'; export * from './pageobjects/ide/CheCodeLocatorLoader'; export * from './pageobjects/login/interfaces/ICheLoginPage'; diff --git a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts index 4a509556f50..0b817e9492a 100644 --- a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts +++ b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts @@ -15,6 +15,7 @@ import { By, Key } from 'selenium-webdriver'; import { Logger } from '../../utils/Logger'; import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; +import { TrustAuthorPopup } from './TrustAuthorPopup'; @injectable() export class CreateWorkspace { @@ -26,7 +27,10 @@ export class CreateWorkspace { constructor( @inject(CLASSES.DriverHelper) - private readonly driverHelper: DriverHelper + private readonly driverHelper: DriverHelper, + + @inject(CLASSES.TrustAuthorPopup) + private readonly trustAuthorPopup: TrustAuthorPopup ) {} async waitTitleContains(expectedText: string, timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise { @@ -84,6 +88,8 @@ export class CreateWorkspace { } await this.driverHelper.waitAndClick(CreateWorkspace.CREATE_AND_OPEN_BUTTON, timeout); + + await this.performTrustAuthorPopup(); } async clickOnEditorsDropdownListButton(sampleName: string, timeout: number): Promise { @@ -93,6 +99,16 @@ export class CreateWorkspace { await this.driverHelper.waitAndClick(editorDropdownListLocator, timeout); } + async performTrustAuthorPopup(): Promise { + Logger.debug(); + + try { + await this.trustAuthorPopup.clickContinue(); + } catch (e) { + Logger.info('"Trust author" popup was not shown'); + } + } + private getEditorsDropdownListLocator(sampleName: string): By { return By.xpath(`//div[text()=\'${sampleName}\']//parent::article//button`); } diff --git a/tests/e2e/pageobjects/dashboard/TrustAuthorPopup.ts b/tests/e2e/pageobjects/dashboard/TrustAuthorPopup.ts new file mode 100644 index 00000000000..4d00c703cd8 --- /dev/null +++ b/tests/e2e/pageobjects/dashboard/TrustAuthorPopup.ts @@ -0,0 +1,42 @@ +/** ******************************************************************* + * copyright (c) 2019-2023 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 { inject, injectable } from 'inversify'; +import 'reflect-metadata'; +import { CLASSES } from '../../configs/inversify.types'; +import { By } from 'selenium-webdriver'; +import { DriverHelper } from '../../utils/DriverHelper'; +import { Logger } from '../../utils/Logger'; +import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; + +@injectable() +export class TrustAuthorPopup { + private static readonly CONTINUE_BUTTON: By = By.xpath('//button[text()="Continue"]'); + private static readonly TRUST_AUTHOR_POPUP_PAGE: By = By.xpath( + '//span[contains(text(), "Do you trust the authors of this repository?")]' + ); + + constructor( + @inject(CLASSES.DriverHelper) + readonly driverHelper: DriverHelper + ) {} + + async clickContinue(timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM): Promise { + Logger.debug(); + + await this.waitPopupIsOpened(); + await this.driverHelper.waitAndClick(TrustAuthorPopup.CONTINUE_BUTTON, timeout); + } + + async waitPopupIsOpened(timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM): Promise { + Logger.debug(); + + await this.driverHelper.waitVisibility(TrustAuthorPopup.TRUST_AUTHOR_POPUP_PAGE, timeout); + } +} diff --git a/tests/e2e/tests-library/WorkspaceHandlingTests.ts b/tests/e2e/tests-library/WorkspaceHandlingTests.ts index e92702b725e..2c2a2df8f1b 100644 --- a/tests/e2e/tests-library/WorkspaceHandlingTests.ts +++ b/tests/e2e/tests-library/WorkspaceHandlingTests.ts @@ -77,6 +77,8 @@ export class WorkspaceHandlingTests { } async obtainWorkspaceNameFromStartingPage(): Promise { + await this.createWorkspace.performTrustAuthorPopup(); + const timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_START_WORKSPACE_TIMEOUT; const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING; const attempts: number = Math.ceil(timeout / polling);