From: Patrick Tasse Date: Fri, 7 Aug 2015 17:46:23 +0000 (-0400) Subject: swtbot: Fix CopyToClipboardTest X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=59b8da2d6370727c0d7f93744aba9259fb08cffe;p=deliverable%2Ftracecompass.git swtbot: Fix CopyToClipboardTest The table sometimes did not react fast enough to the selection to remove the Copy to Clipboard item from its context menu. The condition is changed to wait until the item is no longer found and won't fail even if the item is still found for a short time. Also temporarily fixed to handle the consequences of SWTBot Bug 474063. Change-Id: I6db683abbcec3ec86d4b70c67b6abcf588cd5783 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/53426 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CopyToClipboardTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CopyToClipboardTest.java index 6939a4b190..13b639fb68 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CopyToClipboardTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CopyToClipboardTest.java @@ -67,6 +67,8 @@ public class CopyToClipboardTest { private static final String TRACE_NAME = "syslog_collapse"; private static final String TRACE_PATH = "testfiles/" + TRACE_NAME; private static final String TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog"; + private static final String COPY_TO_CLIPBOARD = "Copy to Clipboard"; + private static final int TIMEOUT = 2000; /* 20 second timeout */ private static File fTestFile = null; @@ -96,7 +98,7 @@ public class CopyToClipboardTest { assumeTrue(fTestFile.exists()); /* Set up for swtbot */ - SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ + SWTBotPreferences.TIMEOUT = TIMEOUT; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; fLogger.removeAllAppenders(); fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); @@ -148,7 +150,7 @@ public class CopyToClipboardTest { final SWTBotTable tableBot = fEditorBot.bot().table(); tableBot.getTableItem(1).click(); - tableBot.contextMenu("Copy to Clipboard").click(); + tableBot.contextMenu(COPY_TO_CLIPBOARD).click(); assertClipboardContentsEquals(HEADER_TEXT + EVENT1_TEXT); } @@ -162,25 +164,43 @@ public class CopyToClipboardTest { KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.DOWN); KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.DOWN); - tableBot.contextMenu("Copy to Clipboard").click(); + tableBot.contextMenu(COPY_TO_CLIPBOARD).click(); assertClipboardContentsEquals(HEADER_TEXT + EVENT1_TEXT + EVENT2_TEXT + EVENT3_TEXT); } /** * Test copy to clipboard not enabled when selection includes search row */ - @Test(expected = TimeoutException.class) + @Test public void testNoCopySearchRow() { final SWTBotTable tableBot = fEditorBot.bot().table(); tableBot.getTableItem(1).click(); KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.UP); - try { - SWTBotPreferences.TIMEOUT = 1000; /* 1 second timeout */ - tableBot.contextMenu("Copy to Clipboard"); - } finally { - SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ - } + assertContextMenuAbsent(tableBot, COPY_TO_CLIPBOARD); + } + + private static void assertContextMenuAbsent(final SWTBotTable tableBot, final String text) { + fBot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + try { + SWTBotPreferences.TIMEOUT = 0; + tableBot.contextMenu(text); + } catch (TimeoutException e) { + return true; + } catch (IndexOutOfBoundsException e) { + /* remove when Bug 474063 is fixed */ + } finally { + SWTBotPreferences.TIMEOUT = TIMEOUT; + } + return false; + } + @Override + public String getFailureMessage() { + return text + " context menu present, absent expected."; + } + }); } private static void assertClipboardContentsEquals(final String expected) {