Skip to content

Commit 460bbeb

Browse files
authored
Add file open verification to Editor test (#23754)
1 parent 1e2be97 commit 460bbeb

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

tests/e2e/specs/miscellaneous/ExtensionActivationTest.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct
7575

7676
test('Open Python file and run it', async function (): Promise<void> {
7777
const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession();
78-
await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME);
79-
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM);
78+
await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME);
8079

8180
await driverHelper.waitAndClick(RUN_PYTHON_BUTTON);
8281
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT);
@@ -108,8 +107,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct
108107
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
109108

110109
const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession();
111-
await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME);
112-
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM);
110+
await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME);
113111

114112
await driverHelper.waitAndClick(RUN_PYTHON_BUTTON);
115113
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT);
@@ -147,8 +145,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct
147145

148146
test('Verify Python execution after workspace restart', async function (): Promise<void> {
149147
const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession();
150-
await projectSection.openItem(PROJECT_NAME, PYTHON_FILE_NAME);
151-
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM);
148+
await projectAndFileTests.openFileAndVerify(projectSection, PROJECT_NAME, PYTHON_FILE_NAME);
152149

153150
await driverHelper.waitAndClick(RUN_PYTHON_BUTTON);
154151
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT);

tests/e2e/tests-library/ProjectAndFileTests.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CLASSES } from '../configs/inversify.types';
1515
import { Logger } from '../utils/Logger';
1616
import { TIMEOUT_CONSTANTS } from '../constants/TIMEOUT_CONSTANTS';
1717
import { CheCodeLocatorLoader } from '../pageobjects/ide/CheCodeLocatorLoader';
18-
import { By, SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects';
18+
import { By, EditorView, SideBarView, ViewContent, ViewItem, ViewSection, Workbench } from 'monaco-page-objects';
1919
import { WorkspaceHandlingTests } from '../tests-library/WorkspaceHandlingTests';
2020
import { RestrictedModeButton } from '../pageobjects/ide/RestrictedModeButton';
2121

@@ -190,4 +190,37 @@ export class ProjectAndFileTests {
190190

191191
return output.trimStart();
192192
}
193+
194+
/**
195+
* open a file in the project tree and verify it is opened in the editor.
196+
* Retries up to 2 times if the file doesn't open on the first attempt.
197+
* @param projectSection ViewSection with project tree files.
198+
* @param projectName Name of the project folder.
199+
* @param fileName Name of the file to open.
200+
*/
201+
async openFileAndVerify(projectSection: ViewSection, projectName: string, fileName: string): Promise<void> {
202+
const maxAttempts: number = 2;
203+
const editorView: EditorView = new EditorView();
204+
205+
for (let attempt: number = 1; attempt <= maxAttempts; attempt++) {
206+
Logger.debug(`Attempt ${attempt}/${maxAttempts}: opening file "${fileName}" in project "${projectName}"`);
207+
await projectSection.openItem(projectName, fileName);
208+
await this.driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM);
209+
210+
const openEditorTitles: string[] = await editorView.getOpenEditorTitles();
211+
Logger.debug(`Open editor titles: ${openEditorTitles.join(', ')}`);
212+
213+
if (openEditorTitles.includes(fileName)) {
214+
Logger.debug(`File "${fileName}" successfully opened in the editor`);
215+
return;
216+
}
217+
218+
if (attempt < maxAttempts) {
219+
Logger.warn(`File "${fileName}" not found in editor tabs, retrying...`);
220+
await this.driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING);
221+
}
222+
}
223+
224+
throw new Error(`File "${fileName}" was not opened in the editor after ${maxAttempts} attempts`);
225+
}
193226
}

0 commit comments

Comments
 (0)