Skip to content

Commit 19e135c

Browse files
Fix error SWT bot test 2
1 parent a70e2f3 commit 19e135c

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

  • tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/project

tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/project/AddProjectNatureTest.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,38 @@ private static void toggleFilters(boolean checked) {
249249
item.toggleCheck();
250250
}
251251

252-
// Wait briefly for UI to process changes and enable the button
253-
fBot.sleep(500);
254-
shell.bot().button(APPLY_BUTTON).click();
252+
// Wait for UI to process changes and for the Apply button to be enabled
253+
// Use ConditionHelpers or implement a more robust wait
254+
SWTBot dialogBot = shell.bot();
255+
try {
256+
// Wait for the Apply button to be enabled (up to 5 seconds)
257+
fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled(
258+
dialogBot.button(APPLY_BUTTON)), 5000);
259+
} catch (Exception e) {
260+
// If button is not found or doesn't enable, try alternative approaches
261+
// First, wait a bit more for UI to settle
262+
fBot.sleep(1000);
263+
try {
264+
dialogBot.button(APPLY_BUTTON).click();
265+
} catch (WidgetNotFoundException e2) {
266+
// If Apply button is still not found, try OK button as fallback
267+
try {
268+
dialogBot.button("OK").click();
269+
return;
270+
} catch (WidgetNotFoundException e3) {
271+
// Log available buttons for debugging
272+
org.eclipse.swtbot.swt.finder.widgets.SWTBotButton[] buttons = dialogBot.buttons();
273+
StringBuilder availableButtons = new StringBuilder("Available buttons: ");
274+
for (org.eclipse.swtbot.swt.finder.widgets.SWTBotButton btn : buttons) {
275+
availableButtons.append("[").append(btn.getText()).append("] ");
276+
}
277+
throw new WidgetNotFoundException(availableButtons.toString(), e3);
278+
}
279+
}
280+
return;
281+
}
282+
283+
// Button is enabled, click it
284+
dialogBot.button(APPLY_BUTTON).click();
255285
}
256286
}

0 commit comments

Comments
 (0)