Skip to content

Commit

Permalink
Support 'trust author' popup in E2E tests (#23088)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Nochevnov <dnochevn@redhat.com>
  • Loading branch information
dmytro-ndp authored Aug 14, 2024
1 parent 245bb11 commit c48026c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tests/e2e/configs/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -90,6 +91,8 @@ e2eContainer.bind<WebTerminalPage>(CLASSES.WebTerminalPage).to(WebTerminalPage);
e2eContainer.bind<UserPreferences>(CLASSES.UserPreferences).to(UserPreferences);
e2eContainer.bind<Generator>(EXTERNAL_CLASSES.Generator).to(Generator);
e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader);
e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader);
e2eContainer.bind<TrustAuthorPopup>(CLASSES.TrustAuthorPopup).to(TrustAuthorPopup);

if (BASE_TEST_CONSTANTS.TS_PLATFORM === Platform.OPENSHIFT) {
if (OAUTH_CONSTANTS.TS_SELENIUM_VALUE_OPENSHIFT_OAUTH) {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/configs/inversify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const CLASSES: any = {
ContainerTerminal: 'ContainerTerminal',
UserPreferences: 'UserPreferences',
WebTerminalPage: 'WebTerminalPage',
RevokeOauthPage: 'RevokeOauthPage'
RevokeOauthPage: 'RevokeOauthPage',
TrustAuthorPopup: 'TrustAuthorPopup'
};

const EXTERNAL_CLASSES: any = {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/constants/CHROME_DRIVER_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
};
11 changes: 6 additions & 5 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 17 additions & 1 deletion tests/e2e/pageobjects/dashboard/CreateWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<void> {
Expand Down Expand Up @@ -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<void> {
Expand All @@ -93,6 +99,16 @@ export class CreateWorkspace {
await this.driverHelper.waitAndClick(editorDropdownListLocator, timeout);
}

async performTrustAuthorPopup(): Promise<void> {
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`);
}
Expand Down
42 changes: 42 additions & 0 deletions tests/e2e/pageobjects/dashboard/TrustAuthorPopup.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
Logger.debug();

await this.driverHelper.waitVisibility(TrustAuthorPopup.TRUST_AUTHOR_POPUP_PAGE, timeout);
}
}
2 changes: 2 additions & 0 deletions tests/e2e/tests-library/WorkspaceHandlingTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export class WorkspaceHandlingTests {
}

async obtainWorkspaceNameFromStartingPage(): Promise<void> {
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);
Expand Down

0 comments on commit c48026c

Please sign in to comment.