tmf: Fix FontEventEditorTest on Mac
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 19 Nov 2015 22:24:04 +0000 (17:24 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 1 Dec 2015 00:37:55 +0000 (19:37 -0500)
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
tmf/org.eclipse.tracecompass.tmf.remote.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/remote/ui/swtbot/tests/fetch/FetchRemoteTracesTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FontEventEditorTest.java

index 22840529ad07d6070a128ab85bc24cc422147212..a2360967ac99f816f55c7ff5fdc06d8ca23ff5c1 100644 (file)
@@ -15,7 +15,6 @@ package org.eclipse.tracecompass.tmf.remote.ui.swtbot.tests.fetch;
 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;
@@ -28,16 +27,13 @@ import org.eclipse.core.resources.ResourcesPlugin;
 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;
@@ -453,27 +449,15 @@ public class FetchRemoteTracesTest {
     }
 
     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();
     }
index b8bbe60a511dbdb8a62c5a4b3cacfa748e603ea3..208b4b7db14f4278117f80bd352a938304cbfbb3 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.swtbot.swt.finder.SWTBot;
 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;
@@ -73,6 +74,9 @@ import org.hamcrest.Matcher;
  */
 public final class SWTBotUtils {
 
+    private static final String WINDOW_MENU = "Window";
+    private static final String PREFERENCES_MENU_ITEM = "Preferences";
+
     private SWTBotUtils() {
     }
 
@@ -591,4 +595,29 @@ public final class 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();
+    }
 }
index 84c04d3d40daf2a809c565d47cce8938b5ad9d0c..ee9b033ec78bdb407cffa71aed037184f112a1bf 100644 (file)
@@ -31,11 +31,12 @@ import org.eclipse.core.runtime.Path;
 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;
@@ -132,11 +133,10 @@ public class FontEventEditorTest {
 
         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");
This page took 0.029281 seconds and 5 git commands to generate.