From 1b2592f353212a6d99d13b5fd6b9c09c00702103 Mon Sep 17 00:00:00 2001 From: Shmaraiev Oleksandr Date: Fri, 31 Jan 2025 20:05:21 +0200 Subject: [PATCH] [Test] Update 'Factory' E2E test (#23311) * Update 'Factory' e2e test * Add new constants * Add new method to Dashboard page object * Update files according to 'prettier' command --- tests/e2e/CODE_STYLE.md | 4 +- tests/e2e/README.md | 74 ++++++++++---------- tests/e2e/constants/BASE_TEST_CONSTANTS.ts | 15 ++++ tests/e2e/pageobjects/dashboard/Dashboard.ts | 7 ++ tests/e2e/specs/factory/Factory.spec.ts | 25 ++++--- 5 files changed, 78 insertions(+), 47 deletions(-) diff --git a/tests/e2e/CODE_STYLE.md b/tests/e2e/CODE_STYLE.md index 8508cbfd3be..04d6f48f2d9 100644 --- a/tests/e2e/CODE_STYLE.md +++ b/tests/e2e/CODE_STYLE.md @@ -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 diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 2d8679b1df8..754798e0639 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -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=` -- `npm ci` +- `export TS_SELENIUM_BASE_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=` - - `export TS_SELENIUM_OCP_PASSWORD=` - - `npm run test` +- Provide connection credentials: + - `export TS_SELENIUM_OCP_USERNAME=` + - `export TS_SELENIUM_OCP_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= && npm run test` (example: `-e USERSTORY=Quarkus`) -- To run test without Selenium WebDriver (API tests etc.) use `export USERSTORY= && 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= && npm run test` (example: `-e USERSTORY=Quarkus`) +- To run test without Selenium WebDriver (API tests etc.) use `export USERSTORY= && 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= && \ @@ -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 @@ -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' -- Create workspace by using 'Chectl' and devfile - - link to 'Chectl' manual - - link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** ) - -- 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' +- Create workspace by using 'Chectl' and devfile + - link to 'Chectl' manual + - link to devfile ( **`For successfull test passing, exactly provided devfile should be used`** ) + +- 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=\ -- export TS_SELENIUM_OCP_USERNAME=\ -- export TS_SELENIUM_OCP_PASSWORD=\ -- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true" -- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\ -- export TS_SELENIUM_DEVWORKSPACE_URL=\ -- export TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME=EmptyWorkspace (default value, see BASE_TEST_CONSTANTS.ts) +- export TS_SELENIUM_BASE_URL=\ +- export TS_SELENIUM_OCP_USERNAME=\ +- export TS_SELENIUM_OCP_PASSWORD=\ +- export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH="true" +- export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=\ +- export TS_SELENIUM_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` diff --git a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts index 900ea1efe0d..6959b8d3642 100644 --- a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts @@ -15,6 +15,8 @@ export enum Platform { export const BASE_TEST_CONSTANTS: { OCP_INFRA: string; DELETE_WORKSPACE_ON_FAILED_TEST: boolean; + DELETE_WORKSPACE_ON_SUCCESSFUL_TEST: boolean; + SELECT_OPENING_EXISTING_WORKSPACE_INSTEAD_OF_CREATION_NEW: boolean; IS_CLUSTER_DISCONNECTED: () => boolean; IS_PRODUCT_DOCUMENTATION_RELEASED: any; OCP_VERSION: string; @@ -130,6 +132,19 @@ export const BASE_TEST_CONSTANTS: { */ DELETE_WORKSPACE_ON_FAILED_TEST: process.env.DELETE_WORKSPACE_ON_FAILED_TEST === 'true', + /** + * stop and remove workspace if a test is successful. + * true by default. + */ + DELETE_WORKSPACE_ON_SUCCESSFUL_TEST: process.env.DELETE_WORKSPACE_ON_SUCCESSFUL_TEST !== 'false', + + /** + * select opening an existing workspace instead of creating a new one, if a duplicate workspace is created from the factory or sample list. + * this option is false by default. + */ + SELECT_OPENING_EXISTING_WORKSPACE_INSTEAD_OF_CREATION_NEW: + process.env.SELECT_OPENING_EXISTING_WORKSPACE_INSTEAD_OF_CREATION_NEW === 'true', + /** * constant, which prolong timeout constants for local debug. */ diff --git a/tests/e2e/pageobjects/dashboard/Dashboard.ts b/tests/e2e/pageobjects/dashboard/Dashboard.ts index 3bd48875b3f..abb4ae990aa 100644 --- a/tests/e2e/pageobjects/dashboard/Dashboard.ts +++ b/tests/e2e/pageobjects/dashboard/Dashboard.ts @@ -39,6 +39,7 @@ export class Dashboard { username: 'username' }; private static readonly CONTINUE_WITH_DEFAULT_DEVFILE_BUTTON: By = By.xpath('//button[text()="Continue with default devfile"]'); + private static readonly OPEN_EXISTING_WORKSPACE_LINK: By = By.xpath('//button[text()="Open the existing workspace"]'); constructor( @inject(CLASSES.DriverHelper) @@ -176,6 +177,12 @@ export class Dashboard { await this.driverHelper.waitAndClick(Dashboard.CREATE_NEW_WORKSPACE_LINK, timeout); } + async clickOpenExistingWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise { + Logger.debug(); + + await this.driverHelper.waitAndClick(Dashboard.OPEN_EXISTING_WORKSPACE_LINK, timeout); + } + async logout(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise { Logger.debug(); diff --git a/tests/e2e/specs/factory/Factory.spec.ts b/tests/e2e/specs/factory/Factory.spec.ts index dd9546f00d9..65a9205f606 100644 --- a/tests/e2e/specs/factory/Factory.spec.ts +++ b/tests/e2e/specs/factory/Factory.spec.ts @@ -88,6 +88,13 @@ suite( }); } + if (BASE_TEST_CONSTANTS.SELECT_OPENING_EXISTING_WORKSPACE_INSTEAD_OF_CREATION_NEW) { + test('Select opening an existing workspace instead of creating a new one', async function (): Promise { + await dashboard.waitExistingWorkspaceFoundAlert(); + await dashboard.clickOpenExistingWorkspaceButton(); + }); + } + test('Obtain workspace name from workspace loader page', async function (): Promise { await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); }); @@ -209,14 +216,16 @@ suite( await browserTabsUtil.closeAllTabsExceptCurrent(); }); - suiteTeardown('Stop and delete the workspace by API', async function (): Promise { - // to avoid a possible creating workspace which is not appeared on Dashboard yet. TODO: implement a better solution. - await driverHelper.wait(30000); - await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); - }); + if (BASE_TEST_CONSTANTS.DELETE_WORKSPACE_ON_SUCCESSFUL_TEST) { + suiteTeardown('Stop and delete the workspace by API', async function (): Promise { + // to avoid a possible creating workspace which is not appeared on Dashboard yet. TODO: implement a better solution. + await driverHelper.wait(30000); + await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); + }); - suiteTeardown('Unregister running workspace', function (): void { - registerRunningWorkspace(''); - }); + suiteTeardown('Unregister running workspace', function (): void { + registerRunningWorkspace(''); + }); + } } );