Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct

test('Open Python file and run it', async function (): Promise<void> {
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -147,8 +145,7 @@ suite(`Extension Activation Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, funct

test('Verify Python execution after workspace restart', async function (): Promise<void> {
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);
Expand Down
35 changes: 34 additions & 1 deletion tests/e2e/tests-library/ProjectAndFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<void> {
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`);
}
}