Skip to content

Commit 740ef2d

Browse files
authored
[Test] Add 'Restricted Mode' button handler to switch on 'Trust Mode' 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
1 parent 23b3436 commit 740ef2d

File tree

12 files changed

+118
-106
lines changed

12 files changed

+118
-106
lines changed

tests/e2e/CODE_STYLE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Automated lint checking and code format performs with ESLint and Prettier tools
3333
pre-commit hook.
3434
Full set of rules can be found:
3535

36-
- [.eslintrc](.eslintrc.js)
37-
- [.prettierrc](.prettierrc.json)
36+
- [.eslintrc](.eslintrc.js)
37+
- [.prettierrc](.prettierrc.json)
3838

3939
### Preferable code style
4040

tests/e2e/README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
## Requirements
44

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

99
## Before launch
1010

1111
**Perform commands:**
1212

13-
- `export TS_SELENIUM_BASE_URL=<Che7 URL>`
14-
- `npm ci`
13+
- `export TS_SELENIUM_BASE_URL=<Che7 URL>`
14+
- `npm ci`
1515

1616
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
1717

1818
## Default launch
1919

20-
- Provide connection credentials:
21-
- `export TS_SELENIUM_OCP_USERNAME=<username>`
22-
- `export TS_SELENIUM_OCP_PASSWORD=<password>`
23-
- `npm run test`
20+
- Provide connection credentials:
21+
- `export TS_SELENIUM_OCP_USERNAME=<username>`
22+
- `export TS_SELENIUM_OCP_PASSWORD=<password>`
23+
- `npm run test`
2424

2525
## Custom launch
2626

27-
- Use environment variables which described in the "constants" folder
28-
- 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'`
29-
- To test one specification export file name as `export USERSTORY=<spec-file-name-without-extension> && npm run test` (example: `-e USERSTORY=Quarkus`)
30-
- 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`)
31-
- 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:
27+
- Use environment variables which described in the "constants" folder
28+
- 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'`
29+
- To test one specification export file name as `export USERSTORY=<spec-file-name-without-extension> && npm run test` (example: `-e USERSTORY=Quarkus`)
30+
- 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`)
31+
- 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:
3232
```
3333
export TS_PLATFORM=kubernetes && \
3434
export TS_SELENIUM_K8S_USERNAME=<username> && \
@@ -37,21 +37,21 @@ Note: If there is any modifications in package.json, manually execute the `npm i
3737
npm run test
3838
```
3939
Also, environmental variables can be set in files in "constants" folder.
40-
- Local test results can be represented with Allure reporter `npm run open-allure-dasboard`
40+
- Local test results can be represented with Allure reporter `npm run open-allure-dasboard`
4141
4242
## Docker launch
4343
44-
- open terminal and go to the "e2e" directory
45-
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
46-
- run command `"npm run test-docker"`
44+
- open terminal and go to the "e2e" directory
45+
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
46+
- run command `"npm run test-docker"`
4747
4848
## Docker launch with changed tests
4949
5050
**For launching tests with local changes perform next steps:**
5151
52-
- open terminal and go to the "e2e" directory
53-
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
54-
- run command `"npm run test-docker-mount-e2e"`
52+
- open terminal and go to the "e2e" directory
53+
- export the `"TS_SELENIUM_BASE_URL"` variable with "Che" url
54+
- run command `"npm run test-docker-mount-e2e"`
5555
5656
## Debug docker launch
5757
@@ -62,27 +62,27 @@ The `'eclipse/che-e2e'` docker image has VNC server installed inside. For connec
6262
**The easiest way to do that is to perform steps which are described in the "Docker launch" paragraph.
6363
For running tests without docker, please perform next steps:**
6464
65-
- Deploy Che on Kubernetes infrastructure by using 'Minikube' and 'Chectl' <https://github.com/eclipse-che/che-server/blob/HEAD/deploy/kubernetes/README.md>
66-
- Create workspace by using 'Chectl' and devfile
67-
- link to 'Chectl' manual <https://github.com/che-incubator/chectl#chectl-workspacestart>
68-
- link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** )
69-
<https://gist.githubusercontent.com/Ohrimenko1988/93f5426f4ebc1705c55feb8ff0396a49/raw/cbea89ad145ba33ed34a151a12c50f045f9f3b78/yaml-ls-bug.yaml>
70-
- Provide the **`'TS_SELENIUM_BASE_URL'`** environment variable as described above
71-
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
72-
- perform command **`export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`**
65+
- Deploy Che on Kubernetes infrastructure by using 'Minikube' and 'Chectl' <https://github.com/eclipse-che/che-server/blob/HEAD/deploy/kubernetes/README.md>
66+
- Create workspace by using 'Chectl' and devfile
67+
- link to 'Chectl' manual <https://github.com/che-incubator/chectl#chectl-workspacestart>
68+
- link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** )
69+
<https://gist.githubusercontent.com/Ohrimenko1988/93f5426f4ebc1705c55feb8ff0396a49/raw/cbea89ad145ba33ed34a151a12c50f045f9f3b78/yaml-ls-bug.yaml>
70+
- Provide the **`'TS_SELENIUM_BASE_URL'`** environment variable as described above
71+
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
72+
- perform command **`export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`**
7373
7474
## Launching the DevWorkspaceHappyPath spec file using Che with oauth authentication
7575
7676
**Setup next environment variables:**
7777
78-
- export TS_SELENIUM_BASE_URL=\<Che-URL\>
79-
- export TS_SELENIUM_OCP_USERNAME=\<cluster-username\>
80-
- export TS_SELENIUM_OCP_PASSWORD=\<cluster-password\>
81-
- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true"
82-
- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\<login-provide-title\>
83-
- export TS_SELENIUM_DEVWORKSPACE_URL=\<devworkspace-url\>
84-
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
78+
- export TS_SELENIUM_BASE_URL=\<Che-URL\>
79+
- export TS_SELENIUM_OCP_USERNAME=\<cluster-username\>
80+
- export TS_SELENIUM_OCP_PASSWORD=\<cluster-password\>
81+
- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true"
82+
- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\<login-provide-title\>
83+
- export TS_SELENIUM_DEVWORKSPACE_URL=\<devworkspace-url\>
84+
- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts)
8585
8686
**Execute the npm command:**
8787
88-
- perform command `export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`
88+
- perform command `export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles`

tests/e2e/configs/inversify.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { UserPreferences } from '../pageobjects/dashboard/UserPreferences';
5555
import { WebTerminalPage } from '../pageobjects/webterminal/WebTerminalPage';
5656
import { TrustAuthorPopup } from '../pageobjects/dashboard/TrustAuthorPopup';
5757
import { ViewsMoreActionsButton } from '../pageobjects/ide/ViewsMoreActionsButton';
58+
import { RestrictedModeButton } from '../pageobjects/ide/RestrictedModeButton';
5859

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

@@ -95,6 +96,7 @@ e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoade
9596
e2eContainer.bind<LocatorLoader>(EXTERNAL_CLASSES.LocatorLoader).to(LocatorLoader);
9697
e2eContainer.bind<TrustAuthorPopup>(CLASSES.TrustAuthorPopup).to(TrustAuthorPopup);
9798
e2eContainer.bind<ViewsMoreActionsButton>(CLASSES.ViewsMoreActionsButton).to(ViewsMoreActionsButton);
99+
e2eContainer.bind<RestrictedModeButton>(CLASSES.RestrictedModeButton).to(RestrictedModeButton);
98100

99101
if (BASE_TEST_CONSTANTS.TS_PLATFORM === Platform.OPENSHIFT) {
100102
if (OAUTH_CONSTANTS.TS_SELENIUM_VALUE_OPENSHIFT_OAUTH) {

tests/e2e/configs/inversify.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ const CLASSES: any = {
5252
WebTerminalPage: 'WebTerminalPage',
5353
RevokeOauthPage: 'RevokeOauthPage',
5454
TrustAuthorPopup: 'TrustAuthorPopup',
55-
ViewsMoreActionsButton: 'ViewsMoreActionsButton'
55+
ViewsMoreActionsButton: 'ViewsMoreActionsButton',
56+
RestrictedModeButton: 'RestrictedModeButton'
5657
};
5758

5859
const EXTERNAL_CLASSES: any = {

tests/e2e/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export * from './pageobjects/dashboard/Workspaces';
3131
export * from './pageobjects/git-providers/OauthPage';
3232
export * from './pageobjects/ide/CheCodeLocatorLoader';
3333
export * from './pageobjects/ide/ViewsMoreActionsButton';
34+
export * from './pageobjects/ide/RestrictedModeButton';
3435
export * from './pageobjects/login/interfaces/ICheLoginPage';
3536
export * from './pageobjects/login/interfaces/IOcpLoginPage';
3637
export * from './pageobjects/login/kubernetes/DexLoginPage';

tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** *******************************************************************
2-
* copyright (c) 2019 Red Hat, Inc.
2+
* copyright (c) 2019-2025 Red Hat, Inc.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -55,10 +55,6 @@ export class CheCodeLocatorLoader extends LocatorLoader {
5555
TreeItem: {
5656
projectFolderItem: By.className('pane-header expanded')
5757
},
58-
ScmView: {
59-
manageWorkspaceTrust: By.xpath('.//a[@class="monaco-button monaco-text-button"]'),
60-
modifiedFile: By.xpath('//div[@class="monaco-list-row" and contains(@aria-label, "Modified")]')
61-
},
6258
Workbench: {
6359
workspaceTrustButton: By.xpath('//a[@role="button" and text()="Trust"]')
6460
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 { By } from 'selenium-webdriver';
14+
import { DriverHelper } from '../../utils/DriverHelper';
15+
import { Logger } from '../../utils/Logger';
16+
17+
@injectable()
18+
export class RestrictedModeButton {
19+
private static readonly RESTRICTED_MODE_BUTTON: By = By.id('status.workspaceTrust');
20+
21+
constructor(
22+
@inject(CLASSES.DriverHelper)
23+
readonly driverHelper: DriverHelper
24+
) {}
25+
26+
async clickOnRestrictedModeButton(): Promise<void> {
27+
Logger.debug();
28+
29+
await this.driverHelper.waitAndClick(RestrictedModeButton.RESTRICTED_MODE_BUTTON);
30+
}
31+
32+
async isRestrictedModeButtonDisappearance(): Promise<void> {
33+
Logger.debug();
34+
35+
await this.driverHelper.waitDisappearance(RestrictedModeButton.RESTRICTED_MODE_BUTTON);
36+
}
37+
}

tests/e2e/specs/dashboard-samples/RecommendedExtensions.spec.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** *******************************************************************
2-
* copyright (c) 2019-2023 Red Hat, Inc.
2+
* copyright (c) 2019-2025 Red Hat, Inc.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -153,17 +153,10 @@ for (const sample of samples) {
153153
});
154154

155155
test(`Get recommended extensions list from ${extensionsListFileName}`, async function (): Promise<void> {
156-
// sometimes the Trust Dialog does not appear as expected - as result we need to execute "projectAndFileTests.performManageWorkspaceTrustBox()" method. In this case.
157-
try {
158-
await (
159-
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
160-
)?.select();
161-
} catch (err) {
162-
await projectAndFileTests.performManageWorkspaceTrustBox();
163-
await (
164-
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
165-
)?.select();
166-
}
156+
await (
157+
await projectAndFileTests.getProjectTreeItem(projectSection, pathToExtensionsListFileName, vsCodeFolderItemLevel)
158+
)?.select();
159+
167160
await (
168161
await projectAndFileTests.getProjectTreeItem(projectSection, extensionsListFileName, vsCodeFolderItemLevel + 1)
169162
)?.select();
@@ -185,13 +178,8 @@ for (const sample of samples) {
185178

186179
test('Open "Extensions" view section', async function (): Promise<void> {
187180
Logger.debug('ActivityBar().getViewControl("Extensions"))?.openView(): open Extensions view.');
188-
// sometimes the Trust Dialog does not appear as expected - as result we need to execute "projectAndFileTests.performManageWorkspaceTrustBox()" method. In this case.
189-
try {
190-
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
191-
} catch (err) {
192-
await projectAndFileTests.performManageWorkspaceTrustBox();
193-
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
194-
}
181+
182+
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
195183
expect(extensionsView, 'Can`t find Extension section').not.undefined;
196184
});
197185

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ suite(
150150
const scmView: NewScmView = new NewScmView();
151151
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
152152
[scmProvider, ...rest] = await scmView.getProviders();
153-
if (scmProvider === undefined) {
154-
await projectAndFileTests.performManageWorkspaceTrustBox();
155-
[scmProvider, ...rest] = await scmView.getProviders();
156-
}
157153
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
158154
});
159155

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ suite(
148148
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
149149
let rest: SingleScmProvider[];
150150
[scmProvider, ...rest] = await scmView.getProviders();
151-
if (scmProvider === undefined) {
152-
await projectAndFileTests.performManageWorkspaceTrustBox();
153-
[scmProvider, ...rest] = await scmView.getProviders();
154-
}
155151
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
156152
});
157153

0 commit comments

Comments
 (0)