@@ -208,8 +208,10 @@ describe("Command Tests", function() {
208208 }
209209 }
210210 await sleep ( 5000 ) ;
211+ // Use command palette to save because the editor input area may not be
212+ // interactable right after the rename refactoring dialog is dismissed.
213+ await new Workbench ( ) . executeCommand ( 'workbench.action.files.save' ) ;
211214 const editor = new TextEditor ( ) ;
212- await editor . save ( ) ;
213215 assert . ok ( await editor . getTitle ( ) === "AppRenamed.java" , `Editor's title should be "AppRenamed.java"` ) ;
214216 assert . ok ( await section . findItem ( "AppRenamed" ) , `Item in Java Project section should be "AppRenamed"` ) ;
215217 } ) ;
@@ -243,6 +245,10 @@ describe("Command Tests", function() {
243245
244246 it ( "Test change to invisible project" , async function ( ) {
245247 await openProject ( invisibleProjectPath ) ;
248+ // Allow VS Code to finish the workspace transition before opening files
249+ await sleep ( 3000 ) ;
250+ // Dismiss any modal dialog (e.g. workspace trust) that may appear after opening a new project
251+ await dismissModalDialogIfPresent ( ) ;
246252 await openFile ( invisibleJavaFilePath ) ;
247253 await waitForLanguageServerReady ( ) ;
248254 const fileSections = await new SideBarView ( ) . getContent ( ) . getSections ( ) ;
@@ -292,6 +298,7 @@ describe("Command Tests", function() {
292298 } ) ;
293299
294300 it ( "Test java.project.create" , async function ( ) {
301+ await dismissModalDialogIfPresent ( ) ;
295302 const projectFolder = createTmpProjectFolder ( "newProject" ) ;
296303 await fse . ensureDir ( projectFolder ) ;
297304 await new Workbench ( ) . executeCommand ( "java.project.create" ) ;
@@ -333,6 +340,8 @@ async function expandMainCodeInJavaProjects() {
333340}
334341
335342async function expandInJavaProjects ( label : string , ...otherLabels : string [ ] ) : Promise < [ TreeItem , ViewSection ] > {
343+ // Dismiss any lingering modal dialog that could block sidebar clicks
344+ await dismissModalDialogIfPresent ( ) ;
336345 // Collapse file section to make sure that the AppToRename tree item fits in the current viewport.
337346 // .findItem will only find tree items in the current viewport.
338347 await collapseFileSection ( ) ;
@@ -390,6 +399,28 @@ async function getActionButton(item: TreeItem, label: string) {
390399 return item . findElement ( By . xpath ( `.//a[contains(@class, 'action-label') and @role='button' and contains(@aria-label, '${ label } ')]` ) ) ;
391400}
392401
402+ async function dismissModalDialogIfPresent ( ) {
403+ try {
404+ const dialog = new ModalDialog ( ) ;
405+ const buttons = await dialog . getButtons ( ) ;
406+ for ( const button of buttons ) {
407+ const text = await button . getText ( ) ;
408+ if ( [ "Yes, I trust the authors" , "OK" , "Yes" , "Continue" , "I Trust the Authors" ] . includes ( text ) ) {
409+ await button . click ( ) ;
410+ await sleep ( 1000 ) ;
411+ return ;
412+ }
413+ }
414+ // Dismiss by clicking the first available button as a fallback
415+ if ( buttons . length > 0 ) {
416+ await buttons [ 0 ] . click ( ) ;
417+ await sleep ( 1000 ) ;
418+ }
419+ } catch ( _e ) {
420+ // No modal dialog present — nothing to dismiss
421+ }
422+ }
423+
393424async function ensureExplorerIsOpen ( ) {
394425 const control = await new ActivityBar ( ) . getViewControl ( 'Explorer' ) ;
395426 if ( control === undefined ) {
0 commit comments