Skip to content

Commit

Permalink
Stabilize workspace with parent test (#23242)
Browse files Browse the repository at this point in the history
* stabilize workspace with parent test
  • Loading branch information
musienko-maxim authored Nov 14, 2024
1 parent 064b37c commit 4787042
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tests/e2e/specs/miscellaneous/WorkspaceWithParent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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();
});
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/utils/workspace/ITestWorkspaceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ export interface ITestWorkspaceUtil {
* Similar with 'force' deleting
*/
deleteAllWorkspaces(): Promise<void>;

/**
* set user preferences for Che "security.workspace.trust.enabled": false using JS.
*/
switchOffTrustDialogWithJavaScript(): Promise<void>;
}
27 changes: 27 additions & 0 deletions tests/e2e/utils/workspace/TestWorkspaceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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);
}
}

0 comments on commit 4787042

Please sign in to comment.