Author: vpakan(a)redhat.com
Date: 2010-04-08 08:37:49 -0400 (Thu, 08 Apr 2010)
New Revision: 21338
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java
Log:
Added new methods for Drools SWTBot tests
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2010-04-08
12:26:40 UTC (rev 21337)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java 2010-04-08
12:37:49 UTC (rev 21338)
@@ -18,6 +18,7 @@
import java.util.Iterator;
import org.apache.log4j.Logger;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
@@ -26,6 +27,8 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
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.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
@@ -92,17 +95,25 @@
* @param type
*/
public SWTBot showView(ViewType type) {
- SWTBotMenu menu1 = bot.menu(IDELabel.Menu.WINDOW);
- SWTBotMenu menu2 = menu1.menu(IDELabel.Menu.SHOW_VIEW);
- menu2.menu(IDELabel.Menu.OTHER).click();
+ return SWTEclipseExt.showView(bot, type);
+ }
+ /**
+ * Show view static version
+ *
+ * @param type
+ */
+ public static SWTBot showView(SWTBotExt bot,ViewType type) {
+ SWTBotMenu menu1 = bot.menu(IDELabel.Menu.WINDOW);
+ SWTBotMenu menu2 = menu1.menu(IDELabel.Menu.SHOW_VIEW);
+ menu2.menu(IDELabel.Menu.OTHER).click();
- bot.tree().expandNode(type.getGroupLabel()).expandNode(
- type.getViewLabel()).select();
- bot.button(IDELabel.Button.OK).click();
+ bot.tree().expandNode(type.getGroupLabel()).expandNode(
+ type.getViewLabel()).select();
+ bot.button(IDELabel.Button.OK).click();
- SWTBot viewBot = bot.viewByTitle(type.getViewLabel()).bot();
- return viewBot;
- }
+ SWTBot viewBot = bot.viewByTitle(type.getViewLabel()).bot();
+ return viewBot;
+ }
// ------------------------------------------------------------
// Perspective related methods
@@ -562,5 +573,91 @@
public void hideWarningIfDisplayed() {
SWTEclipseExt.hideWarningIfDisplayed(bot);
}
+ /**
+ * Returns true when projectName is present in Package Explorer
+ * @param projectName
+ * @return
+ */
+ public boolean isProjectInPackageExplorer(String projectName) {
+ return SWTEclipseExt.isProjectInPackageExplorer(bot,projectName);
+ }
+ /**
+ * Returns true when projectName is present in Package Explorer static version
+ * @param bot
+ * @param projectName
+ * @return
+ */
+ public static boolean isProjectInPackageExplorer(SWTBotExt bot,String projectName) {
+ boolean found = false;
+
+ SWTBot innerBot = SWTEclipseExt.showView(bot,ViewType.PACKAGE_EXPLORER);
+ SWTBotTree tree = innerBot.tree();
+ try {
+ tree.getTreeItem(projectName);
+ found = true;
+ } catch (WidgetNotFoundException e) {
+ }
+ return found;
+ }
+ /**
+ * Returns Tree Item with specified label and located on path
+ * @param tree
+ * @param treeItemText
+ * @param path
+ * @return
+ */
+ public static SWTBotTreeItem getTreeItemOnPath(SWTBotTree tree,String treeItemText,
String[] path) {
+ SWTBotTreeItem parentTreeItem = null;
+ SWTBotTreeItem treeItem = null;
+ if (path != null && path.length > 0){
+ parentTreeItem = tree.expandNode(path[0]);
+ for (int index = 1 ; index < path.length ; index++){
+ parentTreeItem = parentTreeItem.expandNode(path[index]);
+ }
+ treeItem = parentTreeItem.getNode(treeItemText);
+ }
+ else{
+ treeItem = tree.getTreeItem(treeItemText);
+ }
+ return treeItem;
+ }
+ /**
+ * Choose Run As Java Application menu for specified Tree Item
+ * @param treeItem
+ */
+ public void runTreeItemAsJavaApplication(SWTBotTreeItem treeItem){
+ treeItem.select();
+ treeItem.click();
+
SWTEclipseExt.getMenuFromSubmenu(bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RUN_AS),
+ IDELabel.Menu.RUN_AS_JAVA_APPLICATION).click();
+ System.out.println("stop");
+ }
+ /**
+ * Search for Menu Item with Run on Server substring within label
+ * @param subMenu
+ * @return
+ */
+ public static SWTBotMenu getMenuFromSubmenu(SWTBotMenu subMenu, String
menuLabelTextToContain){
+ final SWTBotMenu subMenuToSearch = subMenu;
+ final String stringToSearchFor = menuLabelTextToContain;
+ final MenuItem menuItem = UIThreadRunnable
+ .syncExec(new WidgetResult<MenuItem>() {
+ public MenuItem run() {
+ int menuItemIndex = 0;
+ MenuItem menuItem = null;
+ final MenuItem[] menuItems = subMenuToSearch.widget.getMenu().getItems();
+ while (menuItem == null && menuItemIndex < menuItems.length){
+ if (menuItems[menuItemIndex].getText().indexOf(stringToSearchFor) > - 1){
+ menuItem = menuItems[menuItemIndex];
+ }
+ else{
+ menuItemIndex++;
+ }
+ }
+ return menuItem;
+ }
+ });
+ return new SWTBotMenu(menuItem);
+ }
}
\ No newline at end of file
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-08
12:26:40 UTC (rev 21337)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTUtilExt.java 2010-04-08
12:37:49 UTC (rev 21338)
@@ -483,4 +483,22 @@
}
}
+ /**
+ * Delete directory from directoryLocation
+ * @param directoryLocation
+ */
+ public static void deleteDirectory(String directoryLocation){
+ File directory = new File (directoryLocation);
+ if (directory.exists()){
+ if (directory.isDirectory()){
+ for (File childFile :directory.listFiles()) {
+ SWTUtilExt.deleteDirectory(childFile.getAbsolutePath());
+ }
+ directory.delete();
+ }
+ else{
+ directory.delete();
+ }
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-04-08
12:26:40 UTC (rev 21337)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-04-08
12:37:49 UTC (rev 21338)
@@ -56,12 +56,12 @@
public static final String STRUTS_PROJECT = "Struts Project";
public static final String PREFERENCES = "Preferences";
public static final String JBT_REMOVE_STRUTS_CAPABILITIES = "Remove Struts
Capabilities";
- public static final String ADD_STRUTS_CAPABILITIES = "Add Struts
Capabilities...";
- public static final String WEB_PROJECT_JBT_STRUTS = "JBoss Tools Struts";
- public static final String RUN = "Run";
- public static final String RUN_ON_SERVER = "Run on Server";
- public static final String ADD_AND_REMOVE="Add and Remove...";
-
+ public static final String ADD_STRUTS_CAPABILITIES = "Add Struts
Capabilities...";
+ public static final String WEB_PROJECT_JBT_STRUTS = "JBoss Tools Struts";
+ public static final String RUN = "Run";
+ public static final String RUN_ON_SERVER = "Run on Server";
+ public static final String ADD_AND_REMOVE="Add and Remove...";
+ public static final String RUN_AS_JAVA_APPLICATION="Java Application";
}
public class Button {
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java 2010-04-08
12:26:40 UTC (rev 21337)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/PackageExplorer.java 2010-04-08
12:37:49 UTC (rev 21338)
@@ -1,9 +1,9 @@
package org.jboss.tools.ui.bot.ext.view;
import org.eclipse.swtbot.swt.finder.SWTBot;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
/**
@@ -21,4 +21,16 @@
viewBot.tree().expandNode(projectName).select();
}
+ /**
+ * Selects Tree Item within Package Explorer
+ * @param treeItemText
+ * @param path
+ * @return
+ */
+ public SWTBotTreeItem selectTreeItem(String treeItemText, String[] path) {
+ return
SWTEclipseExt.getTreeItemOnPath(viewByTitle(IDELabel.View.PACKAGE_EXPLORER).bot().tree(),
+ treeItemText, path)
+ .select();
+ }
+
}