diff --git a/tests/e2e/specs/miscellaneous/ExtensionActivationTest.spec.ts b/tests/e2e/specs/miscellaneous/ExtensionActivationTest.spec.ts index 5a62452b033..6dde2ed4d36 100644 --- a/tests/e2e/specs/miscellaneous/ExtensionActivationTest.spec.ts +++ b/tests/e2e/specs/miscellaneous/ExtensionActivationTest.spec.ts @@ -75,8 +75,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct test('Open Python file and run it', async function (): Promise { const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession(); - await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME); - await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM); + await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME); await driverHelper.waitAndClick(RUN_PYTHON_BUTTON); await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT); @@ -108,8 +107,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct await driverHelper.wait(TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession(); - await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME); - await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM); + await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME); await driverHelper.waitAndClick(RUN_PYTHON_BUTTON); await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT); @@ -147,8 +145,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct test('Verify Python execution after workspace restart', async function (): Promise { const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession(); - await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME); - await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM); + await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME); await driverHelper.waitAndClick(RUN_PYTHON_BUTTON); await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT); diff --git a/tests/e2e/tests-library/ProjectAndFileTests.ts b/tests/e2e/tests-library/ProjectAndFileTests.ts index a266441a9d1..31e17950eea 100644 --- a/tests/e2e/tests-library/ProjectAndFileTests.ts +++ b/tests/e2e/tests-library/ProjectAndFileTests.ts @@ -15,7 +15,7 @@ import { CLASSES } from '../configs/inversify.types'; import { Logger } from '../utils/Logger'; import { TIMEOUT_CONSTANTS } from '../constants/TIMEOUT_CONSTANTS'; import { CheCodeLocatorLoader } from '../pageobjects/ide/CheCodeLocatorLoader'; -import { By, SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects'; +import { By, EditorView, SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects'; import { WorkspaceHandlingTests } from '../tests-library/WorkspaceHandlingTests'; import { RestrictedModeButton } from '../pageobjects/ide/RestrictedModeButton'; @@ -190,4 +190,37 @@ export class ProjectAndFileTests { return output.trimStart(); } + + /** + * open a file in the project tree and verify it is opened in the editor. + * Retries up to 2 times if the file doesn't open on the first attempt. + * @param projectSection ViewSection with project tree files. + * @param projectName Name of the project folder. + * @param fileName Name of the file to open. + */ + async openFileAndVerify(projectSection: ViewSection, projectName: string, fileName: string): Promise { + const maxAttempts: number = 2; + const editorView: EditorView = new EditorView(); + + for (let attempt: number = 1; attempt <= maxAttempts; attempt++) { + Logger.debug(`Attempt ${attempt}/${maxAttempts}: opening file "${fileName}" in project "${projectName}"`); + await projectSection.openItem(projectName, fileName); + await this.driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM); + + const openEditorTitles: string[] = await editorView.getOpenEditorTitles(); + Logger.debug(`Open editor titles: ${openEditorTitles.join(', ')}`); + + if (openEditorTitles.includes(fileName)) { + Logger.debug(`File "${fileName}" successfully opened in the editor`); + return; + } + + if (attempt < maxAttempts) { + Logger.warn(`File "${fileName}" not found in editor tabs, retrying...`); + await this.driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING); + } + } + + throw new Error(`File "${fileName}" was not opened in the editor after ${maxAttempts} attempts`); + } }