From 478704278cc41ad19cc2e766175ae54d69f337e6 Mon Sep 17 00:00:00 2001 From: Maksym Musiienko Date: Thu, 14 Nov 2024 16:53:37 +0200 Subject: [PATCH] Stabilize workspace with parent test (#23242) * stabilize workspace with parent test --- .../miscellaneous/WorkspaceWithParent.spec.ts | 7 ++--- .../e2e/utils/workspace/ITestWorkspaceUtil.ts | 5 ++++ .../e2e/utils/workspace/TestWorkspaceUtil.ts | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/e2e/specs/miscellaneous/WorkspaceWithParent.spec.ts b/tests/e2e/specs/miscellaneous/WorkspaceWithParent.spec.ts index af9d736a91e..9d2e8bd5373 100644 --- a/tests/e2e/specs/miscellaneous/WorkspaceWithParent.spec.ts +++ b/tests/e2e/specs/miscellaneous/WorkspaceWithParent.spec.ts @@ -25,7 +25,6 @@ import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; import { DriverHelper } from '../../utils/DriverHelper'; import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; -import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace'; suite(`Workspace using a parent test suite ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); @@ -39,8 +38,6 @@ suite(`Workspace using a parent test suite ${BASE_TEST_CONSTANTS.TEST_ENVIRONMEN CLASSES.KubernetesCommandLineToolsExecutor ); const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); - const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace); - let podName: string = ''; suiteSetup(function (): void { @@ -57,13 +54,13 @@ suite(`Workspace using a parent test suite ${BASE_TEST_CONSTANTS.TEST_ENVIRONMEN ? BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL + '/dashboard/#/' + 'https://github.com/testsfactory/parentDevfile' : BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL + '/dashboard/#/' + FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL; await dashboard.waitPage(); + await testWorkspaceUtil.switchOffTrustDialogWithJavaScript(); await browserTabsUtil.navigateTo(factoryUrl); - await createWorkspace.performTrustAuthorPopup(); await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); // add 10 sec timeout for waiting for finishing animation of all IDE parts (Welcome parts. bottom widgets. etc.) - // using 10 sec easier than performing of finishing animation a all elements + // using 10 sec easier than performing of finishing animation of all elements await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL); await projectAndFileTests.performTrustAuthorDialog(); }); diff --git a/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts b/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts index 1fd3ce0ae56..01a984a49f0 100644 --- a/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts +++ b/tests/e2e/utils/workspace/ITestWorkspaceUtil.ts @@ -40,4 +40,9 @@ export interface ITestWorkspaceUtil { * Similar with 'force' deleting */ deleteAllWorkspaces(): Promise; + + /** + * set user preferences for Che "security.workspace.trust.enabled": false using JS. + */ + switchOffTrustDialogWithJavaScript(): Promise; } diff --git a/tests/e2e/utils/workspace/TestWorkspaceUtil.ts b/tests/e2e/utils/workspace/TestWorkspaceUtil.ts index 681ca6fc260..eccf05fc076 100644 --- a/tests/e2e/utils/workspace/TestWorkspaceUtil.ts +++ b/tests/e2e/utils/workspace/TestWorkspaceUtil.ts @@ -172,4 +172,31 @@ export class TestWorkspaceUtil implements ITestWorkspaceUtil { await this.deleteWorkspaceByName(response.data.items[i].metadata.name); } } + + /** + * set user preferences for Che "security.workspace.trust.enabled": false using JS. in background mode + */ + async switchOffTrustDialogWithJavaScript(): Promise { + const javaScriptExecCode: string = + '(async function importData() {\n' + + ' const stub = "{\\"vscode-web-db\\":{\\"vscode-userdata-store\\":{\\"/User/settings.json\\":{\\"type\\":\\"Uint8Array\\",\\"value\\":\\"%7B%0A%20%20%20%20%22security.workspace.trust.enabled%22%3A%20false%0A%7D\\"}}}}";\n' + + ' for (const [dbName, dbData] of Object.entries(JSON.parse(stub))) {\n' + + ' const req = indexedDB.open(dbName);\n' + + ' req.onupgradeneeded = ({ target: { result: db } }) =>\n' + + ' Object.keys(dbData).forEach((name) => db.createObjectStore(name));\n' + + ' await new Promise((r) => (req.onsuccess = r));\n' + + ' for (const [storeName, storeData] of Object.entries(dbData)) {\n' + + ' const transaction = req.result.transaction(storeName, "readwrite");\n' + + ' const store = transaction.objectStore(storeName);\n' + + ' store.clear();\n' + + ' for (const [key, { type, value }] of Object.entries(storeData)) {\n' + + ' const str = decodeURIComponent(value);\n' + + ' store.put(type === "String" ? str : new TextEncoder().encode(str), key);\n' + + ' }\n' + + ' await new Promise((r) => (transaction.oncomplete = r));\n' + + ' }\n' + + ' }\n' + + '})().then(() => {});'; + await this.driverHelper.getDriver().executeScript(javaScriptExecCode); + } }