Skip to content

Commit

Permalink
[Test] Add 'Restricted Mode' button handler to switch on 'Trust Mode'…
Browse files Browse the repository at this point in the history
… in IDE in E2E tests (#23361)

* Add new pageobject to editor
* Update 'ProjectAndFileTests' object
* Update files according to modify 'performTrustAuthorDialog' method
* Fix up 'RecommendedExtensions'
* Fix up 'CheCodeLocatorLoader' pageobjeect
  • Loading branch information
artaleks9 authored Feb 24, 2025
1 parent 23b3436 commit 740ef2d
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 106 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Automated lint checking and code format performs with ESLint and Prettier tools
pre-commit hook.
Full set of rules can be found:

- [.eslintrc](.eslintrc.js)
- [.prettierrc](.prettierrc.json)
- [.eslintrc](.eslintrc.js)
- [.prettierrc](.prettierrc.json)

### Preferable code style

Expand Down
74 changes: 37 additions & 37 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

## Requirements

- node 16.x
- "Chrome" browser 114.x or later
- deployed Che 7 with accessible URL
- node 16.x
- "Chrome" browser 114.x or later
- deployed Che 7 with accessible URL

## Before launch

**Perform commands:**

- `export TS_SELENIUM_BASE_URL=<Che7 URL>`
- `npm ci`
- `export TS_SELENIUM_BASE_URL=<Che7 URL>`
- `npm ci`

Note: If there is any modifications in package.json, manually execute the `npm install` to update the package-lock.json. So that errors can be avoided while executing npm ci

## Default launch

- Provide connection credentials:
- `export TS_SELENIUM_OCP_USERNAME=<username>`
- `export TS_SELENIUM_OCP_PASSWORD=<password>`
- `npm run test`
- Provide connection credentials:
- `export TS_SELENIUM_OCP_USERNAME=<username>`
- `export TS_SELENIUM_OCP_PASSWORD=<password>`
- `npm run test`

## Custom launch

- Use environment variables which described in the "constants" folder
- Use environment variables for setting timeouts if needed. You can see the list in **`'TimeoutConstants.ts'`**. You can see the list of those variables and their value if you set the `'TS_SELENIUM_PRINT_TIMEOUT_VARIABLES = true'`
- To test one specification export file name as `export USERSTORY=<spec-file-name-without-extension> && npm run test` (example: `-e USERSTORY=Quarkus`)
- To run test without Selenium WebDriver (API tests etc.) use `export USERSTORY=<spec-file-name-without-extension> && npm run driver-less-test` (example: `-e USERSTORY=CloneGitRepoAPI`)
- This project support application testing deployed on Kubernetes or Openshift platform. Openshift is default value. To switch into Kubernetes, please, use `TS_PLATFORM=kubernetes` environmental variable and `TS_SELENIUM_K8S_PASSWORD`, `TS_SELENIUM_K8S_USERNAME` to provide credentials. The sample of test command in this case:
- Use environment variables which described in the "constants" folder
- Use environment variables for setting timeouts if needed. You can see the list in **`'TimeoutConstants.ts'`**. You can see the list of those variables and their value if you set the `'TS_SELENIUM_PRINT_TIMEOUT_VARIABLES = true'`
- To test one specification export file name as `export USERSTORY=<spec-file-name-without-extension> && npm run test` (example: `-e USERSTORY=Quarkus`)
- To run test without Selenium WebDriver (API tests etc.) use `export USERSTORY=<spec-file-name-without-extension> && npm run driver-less-test` (example: `-e USERSTORY=CloneGitRepoAPI`)
- This project support application testing deployed on Kubernetes or Openshift platform. Openshift is default value. To switch into Kubernetes, please, use `TS_PLATFORM=kubernetes` environmental variable and `TS_SELENIUM_K8S_PASSWORD`, `TS_SELENIUM_K8S_USERNAME` to provide credentials. The sample of test command in this case:
```
export TS_PLATFORM=kubernetes && \
export TS_SELENIUM_K8S_USERNAME=<username> && \
Expand All @@ -37,21 +37,21 @@ Note: If there is any modifications in package.json, manually execute the `npm i
npm run test
```
Also, environmental variables can be set in files in "constants" folder.
- Local test results can be represented with Allure reporter `npm run open-allure-dasboard`
- Local test results can be represented with Allure reporter `npm run open-allure-dasboard`
## Docker launch
- open terminal and go to the "e2e" directory
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
- run command `"npm run test-docker"`
- open terminal and go to the "e2e" directory
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
- run command `"npm run test-docker"`
## Docker launch with changed tests
**For launching tests with local changes perform next steps:**
- open terminal and go to the "e2e" directory
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
- run command `"npm run test-docker-mount-e2e"`
- open terminal and go to the "e2e" directory
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
- run command `"npm run test-docker-mount-e2e"`
## Debug docker launch
Expand All @@ -62,27 +62,27 @@ The `'eclipse/che-e2e'` docker image has VNC server installed inside. For connec
**The easiest way to do that is to perform steps which are described in the "Docker launch" paragraph.
For running tests without docker, please perform next steps:**
- Deploy Che on Kubernetes infrastructure by using 'Minikube' and 'Chectl' <https://github.com/eclipse-che/che-server/blob/HEAD/deploy/kubernetes/README.md>
- Create workspace by using 'Chectl' and devfile
- link to 'Chectl' manual <https://github.com/che-incubator/chectl#chectl-workspacestart>
- link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** )
<https://gist.githubusercontent.com/Ohrimenko1988/93f5426f4ebc1705c55feb8ff0396a49/raw/cbea89ad145ba33ed34a151a12c50f045f9f3b78/yaml-ls-bug.yaml>
- Provide the **`'TS_SELENIUM_BASE_URL'`** environment variable as described above
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
- perform command **`export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`**
- Deploy Che on Kubernetes infrastructure by using 'Minikube' and 'Chectl' <https://github.com/eclipse-che/che-server/blob/HEAD/deploy/kubernetes/README.md>
- Create workspace by using 'Chectl' and devfile
- link to 'Chectl' manual <https://github.com/che-incubator/chectl#chectl-workspacestart>
- link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** )
<https://gist.githubusercontent.com/Ohrimenko1988/93f5426f4ebc1705c55feb8ff0396a49/raw/cbea89ad145ba33ed34a151a12c50f045f9f3b78/yaml-ls-bug.yaml>
- Provide the **`'TS_SELENIUM_BASE_URL'`** environment variable as described above
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
- perform command **`export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`**
## Launching the DevWorkspaceHappyPath spec file using Che with oauth authentication
**Setup next environment variables:**
- export TS_SELENIUM_BASE_URL=\<Che-URL\>
- export TS_SELENIUM_OCP_USERNAME=\<cluster-username\>
- export TS_SELENIUM_OCP_PASSWORD=\<cluster-password\>
- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true"
- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\<login-provide-title\>
- export TS_SELENIUM_DEVWORKSPACE_URL=\<devworkspace-url\>
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
- export TS_SELENIUM_BASE_URL=\<Che-URL\>
- export TS_SELENIUM_OCP_USERNAME=\<cluster-username\>
- export TS_SELENIUM_OCP_PASSWORD=\<cluster-password\>
- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true"
- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\<login-provide-title\>
- export TS_SELENIUM_DEVWORKSPACE_URL=\<devworkspace-url\>
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
**Execute the npm command:**
- perform command `export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`
- perform command `export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`
2 changes: 2 additions & 0 deletions tests/e2e/configs/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { UserPreferences } from '../pageobjects/dashboard/UserPreferences';
import { WebTerminalPage } from '../pageobjects/webterminal/WebTerminalPage';
import { TrustAuthorPopup } from '../pageobjects/dashboard/TrustAuthorPopup';
import { ViewsMoreActionsButton } from '../pageobjects/ide/ViewsMoreActionsButton';
import { RestrictedModeButton } from '../pageobjects/ide/RestrictedModeButton';

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

Expand Down Expand Up @@ -95,6 +96,7 @@ e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoade
e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader);
e2eContainer.bind<TrustAuthorPopup>(CLASSES.TrustAuthorPopup).to(TrustAuthorPopup);
e2eContainer.bind<ViewsMoreActionsButton>(CLASSES.ViewsMoreActionsButton).to(ViewsMoreActionsButton);
e2eContainer.bind<RestrictedModeButton>(CLASSES.RestrictedModeButton).to(RestrictedModeButton);

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 @@ -52,7 +52,8 @@ const CLASSES: any = {
WebTerminalPage: 'WebTerminalPage',
RevokeOauthPage: 'RevokeOauthPage',
TrustAuthorPopup: 'TrustAuthorPopup',
ViewsMoreActionsButton: 'ViewsMoreActionsButton'
ViewsMoreActionsButton: 'ViewsMoreActionsButton',
RestrictedModeButton: 'RestrictedModeButton'
};

const EXTERNAL_CLASSES: any = {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './pageobjects/dashboard/Workspaces';
export * from './pageobjects/git-providers/OauthPage';
export * from './pageobjects/ide/CheCodeLocatorLoader';
export * from './pageobjects/ide/ViewsMoreActionsButton';
export * from './pageobjects/ide/RestrictedModeButton';
export * from './pageobjects/login/interfaces/ICheLoginPage';
export * from './pageobjects/login/interfaces/IOcpLoginPage';
export * from './pageobjects/login/kubernetes/DexLoginPage';
Expand Down
6 changes: 1 addition & 5 deletions tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** *******************************************************************
* copyright (c) 2019 Red Hat, Inc.
* copyright (c) 2019-2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -55,10 +55,6 @@ export class CheCodeLocatorLoader extends LocatorLoader {
TreeItem: {
projectFolderItem: By.className('pane-header expanded')
},
ScmView: {
manageWorkspaceTrust: By.xpath('.//a[@class="monaco-button monaco-text-button"]'),
modifiedFile: By.xpath('//div[@class="monaco-list-row" and contains(@aria-label, "Modified")]')
},
Workbench: {
workspaceTrustButton: By.xpath('//a[@role="button" and text()="Trust"]')
}
Expand Down
37 changes: 37 additions & 0 deletions tests/e2e/pageobjects/ide/RestrictedModeButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/** *******************************************************************
* copyright (c) 2025 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';

@injectable()
export class RestrictedModeButton {
private static readonly RESTRICTED_MODE_BUTTON: By = By.id('status.workspaceTrust');

constructor(
@inject(CLASSES.DriverHelper)
readonly driverHelper: DriverHelper
) {}

async clickOnRestrictedModeButton(): Promise<void> {
Logger.debug();

await this.driverHelper.waitAndClick(RestrictedModeButton.RESTRICTED_MODE_BUTTON);
}

async isRestrictedModeButtonDisappearance(): Promise<void> {
Logger.debug();

await this.driverHelper.waitDisappearance(RestrictedModeButton.RESTRICTED_MODE_BUTTON);
}
}
26 changes: 7 additions & 19 deletions tests/e2e/specs/dashboard-samples/RecommendedExtensions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** *******************************************************************
* copyright (c) 2019-2023 Red Hat, Inc.
* copyright (c) 2019-2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -153,17 +153,10 @@ for (const sample of samples) {
});

test(`Get recommended extensions list from ${extensionsListFileName}`, async function (): Promise<void> {
// sometimes the Trust Dialog does not appear as expected - as result we need to execute "projectAndFileTests.performManageWorkspaceTrustBox()" method. In this case.
try {
await (
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
)?.select();
} catch (err) {
await projectAndFileTests.performManageWorkspaceTrustBox();
await (
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
)?.select();
}
await (
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
)?.select();

await (
await projectAndFileTests.getProjectTreeItem(projectSection, extensionsListFileName, vsCodeFolderItemLevel + 1)
)?.select();
Expand All @@ -185,13 +178,8 @@ for (const sample of samples) {

test('Open "Extensions" view section', async function (): Promise<void> {
Logger.debug('ActivityBar().getViewControl("Extensions"))?.openView(): open Extensions view.');
// sometimes the Trust Dialog does not appear as expected - as result we need to execute "projectAndFileTests.performManageWorkspaceTrustBox()" method. In this case.
try {
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
} catch (err) {
await projectAndFileTests.performManageWorkspaceTrustBox();
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
}

extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
expect(extensionsView, 'Can`t find Extension section').not.undefined;
});

Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/specs/factory/Factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ suite(
const scmView: NewScmView = new NewScmView();
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
[scmProvider, ...rest] = await scmView.getProviders();
if (scmProvider === undefined) {
await projectAndFileTests.performManageWorkspaceTrustBox();
[scmProvider, ...rest] = await scmView.getProviders();
}
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
});

Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/specs/factory/NoSetupRepoFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ suite(
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
let rest: SingleScmProvider[];
[scmProvider, ...rest] = await scmView.getProviders();
if (scmProvider === undefined) {
await projectAndFileTests.performManageWorkspaceTrustBox();
[scmProvider, ...rest] = await scmView.getProviders();
}
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
});

Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/specs/factory/RefusedOAuthFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ suite(
const scmView: NewScmView = new NewScmView();
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
[scmProvider, ...rest] = await scmView.getProviders();
if (scmProvider === undefined) {
await projectAndFileTests.performManageWorkspaceTrustBox();
[scmProvider, ...rest] = await scmView.getProviders();
}
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
});

Expand Down
Loading

0 comments on commit 740ef2d

Please sign in to comment.