On Mac, the Preferences menu item is under the application name.
For some reason, we can't access the application menu so we use the
keyboard shortcut. This commits create a helper method in SWTBotUtils so
that this problem doesn't occur again when a new test wants to open the
preference window.
Change-Id: Ib4a76cd6d0f1b70965f83eaf4920aa55cf81835a
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/60857
Reviewed-by: Hudson CI
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
-import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
}
private static void openRemoteProfilePreferences() {
- if (SWTUtils.isMac()) {
- // On Mac, the Preferences menu item is under the application name.
- // For some reason, we can't access the application menu anymore so
- // we use the keyboard shortcut.
- try {
- fBot.activeShell().pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
- } catch (ParseException e) {
- fail();
- }
- } else {
- fBot.menu("Window").menu("Preferences").click();
- }
-
- fBot.waitUntil(Conditions.shellIsActive("Preferences"));
+ SWTBotShell preferencesShell = SWTBotUtils.openPreferences(fBot);
// The first tree is the preference "categories" on the left side
- SWTBotTree tree = fBot.tree(0);
+ SWTBot bot = preferencesShell.bot();
+ SWTBotTree tree = bot.tree(0);
SWTBotTreeItem treeNode = tree.getTreeItem("Tracing");
treeNode.select();
treeNode.expand();
- fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Remote Profiles", treeNode));
+ bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Remote Profiles", treeNode));
treeNode = treeNode.getNode("Remote Profiles");
treeNode.select();
}
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
*/
public final class SWTBotUtils {
+ private static final String WINDOW_MENU = "Window";
+ private static final String PREFERENCES_MENU_ITEM = "Preferences";
+
private SWTBotUtils() {
}
});
return editor[0];
}
+
+ /**
+ * Open the preferences dialog and return the corresponding shell.
+ *
+ * @param bot
+ * a given workbench bot
+ * @return the preferences shell
+ */
+ public static SWTBotShell openPreferences(SWTBot bot) {
+ if (SWTUtils.isMac()) {
+ // On Mac, the Preferences menu item is under the application name.
+ // For some reason, we can't access the application menu anymore so
+ // we use the keyboard shortcut.
+ try {
+ bot.activeShell().pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
+ } catch (ParseException e) {
+ fail();
+ }
+ } else {
+ bot.menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
+ }
+
+ bot.waitUntil(Conditions.shellIsActive(PREFERENCES_MENU_ITEM));
+ return bot.activeShell();
+ }
}
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
-import org.eclipse.swtbot.swt.finder.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
FontData font = getFont(rawText);
- fBot.menu("Window").menu("Preferences").click();
+ SWTBotShell preferencesShell = SWTBotUtils.openPreferences(fBot);
- fBot.waitUntil(Conditions.shellIsActive("Preferences"));
- SWTWorkbenchBot bot = new SWTWorkbenchBot();
- bot.activeShell().activate();
+ SWTBot bot = preferencesShell.bot();
+ preferencesShell.activate();
bot.text().setText("color");
SWTBotTreeItem generalItem = bot.tree().getTreeItem("General");