Skip to content

Commit 2f55ec9

Browse files
committed
Wait for UI to load
Signed-off-by: Adam Wisniewski <awisniew@us.ibm.com>
1 parent 7fa4694 commit 2f55ec9

File tree

1 file changed

+92
-10
lines changed

1 file changed

+92
-10
lines changed

tests/src/main/java/io/openliberty/tools/eclipse/test/it/utils/SWTBotPluginOperations.java

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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,11 +223,27 @@ 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

232+
// Explicitly activate the Debug view to ensure widgets are properly rendered
233+
// This is critical for headless CI environments
234+
if (debugView instanceof ViewPart) {
235+
final ViewPart vp = (ViewPart) debugView;
236+
try {
237+
IWorkbench wb = PlatformUI.getWorkbench();
238+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
239+
if (window != null && window.getActivePage() != null) {
240+
window.getActivePage().activate(vp);
241+
}
242+
} catch (Exception e) {
243+
System.err.println("Failed to activate Debug view: " + e.getMessage());
244+
}
245+
}
246+
216247
result[0] = MagicWidgetFinder.find(objectName, debugView,
217248
Option.factory().useContains(true).setThrowExceptionOnNotFound(false).widgetClass(TreeItem.class).build());
218249
}
@@ -240,6 +271,31 @@ public void run() {
240271
Display.getDefault().syncExec(runnable);
241272
}
242273

274+
/**
275+
* Opens the Debug view using Eclipse API directly.
276+
* This is more reliable than menu navigation in headless CI environments.
277+
*/
278+
private static void showDebugView() {
279+
Display.getDefault().syncExec(new Runnable() {
280+
@Override
281+
public void run() {
282+
try {
283+
IWorkbench wb = PlatformUI.getWorkbench();
284+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
285+
if (window != null && window.getActivePage() != null) {
286+
// Show the Debug view using its ID
287+
window.getActivePage().showView("org.eclipse.debug.ui.DebugView");
288+
}
289+
} catch (Exception e) {
290+
System.err.println("Failed to open Debug view: " + e.getMessage());
291+
e.printStackTrace();
292+
}
293+
}
294+
});
295+
// Give the view time to open
296+
MagicWidgetFinder.pause(500);
297+
}
298+
243299
public static void openJavaPerspectiveViaMenu() {
244300
Object windowMenu = findGlobal("Window", Option.factory().widgetClass(MenuItem.class).build());
245301

@@ -723,8 +779,9 @@ public static void checkRunCleanProjectCheckBox(Shell shell, String runDebugConf
723779

724780
public static Object getAppInPackageExplorerTree(String appName) {
725781
openJavaPerspectiveViaMenu();
726-
Object windowMenu = findGlobal("Window", Option.factory().widgetClass(MenuItem.class).build());
727-
goMenuItem(windowMenu, "Show View", "Package Explorer");
782+
// Open Package Explorer view using Eclipse API instead of menu navigation
783+
// This is more reliable in headless CI environments
784+
showPackageExplorerView();
728785
Object peView = MagicWidgetFinder.findGlobal("Package Explorer");
729786

730787
Object project = MagicWidgetFinder.find(appName, peView, Option.factory().useContains(true).widgetClass(TreeItem.class).build());
@@ -988,6 +1045,31 @@ public static void closeDashboardView(SWTWorkbenchBot bot) {
9881045
}
9891046
}
9901047

1048+
/**
1049+
* Opens the Package Explorer view using Eclipse API directly.
1050+
* This is more reliable than menu navigation in headless CI environments.
1051+
*/
1052+
private static void showPackageExplorerView() {
1053+
Display.getDefault().syncExec(new Runnable() {
1054+
@Override
1055+
public void run() {
1056+
try {
1057+
IWorkbench wb = PlatformUI.getWorkbench();
1058+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
1059+
if (window != null && window.getActivePage() != null) {
1060+
// Show the Package Explorer view using its ID
1061+
window.getActivePage().showView("org.eclipse.jdt.ui.PackageExplorer");
1062+
}
1063+
} catch (Exception e) {
1064+
System.err.println("Failed to open Package Explorer view: " + e.getMessage());
1065+
e.printStackTrace();
1066+
}
1067+
}
1068+
});
1069+
// Give the view time to open
1070+
MagicWidgetFinder.pause(500);
1071+
}
1072+
9911073
/**
9921074
* Switches the Liberty run configuration main tab to the JRE Tab. A Liberty configuration must be opened prior to calling this
9931075
* method.

0 commit comments

Comments
 (0)