@@ -135,10 +135,17 @@ public void run() {
135135 */
136136 public static SWTBotMenu getDebuggerConnectMenuForDebugObject (Object debugObject ) {
137137 openDebugPerspective ();
138- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
139- goMenuItem (windowMenu , "Show View" , "Debug" );
138+ // Open Debug view using Eclipse API instead of menu navigation
139+ // This is more reliable in headless CI environments
140+ showDebugView ();
140141
141142 SWTBotTreeItem obj = new SWTBotTreeItem ((TreeItem ) debugObject );
143+
144+ // Ensure the tree item is properly selected and focused before accessing context menu
145+ // This is critical for headless CI environments where context menus can hang
146+ obj .select ();
147+ obj .setFocus ();
148+ MagicWidgetFinder .pause (500 );
142149
143150 return obj .contextMenu ("Connect Liberty Debugger" );
144151 }
@@ -152,8 +159,15 @@ public static SWTBotMenu getDebuggerConnectMenuForDebugObject(Object debugObject
152159 */
153160 public static void disconnectDebugTarget (Object debugTarget ) {
154161 openDebugPerspective ();
155- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
156- goMenuItem (windowMenu , "Show View" , "Debug" );
162+ // Open Debug view using Eclipse API instead of menu navigation
163+ // This is more reliable in headless CI environments
164+ showDebugView ();
165+
166+ // Ensure proper selection before accessing context menu
167+ SWTBotTreeItem obj = new SWTBotTreeItem ((TreeItem ) debugTarget );
168+ obj .select ();
169+ obj .setFocus ();
170+ MagicWidgetFinder .pause (500 );
157171
158172 MagicWidgetFinder .context (debugTarget , "Disconnect" );
159173
@@ -168,8 +182,9 @@ public static void terminateLaunch() {
168182 @ Override
169183 public void run () {
170184 openDebugPerspective ();
171- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
172- goMenuItem (windowMenu , "Show View" , "Debug" );
185+ // Open Debug view using Eclipse API instead of menu navigation
186+ // This is more reliable in headless CI environments
187+ showDebugView ();
173188
174189 Object debugView = MagicWidgetFinder .findGlobal ("Debug" );
175190
@@ -208,8 +223,9 @@ public static Object getObjectInDebugView(final String objectName) {
208223 @ Override
209224 public void run () {
210225 openDebugPerspective ();
211- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
212- goMenuItem (windowMenu , "Show View" , "Debug" );
226+ // Open Debug view using Eclipse API instead of menu navigation
227+ // This is more reliable in headless CI environments
228+ showDebugView ();
213229
214230 Object debugView = MagicWidgetFinder .findGlobal ("Debug" );
215231
@@ -240,6 +256,31 @@ public void run() {
240256 Display .getDefault ().syncExec (runnable );
241257 }
242258
259+ /**
260+ * Opens the Debug view using Eclipse API directly.
261+ * This is more reliable than menu navigation in headless CI environments.
262+ */
263+ private static void showDebugView () {
264+ Display .getDefault ().syncExec (new Runnable () {
265+ @ Override
266+ public void run () {
267+ try {
268+ IWorkbench wb = PlatformUI .getWorkbench ();
269+ IWorkbenchWindow window = wb .getActiveWorkbenchWindow ();
270+ if (window != null && window .getActivePage () != null ) {
271+ // Show the Debug view using its ID
272+ window .getActivePage ().showView ("org.eclipse.debug.ui.DebugView" );
273+ }
274+ } catch (Exception e ) {
275+ System .err .println ("Failed to open Debug view: " + e .getMessage ());
276+ e .printStackTrace ();
277+ }
278+ }
279+ });
280+ // Give the view time to open
281+ MagicWidgetFinder .pause (500 );
282+ }
283+
243284 public static void openJavaPerspectiveViaMenu () {
244285 Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
245286
@@ -723,8 +764,9 @@ public static void checkRunCleanProjectCheckBox(Shell shell, String runDebugConf
723764
724765 public static Object getAppInPackageExplorerTree (String appName ) {
725766 openJavaPerspectiveViaMenu ();
726- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
727- goMenuItem (windowMenu , "Show View" , "Package Explorer" );
767+ // Open Package Explorer view using Eclipse API instead of menu navigation
768+ // This is more reliable in headless CI environments
769+ showPackageExplorerView ();
728770 Object peView = MagicWidgetFinder .findGlobal ("Package Explorer" );
729771
730772 Object project = MagicWidgetFinder .find (appName , peView , Option .factory ().useContains (true ).widgetClass (TreeItem .class ).build ());
@@ -988,6 +1030,31 @@ public static void closeDashboardView(SWTWorkbenchBot bot) {
9881030 }
9891031 }
9901032
1033+ /**
1034+ * Opens the Package Explorer view using Eclipse API directly.
1035+ * This is more reliable than menu navigation in headless CI environments.
1036+ */
1037+ private static void showPackageExplorerView () {
1038+ Display .getDefault ().syncExec (new Runnable () {
1039+ @ Override
1040+ public void run () {
1041+ try {
1042+ IWorkbench wb = PlatformUI .getWorkbench ();
1043+ IWorkbenchWindow window = wb .getActiveWorkbenchWindow ();
1044+ if (window != null && window .getActivePage () != null ) {
1045+ // Show the Package Explorer view using its ID
1046+ window .getActivePage ().showView ("org.eclipse.jdt.ui.PackageExplorer" );
1047+ }
1048+ } catch (Exception e ) {
1049+ System .err .println ("Failed to open Package Explorer view: " + e .getMessage ());
1050+ e .printStackTrace ();
1051+ }
1052+ }
1053+ });
1054+ // Give the view time to open
1055+ MagicWidgetFinder .pause (500 );
1056+ }
1057+
9911058 /**
9921059 * Switches the Liberty run configuration main tab to the JRE Tab. A Liberty configuration must be opened prior to calling this
9931060 * method.
0 commit comments