Skip to content
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
10 changes: 8 additions & 2 deletions tests/e2e/constants/FACTORY_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const FACTORY_TEST_CONSTANTS: {
TS_GIT_PERSONAL_ACCESS_TOKEN: string;
TS_SELENIUM_SSH_PRIVATE_KEY: string;
TS_SELENIUM_SSH_PUBLIC_KEY: string;
TS_SELENIUM_SSH_KEY_PASSPHRASE: string;
TS_SELENIUM_FACTORY_URL(): string;
} = {
/**
Expand Down Expand Up @@ -90,15 +91,20 @@ export const FACTORY_TEST_CONSTANTS: {
TS_GIT_PERSONAL_ACCESS_TOKEN: process.env.TS_GIT_PERSONAL_ACCESS_TOKEN || '',

/**
* sSH private key as string (from environment variable)
* ssh private key as string (from environment variable)
*/
TS_SELENIUM_SSH_PRIVATE_KEY: process.env.TS_SELENIUM_SSH_PRIVATE_KEY || '',

/**
* sSH public key as string (from environment variable)
* ssh public key as string (from environment variable)
*/
TS_SELENIUM_SSH_PUBLIC_KEY: process.env.TS_SELENIUM_SSH_PUBLIC_KEY || '',

/**
* ssh key passphrase as string (from environment variable)
*/
TS_SELENIUM_SSH_KEY_PASSPHRASE: process.env.TS_SELENIUM_SSH_KEY_PASSPHRASE || '',

/**
* full factory URL
*/
Expand Down
9 changes: 8 additions & 1 deletion tests/e2e/pageobjects/dashboard/UserPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class UserPreferences {
private static readonly ADD_SSH_KEYS_POPUP: By = By.xpath('//span[text()="Add SSH Keys"]');
private static readonly PASTE_PRIVATE_SSH_KEY_FIELD: By = By.css('textarea[name="ssh-private-key"]');
private static readonly PASTE_PUBLIC_SSH_KEY_FIELD: By = By.css('textarea[name="ssh-public-key"]');
private static readonly PASTE_SSH_KEY_PASSPHRASE_FIELD: By = By.xpath('//input[@placeholder="Enter passphrase (optional)"]');
private static readonly ADD_SSH_KEYS_BUTTON: By = By.css('.pf-c-button.pf-m-primary');
private static readonly GIT_SSH_KEY_NAME: By = By.css('[data-testid="title"]');
private static readonly GIT_SSH_KEY_ACTIONS_BUTTON: By = By.css('section[id*="SshKeys-user-preferences"] button[aria-label="Actions"]');
Expand Down Expand Up @@ -184,7 +185,7 @@ export class UserPreferences {
Logger.info('SSH keys have been added');
}

async addSshKeysFromStrings(privateSshKey: string, publicSshKey: string): Promise<void> {
async addSshKeysFromStrings(privateSshKey: string, publicSshKey: string, passphrase?: string): Promise<void> {
Logger.debug();

if (!privateSshKey || privateSshKey === '') {
Expand All @@ -206,6 +207,12 @@ export class UserPreferences {
await this.driverHelper.waitAndClick(UserPreferences.PASTE_PUBLIC_SSH_KEY_FIELD);
await this.driverHelper.getAction().sendKeys(publicSshKey).perform();

if (passphrase) {
Logger.info('Pasting SSH key passphrase');
await this.driverHelper.waitAndClick(UserPreferences.PASTE_SSH_KEY_PASSPHRASE_FIELD);
await this.driverHelper.getAction().sendKeys(passphrase).perform();
}

await this.driverHelper.waitAndClick(UserPreferences.ADD_SSH_KEYS_BUTTON);
await this.driverHelper.waitVisibility(UserPreferences.GIT_SSH_KEY_NAME);
Logger.info('SSH keys have been added');
Expand Down
126 changes: 122 additions & 4 deletions tests/e2e/specs/factory/SshUrlNoOauthPatFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ViewSection } from 'monaco-page-objects';
import { ActivityBar, ContextMenu, Key, Locators, NewScmView, SingleScmProvider, ViewControl, ViewSection } from 'monaco-page-objects';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { e2eContainer } from '../../configs/inversify.config';
Expand All @@ -24,23 +24,45 @@ import { UserPreferences } from '../../pageobjects/dashboard/UserPreferences';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { Logger } from '../../utils/Logger';
import { DriverHelper } from '../../utils/DriverHelper';
import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader';
import { ViewsMoreActionsButton } from '../../pageobjects/ide/ViewsMoreActionsButton';
import { SourceControlView } from '../../pageobjects/ide/SourceControlView';

suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences);
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader);
const viewsMoreActionsButton: ViewsMoreActionsButton = e2eContainer.get(CLASSES.ViewsMoreActionsButton);
const sourceControlView: SourceControlView = e2eContainer.get(CLASSES.SourceControlView);
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;

const factoryUrl: string =
FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL ||
'ssh://[email protected]/~admin/private-bb-repo.git';
const privateSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY;
const publicSshKey: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY;
const sshPassphrase: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_KEY_PASSPHRASE;
const privateSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PRIVATE_KEY_PATH;
const publicSshKeyPath: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_SSH_PUBLIC_KEY_PATH;

let projectSection: ViewSection;
let scmProvider: SingleScmProvider;
let scmContextMenu: ContextMenu;
let viewsActionsButton: boolean;
// test specific data
const timeToRefresh: number = 1500;
const changesToCommit: string = 'Commit ' + new Date().getTime().toString();
const fileToChange: string = 'Date.txt';
const refreshButtonLabel: string = 'Refresh';
const pushItemLabel: string = 'Push';
let testRepoProjectName: string;

async function deleteSshKeys(): Promise<void> {
Logger.debug('Deleting SSH keys if they are present');
Expand All @@ -62,7 +84,7 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
// use environment variables if available, otherwise fall back to file paths
if (privateSshKey && publicSshKey) {
Logger.info('Using SSH keys from environment variables');
await userPreferences.addSshKeysFromStrings(privateSshKey, publicSshKey);
await userPreferences.addSshKeysFromStrings(privateSshKey, publicSshKey, sshPassphrase);
} else {
Logger.info('Using SSH keys from file paths');
await userPreferences.addSshKeysFromFiles(privateSshKeyPath, publicSshKeyPath);
Expand All @@ -87,19 +109,115 @@ suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONM
.undefined;
});
test('Accept the project as a trusted one', async function (): Promise<void> {
await projectAndFileTests.performTrustAuthorDialog();
await projectAndFileTests.performTrustDialogs();
// it needs to wait here for the Trust dialogs to be closed and the Editor to be ready
await driverHelper.wait(5000);
});
test('Check the project files was imported', async function (): Promise<void> {
expect(
await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME),
'Project files were not imported'
).not.undefined;
testRepoProjectName = StringUtil.getProjectNameFromGitUrl(factoryUrl);
});

test('Make changes to the file', async function (): Promise<void> {
Logger.debug(`projectSection.openItem: "${fileToChange}"`);
await projectSection.openItem(testRepoProjectName, fileToChange);
await driverHelper.waitVisibility(webCheCodeLocators.Editor.inputArea);
await driverHelper.getDriver().findElement(webCheCodeLocators.Editor.inputArea).click();
await driverHelper.wait(1000);

Logger.debug('Clearing the editor with Ctrl+A');
await driverHelper.getDriver().actions().keyDown(Key.CONTROL).sendKeys('a').keyUp(Key.CONTROL).perform();
await driverHelper.wait(1000);
Logger.debug('Deleting selected text');
await driverHelper.getDriver().actions().sendKeys(Key.DELETE).perform();
await driverHelper.wait(1000);
Logger.debug(`Entering text: "${changesToCommit}"`);
await driverHelper.getDriver().actions().sendKeys(changesToCommit).perform();
});

test('Open a source control manager', async function (): Promise<void> {
const viewSourceControl: string = 'Source Control';
const sourceControl: ViewControl = (await new ActivityBar().getViewControl(viewSourceControl)) as ViewControl;
Logger.debug(`sourceControl.openView: "${viewSourceControl}"`);
await sourceControl.openView();
const scmView: NewScmView = new NewScmView();
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
let rest: SingleScmProvider[];
[scmProvider, ...rest] = await scmView.getProviders();
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
});

test('Check if the changes are displayed in the source control manager', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
// wait while changes counter will be refreshed
await driverHelper.wait(timeToRefresh);
const changes: number = await scmProvider.getChangeCount();
Logger.debug(`scmProvider.getChangeCount: number of changes is "${changes}"`);
expect(changes).eql(1);
});

test('Stage the changes', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
viewsActionsButton = await viewsMoreActionsButton.viewsAndMoreActionsButtonIsVisible();
if (viewsActionsButton) {
await viewsMoreActionsButton.closeSourceControlGraph();
}
scmContextMenu = await scmProvider.openMoreActions();
await driverHelper.waitVisibility(webCheCodeLocators.ContextMenu.contextView);
Logger.debug('scmContextMenu.select: "Changes" -> "Stage All Changes"');
await scmContextMenu.select('Changes', 'Stage All Changes');
});

test('Commit the changes', async function (): Promise<void> {
Logger.info(`ScmView inputField locator: "${(webCheCodeLocators.ScmView as any).scmEditor}"`);
Logger.debug('Click on the Scm Editor');
await driverHelper
.getDriver()
.findElement((webCheCodeLocators.ScmView as any).scmEditor)
.click();
await sourceControlView.typeCommitMessage(changesToCommit);
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
// wait while changes counter will be refreshed
await driverHelper.wait(timeToRefresh);
const changes: number = await scmProvider.getChangeCount();
Logger.debug(`scmProvider.getChangeCount: number of changes is "${changes}"`);
expect(changes).eql(0);
});

test('Push the changes and check if the changes were pushed', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.Notification.action);
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
Logger.debug('scmProvider.openMoreActions');
scmContextMenu = await scmProvider.openMoreActions();
await driverHelper.waitVisibility(webCheCodeLocators.ContextMenu.itemConstructor(pushItemLabel));
Logger.debug(`scmContextMenu.select: "${pushItemLabel}"`);
await scmContextMenu.select(pushItemLabel);

await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
const isCommitButtonDisabled: string = await driverHelper.waitAndGetElementAttribute(
webCheCodeLocators.Notification.action,
'aria-disabled'
);
expect(isCommitButtonDisabled).to.equal('true');
});

suiteTeardown('Delete SSH keys', async function (): Promise<void> {
await dashboard.openDashboard();
await deleteSshKeys();
});
suiteTeardown('Stop and delete the workspace by APII', async function (): Promise<void> {
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
await browserTabsUtil.closeAllTabsExceptCurrent();
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});
Expand Down