Author: lzoubek(a)redhat.com
Date: 2011-01-07 10:28:47 -0500 (Fri, 07 Jan 2011)
New Revision: 27981
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/SWTOpenExt.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/gen/ActionItem.java
Log:
swtbot ext: added runJavaApp (able to pass arguments to main method), minors
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 2011-01-07
14:55:03 UTC (rev 27980)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2011-01-07
15:28:47 UTC (rev 27981)
@@ -11,7 +11,11 @@
package org.jboss.tools.ui.bot.ext;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic;
+import static org.hamcrest.Matchers.allOf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
@@ -23,6 +27,7 @@
import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
@@ -32,9 +37,11 @@
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.WidgetResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCTabItem;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.hamcrest.Matcher;
@@ -50,6 +57,7 @@
import org.jboss.tools.ui.bot.ext.types.IDELabel.PreferencesDialog;
import org.jboss.tools.ui.bot.ext.types.PerspectiveType;
import org.jboss.tools.ui.bot.ext.types.ViewType;
+import org.jboss.tools.ui.bot.ext.view.ProjectExplorer;
/**
* Provides Eclipse common operation based on SWTBot element operations
@@ -1042,6 +1050,33 @@
}
/**
+ * runs java application (run configuration)
+ * NOTE that Run->Run Configurations.. must be available to work (use appropriate
perspective)
+ * @param project which should run
+ * @param className with main class to run
+ * @param arguments that will be passed to main class (can be null)
+ */
+ @SuppressWarnings("unchecked")
+ public void runJavaApplication(String project, String className, String arguments) {
+ bot.menu(IDELabel.Menu.RUN).menu("Run Configurations...").click();
+ SWTBotShell shell = bot.shell("Run Configurations");
+ shell.activate();
+ open.selectTreeNode(shell.bot(),ActionItem.create("Java Application"));
+ shell.bot().toolbarButton(0).click();
+ SWTBotCTabItem tab = shell.bot().cTabItem("Main").activate();
+ List<Text> list = (List<Text>)
shell.bot().widgets(allOf(widgetOfType(Text.class)), tab.widget);
+ assertTrue(list.size()>=2);
+ new SWTBotText(list.get(0)).setText(project);
+ new SWTBotText(list.get(1)).setText(className);
+ if (arguments!=null) {
+ tab = shell.bot().cTabItem("Arguments").activate();
+ list = (List<Text>) shell.bot().widgets(allOf(widgetOfType(Text.class)),
tab.widget);
+ assertTrue(list.size()>=2);
+ new SWTBotText(list.get(0)).setText(arguments);
+ }
+ bot.button(IDELabel.Button.RUN).click();
+ }
+ /**
* Search for Menu Item with Run on Server substring within label
*
* @param subMenu
@@ -1168,7 +1203,25 @@
return treeItems;
}
-
+ public static String getFormattedTreeNode(SWTBotTreeItem item) {
+ if (item==null) {
+ return "<item is null>";
+ }
+ if (item.row()==null) {
+ return item.getText();
+ }
+ StringBuilder sb = new StringBuilder("");
+ for (int i=0;i<item.row().columnCount();i++) {
+ String text = item.row().get(i);
+ if (text==null) {
+ sb.append("\"<null>\"");
+ }
+ else {
+ sb.append(String.format("\"{0}\"", text));
+ }
+ }
+ return sb.toString();
+ }
public static String getFormattedTreeNodeText (SWTBotTree tree, SWTBotTreeItem item){
StringBuilder stringBuilder = new StringBuilder("");
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2011-01-07
14:55:03 UTC (rev 27980)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2011-01-07
15:28:47 UTC (rev 27981)
@@ -76,13 +76,20 @@
+ "'");
}
}
-
/**
* selects given actionItem in bot's tree();
*
* @param item
*/
public void selectTreeNode(IActionItem item) {
+ selectTreeNode(this.bot,item);
+ }
+ /**
+ * selects given actionItem in bot's tree();
+ *
+ * @param item
+ */
+ public void selectTreeNode(SWTBot bot, IActionItem item) {
SWTBotTreeItem ti = null;
try {
Iterator<String> iter = item.getGroupPath().iterator();
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/gen/ActionItem.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/gen/ActionItem.java 2011-01-07
14:55:03 UTC (rev 27980)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/gen/ActionItem.java 2011-01-07
15:28:47 UTC (rev 27981)
@@ -20,6 +20,34 @@
sb.append(item.getName());
return sb.toString();
}
+ /**
+ * creates new action item instance from given path
+ * @param path
+ * @return
+ */
+ public static IActionItem create(final String...path) {
+ if (path.length<1) {
+ throw new IllegalArgumentException("path must contain at least 1 item");
+ }
+ return new IActionItem() {
+
+ @Override
+ public String getName() {
+ // TODO Auto-generated method stub
+ return path[path.length-1];
+ }
+
+ @Override
+ public List<String> getGroupPath() {
+ List<String> l = new Vector<String>();
+ for (int i=0; i<path.length-1;i++) {
+ l.add(path[i]);
+ }
+ return l;
+ }
+
+ };
+ }
public static class View {
public static class JavaBrowsingTypes {
/**
Show replies by date