From f7cf5a154f03266749d5923a69721bd37b2b71a0 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Wed, 19 Nov 2014 22:49:57 -0500 Subject: [PATCH] swtbot: Look for "Eclipse" in the shell title instead of "Eclipse SDK" This allows running the tests with the Eclipse Platform product. Change-Id: I0027654e5b2a885d656f9610459b4d4beaa875ce Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/36731 Reviewed-by: Marc Khouzam Tested-by: Marc Khouzam --- .../cdt/autotools/ui/tests/AbstractTest.java | 35 ++++++++++++------- .../ui/tests/TestEnvironmentVars.java | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java index 8fc60c56b2b..c4e660eb984 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java @@ -17,8 +17,8 @@ import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRe import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withStyle; import static org.eclipse.swtbot.swt.finder.waits.Conditions.waitForWidget; import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectNature; @@ -64,17 +64,8 @@ public abstract class AbstractTest { SWTBotPreferences.PLAYBACK_DELAY = 10; bot = new SWTWorkbenchBot(); bot.sleep(5000); - mainShell = null; - for (int i = 0, attempts = 100; i < attempts; i++) { - for (SWTBotShell shell : bot.shells()) { - if (shell.getText().contains("Eclipse Platform")) { - mainShell = shell; - shell.setFocus(); - break; - } - } - } - assertNotNull(mainShell); + mainShell = getMainShell(); + // Close the Welcome view if it exists try { bot.viewByTitle("Welcome").close(); @@ -305,7 +296,7 @@ public abstract class AbstractTest { .toolbarDropDownButton("Display Selected Console"); org.hamcrest.Matcher withRegex = withRegex(".*" + consoleType + ".*"); - bot.shell("C/C++ - Eclipse Platform").activate(); + focusMainShell(); b.menuItem(withRegex).click(); try { b.pressShortcut(KeyStroke.getInstance("ESC")); @@ -315,6 +306,24 @@ public abstract class AbstractTest { return view; } + /** + * Focus on the main window + */ + public static void focusMainShell() { + SWTBotShell shell = getMainShell(); + shell.activate(); + } + + private static SWTBotShell getMainShell() { + for (SWTBotShell shellBot : bot.shells()) { + if (shellBot.getText().toLowerCase().contains("eclipse")) { + return shellBot; + } + } + fail("Could not find main shell"); + return null; + } + @After public void cleanUp() { exitProjectFolder(); diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java index dbde06d6511..fc881d5da7b 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java @@ -162,7 +162,7 @@ public class TestEnvironmentVars extends AbstractTest { // the script clickContextMenu(projectExplorer.bot().tree().select(projectName), "Reconfigure Project"); - bot.shell("C/C++ - Eclipse Platform").activate(); + focusMainShell(); bot.sleep(3000); SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus();