Skip to content

Commit 7bed30f

Browse files
committed
releng: Fix SWTBot tests for 4.36 platform
The Window > "Preferences" menu has been renamed to Window > "Preferences..." in 4.36 platform. Add utility method SWTBotUtils.anyMenuOf() and use it with both menu item text options for backward compatibility. Signed-off-by: Patrick Tasse <[email protected]>
1 parent b1cf1c7 commit 7bed30f

File tree

1 file changed

+22
-3
lines changed
  • tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared

1 file changed

+22
-3
lines changed

tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014, 2020 Ericsson
2+
* Copyright (c) 2014, 2025 Ericsson
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -65,6 +65,7 @@
6565
import org.eclipse.swt.widgets.Button;
6666
import org.eclipse.swt.widgets.Control;
6767
import org.eclipse.swt.widgets.Display;
68+
import org.eclipse.swt.widgets.MenuItem;
6869
import org.eclipse.swt.widgets.Shell;
6970
import org.eclipse.swt.widgets.Table;
7071
import org.eclipse.swt.widgets.TableItem;
@@ -141,7 +142,7 @@
141142
public final class SWTBotUtils {
142143

143144
private static final String WINDOW_MENU = "Window";
144-
private static final String PREFERENCES_MENU_ITEM = "Preferences";
145+
private static final String[] PREFERENCES_MENU_ITEM = { "Preferences...", "Preferences" };
145146
private static final String PREFERENCES_SHELL = "Preferences";
146147
private static boolean fPrintedEnvironment = false;
147148
private static Logger log = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
@@ -1148,7 +1149,8 @@ public static SWTBotShell openPreferences(SWTBot bot, String text) {
11481149
fail();
11491150
}
11501151
} else {
1151-
mainShell.bot().menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
1152+
SWTBotMenu windowMenu = mainShell.bot().menu(WINDOW_MENU);
1153+
anyMenuOf(windowMenu, PREFERENCES_MENU_ITEM).click();
11521154
}
11531155

11541156
if (text != null) {
@@ -1205,6 +1207,23 @@ public static SWTBotShell anyShellOf(SWTBot bot, String... texts) {
12051207
return new SWTBotShell((Shell) bot.widget(allOf(matchers), 0), allOf(matchers));
12061208
}
12071209

1210+
/**
1211+
* Get the first menu that has any one of the specified texts. Useful when
1212+
* menus change text between releases, or when one of many menus could appear.
1213+
*
1214+
* @param bot
1215+
* a given menu bot
1216+
* @param texts
1217+
* the possible menu texts
1218+
* @return a SWTBotMenu
1219+
* @throws WidgetNotFoundException
1220+
* if the widget is not found or is disposed.
1221+
*/
1222+
public static SWTBotMenu anyMenuOf(SWTBotMenu bot, String... texts) {
1223+
Matcher<MenuItem> anyOf = anyOf(Lists.transform(Arrays.asList(texts), text -> withMnemonic(text)));
1224+
return bot.menu(anyOf, false, 0);
1225+
}
1226+
12081227
/**
12091228
* Maximize a workbench part and wait for one of its controls to be resized.
12101229
* Calling this a second time will "un-maximize" the part.

0 commit comments

Comments
 (0)