|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2014, 2020 Ericsson |
| 2 | + * Copyright (c) 2014, 2025 Ericsson |
3 | 3 | * |
4 | 4 | * All rights reserved. This program and the accompanying materials are |
5 | 5 | * made available under the terms of the Eclipse Public License 2.0 which |
|
65 | 65 | import org.eclipse.swt.widgets.Button; |
66 | 66 | import org.eclipse.swt.widgets.Control; |
67 | 67 | import org.eclipse.swt.widgets.Display; |
| 68 | +import org.eclipse.swt.widgets.MenuItem; |
68 | 69 | import org.eclipse.swt.widgets.Shell; |
69 | 70 | import org.eclipse.swt.widgets.Table; |
70 | 71 | import org.eclipse.swt.widgets.TableItem; |
|
141 | 142 | public final class SWTBotUtils { |
142 | 143 |
|
143 | 144 | 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" }; |
145 | 146 | private static final String PREFERENCES_SHELL = "Preferences"; |
146 | 147 | private static boolean fPrintedEnvironment = false; |
147 | 148 | private static Logger log = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); |
@@ -1148,7 +1149,8 @@ public static SWTBotShell openPreferences(SWTBot bot, String text) { |
1148 | 1149 | fail(); |
1149 | 1150 | } |
1150 | 1151 | } 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(); |
1152 | 1154 | } |
1153 | 1155 |
|
1154 | 1156 | if (text != null) { |
@@ -1205,6 +1207,23 @@ public static SWTBotShell anyShellOf(SWTBot bot, String... texts) { |
1205 | 1207 | return new SWTBotShell((Shell) bot.widget(allOf(matchers), 0), allOf(matchers)); |
1206 | 1208 | } |
1207 | 1209 |
|
| 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 | + |
1208 | 1227 | /** |
1209 | 1228 | * Maximize a workbench part and wait for one of its controls to be resized. |
1210 | 1229 | * Calling this a second time will "un-maximize" the part. |
|
0 commit comments