@@ -15,7 +15,7 @@ import { CLASSES } from '../configs/inversify.types';
1515import { Logger } from '../utils/Logger' ;
1616import { TIMEOUT_CONSTANTS } from '../constants/TIMEOUT_CONSTANTS' ;
1717import { 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' ;
1919import { WorkspaceHandlingTests } from '../tests-library/WorkspaceHandlingTests' ;
2020import { 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