tmf: Add a more reliable way to get the active editor with SWTBot
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 19 Aug 2015 20:01:16 +0000 (16:01 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 2 Sep 2015 18:18:52 +0000 (14:18 -0400)
StandardImportGzipTraceTest assumes that after double-clicking on the
trace, there will be an active editor right away. Instead, we can
have a method that waits until there is an active editor.

I've seen the failure:
WidgetNotFoundException: There is no active editor
here:
http://eclip.se/5l

Change-Id: I41dd5c7c4f30f789dabab813eb8bcbb81fdcb48e
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/54154
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
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/ColorsViewTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FilterViewerTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/TmfAlignTimeAxisTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/wizards/StandardImportGzipTraceTest.java

index 07f5049c83c326795a31fe6d869a4ccd9ec364c9..7386e341f3ecca0004bd6b67d920fe1910bfe26a 100644 (file)
@@ -42,6 +42,7 @@ 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.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
@@ -521,4 +522,35 @@ public final class SWTBotUtils {
 
         return currentNode;
     }
+
+    /**
+     * Get the active events editor. Note that this will wait until such editor
+     * is available.
+     *
+     * @param workbenchBot
+     *            a given workbench bot
+     * @return the active events editor
+     */
+    public static SWTBotEditor activeEventsEditor(final SWTWorkbenchBot workbenchBot) {
+        final SWTBotEditor editor[] = new SWTBotEditor[1];
+        workbenchBot.waitUntil(new DefaultCondition() {
+            @Override
+            public boolean test() throws Exception {
+                List<SWTBotEditor> editors = workbenchBot.editors(WidgetMatcherFactory.withPartId(TmfEventsEditor.ID));
+                for (SWTBotEditor e : editors) {
+                    if (e.isActive() && !e.getWidget().isDisposed()) {
+                        editor[0] = e;
+                        return true;
+                    }
+                }
+                return false;
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return "Active events editor not found";
+            }
+        });
+        return editor[0];
+    }
 }
index 1f16dbc10ddce1e2065136bc85fa72f4004c60bf..9f74f6cea0068ff1bf6b6a9cb97d48079bdd75e8 100644 (file)
@@ -248,7 +248,7 @@ public class ColorsViewTest {
                 ColorSettingsManager.setColorSettings(cs);
             }
         });
-        final SWTBotTable eventsEditor = fBot.activeEditor().bot().table();
+        final SWTBotTable eventsEditor = SWTBotUtils.activeEventsEditor(fBot).bot().table();
         // should fix race condition of loading the trace
         SWTBotUtils.waitForJobs();
         eventsEditor.select(2);
index 636dcd33a54fd3d693069aa2f4f7fe973697c123..4fd2967708d297c8ec40d53af2860e2cadf6ed3f 100644 (file)
@@ -307,7 +307,7 @@ public class FilterViewerTest {
 
     private static String applyFilter(SWTWorkbenchBot bot, final String filterName) {
         SWTBotUtils.waitForJobs();
-        final SWTBotTable eventsEditor = bot.activeEditor().bot().table();
+        final SWTBotTable eventsEditor = SWTBotUtils.activeEventsEditor(bot).bot().table();
         SWTBotTableItem tableItem = eventsEditor.getTableItem(2);
         tableItem.contextMenu(filterName).click();
         fBot.waitUntil(ConditionHelpers.isTableCellFilled(eventsEditor, "/100", 1, 1));
index 24a7d9a859391614d2f9d3131afb0a2eaff17cfa..6827490050d6c61c039b53fbd03c49ed7167484a 100644 (file)
@@ -140,7 +140,7 @@ public class TmfAlignTimeAxisTest {
     @After
     public void after() {
         SWTWorkbenchBot bot = new SWTWorkbenchBot();
-        bot.activeEditor().close();
+        SWTBotUtils.activeEventsEditor(bot).close();
     }
 
     /**
index 3b1d112070f45d3cd19ca8c67975695cc4af1b43..a7ad2397522e2182051150580d14e7ceec475064 100644 (file)
@@ -168,7 +168,7 @@ public class StandardImportGzipTraceTest {
         /*
          * Check results
          */
-        SWTBot editorBot = fBot.activeEditor().bot();
+        SWTBot editorBot = SWTBotUtils.activeEventsEditor(fBot).bot();
         SWTBotTable editorTable = editorBot.table();
         final String expectedContent1 = "Type-1";
         final String expectedContent2 = "";
This page took 0.028624 seconds and 5 git commands to generate.