Author: jgargula
Date: 2012-05-11 10:29:09 -0400 (Fri, 11 May 2012)
New Revision: 40950
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
Log:
Added support for finding menu matching regular expression.
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2012-05-11
12:29:33 UTC (rev 40949)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2012-05-11
14:29:09 UTC (rev 40950)
@@ -1244,7 +1244,9 @@
//System.out.println (treeItem.contextMenu("Run As").menu("2 Java
Application").getText());
bot.sleep(Timing.time30S());
- treeItem.contextMenu("Run As").menu("2 Java
Application").click();
+ //treeItem.contextMenu("Run As").menu("2 Java
Application").click();
+ SWTUtilExt.menuWithRegex("(.*) Java Application",
treeItem.contextMenu(IDELabel.Menu.RUN_AS)).click();
+
//runJavaApplication("helloworld_testclient","org.jboss.soa.esb.samples.quickstart.helloworld.test.SendJMSMessage","
");
bot.sleep(Timing.time30S()); // This is needed to enable the test to run successfully
to completion
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2012-05-11
12:29:33 UTC (rev 40949)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2012-05-11
14:29:09 UTC (rev 40950)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.ui.bot.ext;
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withTooltip;
import static org.junit.Assert.fail;
@@ -29,6 +31,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
@@ -36,21 +39,24 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.MenuFinder;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
+import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
import org.jboss.tools.ui.bot.ext.parts.SWTBotBrowserExt;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.jboss.tools.ui.bot.ext.types.JobLists;
import org.jboss.tools.ui.bot.ext.types.JobState;
import org.osgi.framework.Bundle;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
/**
* SWTUtilExt is contains helper method for writing SWTBot tests, i.e. various delay
methods
@@ -822,4 +828,29 @@
projectName;
}
+ /**
+ * Returns the first found menu which matches given regular expression.
+ *
+ * @param menuRegex Regular expression which is looking for in menu text.
+ * @param parentMenu Parent menu which is used for searching.
+ *
+ * @return Menu matching regular expression.
+ *
+ * @throws WidgetNotFoundException If no menu matches.
+ */
+ public static SWTBotMenu menuWithRegex(final String menuRegex, final SWTBotMenu
parentMenu) throws WidgetNotFoundException {
+ final Matcher<? extends Widget> matcher = withRegex(menuRegex);
+ MenuItem menuItem = syncExec(new WidgetResult<MenuItem>() {
+ public MenuItem run() {
+ Menu bar = parentMenu.widget.getMenu();
+ Matcher<MenuItem> withRegex = withRegex(menuRegex);
+ List<MenuItem> menus = new MenuFinder().findMenus(bar, withRegex,
true);
+ if (!menus.isEmpty())
+ return menus.get(0);
+ return null;
+ }
+ });
+ return new SWTBotMenu(menuItem, matcher);
+ }
+
}
\ No newline at end of file
Show replies by date