Skip to content

Commit da36bbf

Browse files
authored
[Test] Fix up 'factory' E2E tests when use public repository (#23617)
* Update test scenario 'NoSetupRepoFactory' * Update test scenario 'RefusedOAuthFactory' * Create 'SourceControlView' pageobject * Create 'GitHubExtensionDialog' pageobject
1 parent 83f7499 commit da36bbf

File tree

11 files changed

+277
-104
lines changed

11 files changed

+277
-104
lines changed

tests/e2e/configs/inversify.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import { CommandPalette } from '../pageobjects/ide/CommandPalette';
6060
import { ExtensionsView } from '../pageobjects/ide/ExtensionsView';
6161
import { ExplorerView } from '../pageobjects/ide/ExplorerView';
6262
import { NotificationHandler } from '../pageobjects/ide/NotificationHandler';
63+
import { SourceControlView } from '../pageobjects/ide/SourceControlView';
64+
import { GitHubExtensionDialog } from '../pageobjects/ide/GitHubExtensionDialog';
6365

6466
const e2eContainer: Container = new Container({ defaultScope: 'Transient', skipBaseClassChecks: true });
6567

@@ -105,6 +107,8 @@ e2eContainer.bind<CommandPalette>(CLASSES.CommandPalette).to(CommandPalette);
105107
e2eContainer.bind<ExtensionsView>(CLASSES.ExtensionsView).to(ExtensionsView);
106108
e2eContainer.bind<ExplorerView>(CLASSES.ExplorerView).to(ExplorerView);
107109
e2eContainer.bind<NotificationHandler>(CLASSES.NotificationHandler).to(NotificationHandler);
110+
e2eContainer.bind<SourceControlView>(CLASSES.SourceControlView).to(SourceControlView);
111+
e2eContainer.bind<GitHubExtensionDialog>(CLASSES.GitHubExtensionDialog).to(GitHubExtensionDialog);
108112

109113
if (BASE_TEST_CONSTANTS.TS_PLATFORM === Platform.OPENSHIFT) {
110114
if (OAUTH_CONSTANTS.TS_SELENIUM_VALUE_OPENSHIFT_OAUTH) {

tests/e2e/configs/inversify.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const CLASSES: any = {
5757
CommandPalette: 'CommandPalette',
5858
ExtensionsView: 'ExtensionsView',
5959
ExplorerView: 'ExplorerView',
60-
NotificationHandler: 'NotificationHandler'
60+
NotificationHandler: 'NotificationHandler',
61+
SourceControlView: 'SourceControlView',
62+
GitHubExtensionDialog: 'GitHubExtensionDialog'
6163
};
6264

6365
const EXTERNAL_CLASSES: any = {

tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export const FACTORY_TEST_CONSTANTS: {
2727
TS_SELENIUM_FACTORY_GIT_REPO_BRANCH: string;
2828
TS_SELENIUM_SSH_PRIVATE_KEY_PATH: string;
2929
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: string;
30+
TS_GIT_COMMIT_AUTHOR_NAME: string;
31+
TS_GIT_COMMIT_AUTHOR_EMAIL: string;
32+
TS_GIT_PERSONAL_ACCESS_TOKEN: string;
3033
TS_SELENIUM_SSH_PRIVATE_KEY: string;
3134
TS_SELENIUM_SSH_PUBLIC_KEY: string;
3235
TS_SELENIUM_FACTORY_URL(): string;
@@ -71,6 +74,21 @@ export const FACTORY_TEST_CONSTANTS: {
7174
*/
7275
TS_SELENIUM_SSH_PUBLIC_KEY_PATH: process.env.TS_SELENIUM_SSH_PUBLIC_KEY_PATH || 'resources/factory/pub-k.txt',
7376

77+
/**
78+
* git commit author name
79+
*/
80+
TS_GIT_COMMIT_AUTHOR_NAME: process.env.TS_GIT_CONFIG_USER_NAME || 'user',
81+
82+
/**
83+
* git commit author email
84+
*/
85+
TS_GIT_COMMIT_AUTHOR_EMAIL: process.env.TS_GIT_CONFIG_USER_EMAIL || '[email protected]',
86+
87+
/**
88+
* personal access token of git provider (or api token if Bitbucket.org)
89+
*/
90+
TS_GIT_PERSONAL_ACCESS_TOKEN: process.env.TS_GIT_PERSONAL_ACCESS_TOKEN || '',
91+
7492
/**
7593
* sSH private key as string (from environment variable)
7694
*/

tests/e2e/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ export * from './pageobjects/dashboard/Workspaces';
3131
export * from './pageobjects/git-providers/OauthPage';
3232
export * from './pageobjects/ide/CheCodeLocatorLoader';
3333
export * from './pageobjects/ide/CommandPalette';
34+
export * from './pageobjects/ide/GitHubExtensionDialog';
3435
export * from './pageobjects/ide/ExplorerView';
3536
export * from './pageobjects/ide/ExtensionsView';
3637
export * from './pageobjects/ide/NotificationHandler';
3738
export * from './pageobjects/ide/RestrictedModeButton';
39+
export * from './pageobjects/ide/SourceControlView';
3840
export * from './pageobjects/ide/ViewsMoreActionsButton';
3941
export * from './pageobjects/login/interfaces/ICheLoginPage';
4042
export * from './pageobjects/login/interfaces/IOcpLoginPage';

tests/e2e/pageobjects/dashboard/UserPreferences.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class UserPreferences {
3333
private static readonly ADD_NEW_PAT_BUTTON: By = By.xpath('//button[text()="Add Personal Access Token"]');
3434

3535
private static readonly GIT_CONFIG_PAGE: By = By.xpath('//button[text()="Gitconfig"]');
36+
private static readonly GIT_CONFIG_USER_NAME: By = By.id('gitconfig-user-name');
37+
private static readonly GIT_CONFIG_USER_EMAIL: By = By.id('gitconfig-user-email');
38+
private static readonly GIT_CONFIG_SAVE_BUTTON: By = By.css('[data-testid="button-save"]');
3639

3740
private static readonly SSH_KEY_TAB: By = By.xpath('//button[text()="SSH Keys"]');
3841
private static readonly ADD_NEW_SSH_KEY_BUTTON: By = By.xpath('//button[text()="Add SSH Key"]');
@@ -123,6 +126,39 @@ export class UserPreferences {
123126
await this.driverHelper.waitAndClick(UserPreferences.GIT_CONFIG_PAGE);
124127
}
125128

129+
async enterGitConfigUsernameAndEmail(userName: string, userEmail: string): Promise<void> {
130+
Logger.debug(`"${userName}"`);
131+
Logger.debug(`"${userEmail}"`);
132+
133+
await this.driverHelper.enterValue(UserPreferences.GIT_CONFIG_USER_NAME, userName);
134+
await this.driverHelper.enterValue(UserPreferences.GIT_CONFIG_USER_EMAIL, userEmail);
135+
}
136+
137+
async clickOnGitConfigSaveButton(): Promise<void> {
138+
Logger.debug();
139+
140+
await this.driverHelper.waitAndClick(UserPreferences.GIT_CONFIG_SAVE_BUTTON);
141+
}
142+
143+
async waitGitConfigSaveButtonIsDisabled(): Promise<void> {
144+
Logger.debug();
145+
146+
await this.driverHelper.waitAttributeValue(
147+
UserPreferences.GIT_CONFIG_SAVE_BUTTON,
148+
'aria-disabled',
149+
'true',
150+
TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT
151+
);
152+
}
153+
154+
async setupGitConfig(userName: string, userEmail: string): Promise<void> {
155+
await this.openUserPreferencesPage();
156+
await this.openGitConfigPage();
157+
await this.enterGitConfigUsernameAndEmail(userName, userEmail);
158+
await this.clickOnGitConfigSaveButton();
159+
// await userPreferences.waitGitConfigSaveButtonIsDisabled();// TODO: restore line after fix https://github.com/eclipse-che/che/issues/23625
160+
}
161+
126162
async openSshKeyTab(): Promise<void> {
127163
Logger.debug();
128164

tests/e2e/pageobjects/git-providers/OauthPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class OauthPage {
7474
{
7575
OauthPage.LOGIN_FORM = By.id('login_field');
7676
OauthPage.PASSWORD_FORM = By.id('password');
77-
OauthPage.APPROVE_BUTTON = By.xpath('//*[@id="js-oauth-authorize-btn"]');
77+
OauthPage.APPROVE_BUTTON = By.xpath('//button[contains(., "Authorize")]');
7878
OauthPage.SUBMIT_BUTTON = By.xpath('//*[@value="Sign in"]');
7979
OauthPage.DENY_ACCESS_BUTTON = By.xpath('//button[contains(., "Cancel")]');
8080
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** *******************************************************************
2+
* copyright (c) 2025 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
import { inject, injectable } from 'inversify';
11+
import 'reflect-metadata';
12+
import { CLASSES } from '../../configs/inversify.types';
13+
import { DriverHelper } from '../../utils/DriverHelper';
14+
import { Logger } from '../../utils/Logger';
15+
import { By, ModalDialog } from 'monaco-page-objects';
16+
import { CheCodeLocatorLoader } from './CheCodeLocatorLoader';
17+
18+
@injectable()
19+
export class GitHubExtensionDialog {
20+
private static readonly DIALOG_LOCATOR: By = By.xpath(
21+
'//div[@class="dialog-message-detail" and contains(., "The extension \'GitHub\' wants to sign in using GitHub.")]'
22+
);
23+
24+
constructor(
25+
@inject(CLASSES.DriverHelper)
26+
private readonly driverHelper: DriverHelper,
27+
@inject(CLASSES.CheCodeLocatorLoader)
28+
private readonly cheCodeLocatorLoader: CheCodeLocatorLoader
29+
) {}
30+
31+
/**
32+
* check if the dialog box with the message about the GitHub extension is visible.
33+
* @returns Promise resolving to boolean.
34+
*/
35+
async isDialogVisible(): Promise<boolean> {
36+
Logger.debug();
37+
38+
return await this.driverHelper.waitVisibilityBoolean(GitHubExtensionDialog.DIALOG_LOCATOR);
39+
}
40+
41+
/**
42+
* close the dialog box with the message about the GitHub extension.
43+
*/
44+
async closeDialog(): Promise<void> {
45+
Logger.debug();
46+
47+
const modalDialog: ModalDialog = new ModalDialog();
48+
await modalDialog.close();
49+
await this.driverHelper.waitDisappearance(this.cheCodeLocatorLoader.webCheCodeLocators.Dialog.constructor);
50+
Logger.debug('Dialog box with the message about the GitHub extension closed');
51+
}
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** *******************************************************************
2+
* copyright (c) 2025 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
import { inject, injectable } from 'inversify';
11+
import 'reflect-metadata';
12+
import { CLASSES } from '../../configs/inversify.types';
13+
import { DriverHelper } from '../../utils/DriverHelper';
14+
import { Logger } from '../../utils/Logger';
15+
import { Key } from 'selenium-webdriver';
16+
17+
@injectable()
18+
export class SourceControlView {
19+
constructor(
20+
@inject(CLASSES.DriverHelper)
21+
readonly driverHelper: DriverHelper
22+
) {}
23+
24+
/**
25+
* type the commit message and press Ctrl+Enter to commit the changes.
26+
* @param textCommit Text to commit.
27+
*/
28+
async typeCommitMessage(textCommit: string): Promise<void> {
29+
Logger.debug(`Type commit text: "Commit ${textCommit}"`);
30+
31+
await this.driverHelper.getDriver().actions().sendKeys(textCommit).perform();
32+
Logger.debug('Press Enter to commit the changes');
33+
await this.driverHelper.getDriver().actions().keyDown(Key.CONTROL).sendKeys(Key.ENTER).keyUp(Key.CONTROL).perform();
34+
}
35+
}

tests/e2e/specs/factory/Factory.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
3131
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
3232
import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace';
3333
import { ViewsMoreActionsButton } from '../../pageobjects/ide/ViewsMoreActionsButton';
34+
import { SourceControlView } from '../../pageobjects/ide/SourceControlView';
3435

3536
suite(
3637
`Create a workspace via launching a factory from the ${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER} repository ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`,
@@ -47,6 +48,7 @@ suite(
4748
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
4849
const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace);
4950
const viewsMoreActionsButton: ViewsMoreActionsButton = e2eContainer.get(CLASSES.ViewsMoreActionsButton);
51+
const sourceControlView: SourceControlView = e2eContainer.get(CLASSES.SourceControlView);
5052

5153
let projectSection: ViewSection;
5254
let scmProvider: SingleScmProvider;
@@ -103,8 +105,10 @@ suite(
103105
});
104106

105107
test('Check if the project files were imported', async function (): Promise<void> {
106-
const label: string = BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME;
107-
expect(await projectAndFileTests.getProjectTreeItem(projectSection, label), 'Project files were not imported').not.undefined;
108+
expect(
109+
await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME),
110+
'Project files were not imported'
111+
).not.undefined;
108112
});
109113

110114
test('Make changes to the file', async function (): Promise<void> {
@@ -166,10 +170,7 @@ suite(
166170
.getDriver()
167171
.findElement((webCheCodeLocators.ScmView as any).scmEditor)
168172
.click();
169-
Logger.debug(`Type commit text: "Commit ${changesToCommit}"`);
170-
await driverHelper.getDriver().actions().sendKeys(changesToCommit).perform();
171-
Logger.debug('Press Enter to commit the changes');
172-
await driverHelper.getDriver().actions().keyDown(Key.CONTROL).sendKeys(Key.ENTER).keyUp(Key.CONTROL).perform();
173+
await sourceControlView.typeCommitMessage(changesToCommit);
173174
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
174175
await driverHelper.wait(timeToRefresh);
175176
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);

0 commit comments

Comments
 (0)