Author: vpakan(a)redhat.com
Date: 2010-08-06 02:36:56 -0400 (Fri, 06 Aug 2010)
New Revision: 23961
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotTableExt.java
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.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/types/ViewType.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/META-INF/MANIFEST.MF
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/JspFileEditingTest.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java
Log:
Extend Jsp File Editing SWTBot Test
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java 2010-08-06
06:34:01 UTC (rev 23960)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -2,11 +2,14 @@
import java.awt.AWTException;
import java.awt.Robot;
+import java.awt.event.KeyEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
+import org.jboss.tools.ui.bot.ext.Timing;
public class KeyboardHelper {
private static Robot robot = null;
@@ -28,6 +31,17 @@
}
/**
+ * Simulate pressing of keys with keyCodes via SWT
+ * @param display
+ * @param keyCodes
+ */
+ public static void pressKeyCodes (Display display , byte[] keyCodes){
+ for (byte keyCode : keyCodes){
+ KeyboardHelper.pressKeyCode(display,keyCode);
+ SWTUtils.sleep(Timing.time1S());
+ }
+ }
+ /**
* Simulate pressing of key with keyCode via AWT
* @param awtKeyCode
*/
@@ -57,4 +71,46 @@
throw new RuntimeException(e);
}
}
+ /**
+ * Simulate typing of key with keyCode via AWT
+ * @param awtKeyCode
+ */
+ public static void typeKeyCodeUsingAWT (int awtKeyCode){
+ KeyboardHelper.pressKeyCodeUsingAWT(awtKeyCode);
+ KeyboardHelper.releaseKeyCodeUsingAWT(awtKeyCode);
+ }
+ /**
+ * Simulate typing of basic string via AWT
+ * @param textkeyCodes - string which can contain only basic characters 0..9, A..Z,
a..z
+ */
+ public static void typeBasicStringUsingAWT (String textKeyCodes){
+ for (int index = 0 ; index < textKeyCodes.length() ; index++){
+ char ch = textKeyCodes.charAt(index);
+ int keyCode = getAWTKeyCode (ch);
+ boolean pressShift = (ch >= 'A' && ch <= 'Z');
+ if (pressShift){
+ KeyboardHelper.pressKeyCodeUsingAWT(KeyEvent.VK_SHIFT);
+ }
+ KeyboardHelper.typeKeyCodeUsingAWT(keyCode);
+ if (pressShift){
+ KeyboardHelper.releaseKeyCodeUsingAWT(KeyEvent.VK_SHIFT);
+ }
+ KeyboardHelper.robot.delay(Timing.time1S());
+ }
+ }
+
+ public static int getAWTKeyCode (char ch){
+ int result = KeyEvent.VK_UNDEFINED;
+ try {
+ result = ReflectionsHelper.getPrivateFieldValue(KeyEvent.class,
+ "VK_" + String.valueOf(ch).toUpperCase(),
+ null,
+ Integer.class);
+ } catch (SecurityException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (NoSuchFieldException e) {
+ } catch (IllegalAccessException e) {
+ }
+ return result;
+ }
}
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -0,0 +1,39 @@
+ /*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ui.bot.ext.helper;
+
+import java.lang.reflect.Field;
+
+import org.apache.log4j.Logger;
+/**
+ * Helper to use Reflections functionality
+ * @author Vladimir Pakan
+ *
+ */
+public class ReflectionsHelper {
+ protected static final Logger log = Logger.getLogger(ReflectionsHelper.class);
+
+ @SuppressWarnings("unchecked")
+ public static <T> T getPrivateFieldValue (Class<?> clazz , String fieldName
,
+ Object instance, Class<T> resultClazz) throws SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
+ Field field = clazz.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ if (value != null){
+ return (T)value;
+ }
+ else{
+ return null;
+ }
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotTableExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotTableExt.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotTableExt.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+
+ * Copyright (c) 2007-2010 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ui.bot.ext.parts;
+
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.jboss.tools.ui.bot.ext.Timing;
+
+/**
+ * Extends Table Component
+ * @author vlado pakan
+ *
+ */
+public class SWTBotTableExt extends AbstractSWTBotControl<Table> {
+
+ private SWTBotTable swtBotTable = null;
+
+ private SWTBotTableExt(Table table) throws WidgetNotFoundException {
+ super(table);
+ }
+
+ public SWTBotTableExt(SWTBotTable swtBotTable) throws WidgetNotFoundException {
+ this(swtBotTable.widget);
+ this.swtBotTable = swtBotTable;
+ }
+ /**
+ * Sets value of table cell editable via Text Cell Editor on position specified by row
and column
+ * @param newValue - new value of the cell
+ * @param row - zero based row index
+ * @param column - zero based column index
+ * @param oldValue - old value of the cell
+ * @param bot - bot containing table
+ */
+ public void setTableCellWithTextEditorText(String newValue,
+ int row , int column,
+ String oldValue,
+ SWTBot bot){
+
+ swtBotTable.click(row, column);
+ bot.sleep(Timing.time1S());
+ bot.text(oldValue, 0).setText(newValue);
+
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotTableExt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-08-06
06:34:01 UTC (rev 23960)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/IDELabel.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -98,6 +98,7 @@
public static final String EDIT = "Edit...";
public static final String ADD_WITHOUT_DOTS = "Add";
public static final String DROOLS_WORKBENCH = "Drools workbench";
+ public static final String REFRESH = "Refresh";
}
public class Shell {
@@ -137,6 +138,7 @@
public static final String SHOW_VIEW = "Show View";
public static final String PROPERTIES_FOR = "Properties for";
public static final String COPY_FILE_FROM_GUVNOR_TO_PACKAGE_EXPLORER = "File
Operation";
+ public static final String INSERT_TAG = "Insert Tag";
}
public class EntityGroup {
@@ -196,6 +198,7 @@
public static final String GUVNOR_REPOSITORIES = "Guvnor Repositories";
public static final String GUVNOR_RESOURCE_HISTORY = "Guvnor Resource
History";
public static final String PROPERTIES = "Properties";
+ public static final String JBOSS_TOOLS_PALETTE = "JBoss Tools Palette";
}
public class ViewGroup {
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java 2010-08-06
06:34:01 UTC (rev 23960)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/types/ViewType.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -20,7 +20,7 @@
public enum ViewType {
PACKAGE_EXPLORER, PROJECT_EXPLORER, WELCOME, DATA_SOURCE_EXPLORER,
SERVERS,WEB_PROJECTS,PROBLEMS,DEBUG,GUVNOR_REPOSITORIES,PROPERTIES,
- GUVNOR_RESOURCE_HISTORY;
+ GUVNOR_RESOURCE_HISTORY,JBOSS_TOOLS_PALETTE;
public String getGroupLabel() {
@@ -36,6 +36,7 @@
case GUVNOR_REPOSITORIES: viewLabel = IDELabel.ViewGroup.GUVNOR; break;
case PROPERTIES: viewLabel = IDELabel.ViewGroup.GENERAL; break;
case GUVNOR_RESOURCE_HISTORY: viewLabel = IDELabel.ViewGroup.GUVNOR; break;
+ case JBOSS_TOOLS_PALETTE: viewLabel = IDELabel.ViewGroup.JBOSS_TOOLS_WEB; break;
default: fail("Unknown View Type");
}
return viewLabel;
@@ -54,6 +55,7 @@
case GUVNOR_REPOSITORIES: viewLabel = IDELabel.View.GUVNOR_REPOSITORIES; break;
case PROPERTIES: viewLabel = IDELabel.View.PROPERTIES; break;
case GUVNOR_RESOURCE_HISTORY: viewLabel = IDELabel.View.GUVNOR_RESOURCE_HISTORY;
break;
+ case JBOSS_TOOLS_PALETTE: viewLabel = IDELabel.View.JBOSS_TOOLS_PALETTE; break;
default: fail("Unknown View Type");
}
return viewLabel;
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/META-INF/MANIFEST.MF 2010-08-06
06:34:01 UTC (rev 23960)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/META-INF/MANIFEST.MF 2010-08-06
06:36:56 UTC (rev 23961)
@@ -28,7 +28,10 @@
org.jboss.tools.vpe.html,
org.jboss.tools.vpe.jsp,
org.jboss.tools.vpe.resref,
- org.jboss.tools.vpe.ui.palette
+ org.jboss.tools.vpe.ui.palette,
+ org.eclipse.swtbot.eclipse.gef.finder;bundle-version="2.0.0",
+ org.eclipse.gef;bundle-version="3.6.0",
+ org.jboss.tools.common.model.ui;bundle-version="3.2.0"
Eclipse-RegisterBuddy: org.apache.log4j
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/JspFileEditingTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/JspFileEditingTest.java 2010-08-06
06:34:01 UTC (rev 23960)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/JspFileEditingTest.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -11,61 +11,112 @@
******************************************************************************/
package org.jboss.tools.vpe.ui.bot.test.editor;
-
-import java.io.File;
-import java.io.IOException;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
import org.jboss.tools.ui.bot.ext.Timing;
-import org.jboss.tools.ui.bot.ext.helper.FileHelper;
+import org.jboss.tools.ui.bot.ext.helper.KeyboardHelper;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotTableExt;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.jboss.tools.vpe.ui.bot.test.tools.SWTBotWebBrowser;
import org.mozilla.interfaces.nsIDOMNode;
/**
- * Tests large XHTML file editing
+ * Tests JSP file editing and synchronization between Source Editor and Visual Editor
* @author vlado pakan
*
*/
public class JspFileEditingTest extends VPEEditorTestCase {
+ private SWTBotExt botExt = null;
+
public JspFileEditingTest() {
super();
+ botExt = new SWTBotExt();
}
public void testJspFileEditing(){
- try{
- String resourceWebContentLocation = getPathToResources("WebContent");
- FileHelper.copyFilesBinaryRecursively(new File(resourceWebContentLocation),
- new File(FileHelper.getProjectLocation(JBT_TEST_PROJECT_NAME,
bot),"WebContent"),
- null);
- }catch (IOException ioe){
- throw new RuntimeException("Unable to copy necessary files from plugin's
resources directory",ioe);
- }
- bot.menu(IDELabel.Menu.FILE).menu(IDELabel.Menu.REFRESH).click();
- bot.sleep(Timing.time1S());
eclipse.maximizeActiveShell();
- openPage();
- openPalette();
- SWTBotWebBrowser swtBotWebBrowser = new SWTBotWebBrowser(TEST_PAGE,bot);
+
+ insertTagUsingContextMenu();
+ insertTagUsingPalette();
- nsIDOMNode node = swtBotWebBrowser.getDomNodeByTagName("INPUT",1);
-
- swtBotWebBrowser.selectDomNode(node,0);
- bot.sleep(Timing.time1S());
- swtBotWebBrowser.clickContextMenu(node, SWTBotWebBrowser.INSERT_AFTER_MENU_LABEL,
- SWTBotWebBrowser.JSF_MENU_LABEL,
- SWTBotWebBrowser.HTML_MENU_LABEL,
- SWTBotWebBrowser.H_OUTPUT_TEXT_TAG_MENU_LABEL);
-
- final SWTBotEclipseEditor jspTextEditor =
bot.editorByTitle(TEST_PAGE).toTextEditor();
+ }
+ /**
+ * Inserts tag to html page using Context Menu of Visual Editor
+ */
+ private void insertTagUsingContextMenu() {
+
+ openPage();
+ SWTBotWebBrowser swtBotWebBrowser = new SWTBotWebBrowser(TEST_PAGE, botExt);
+ nsIDOMNode node = swtBotWebBrowser.getDomNodeByTagName("INPUT", 1);
+ swtBotWebBrowser.selectDomNode(node, 0);
+ botExt.sleep(Timing.time1S());
+
+ swtBotWebBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.INSERT_AFTER_MENU_LABEL,
+ SWTBotWebBrowser.JSF_MENU_LABEL, SWTBotWebBrowser.HTML_MENU_LABEL,
+ SWTBotWebBrowser.H_OUTPUT_TEXT_TAG_MENU_LABEL);
+
+ final SWTBotEclipseEditor jspTextEditor = botExt.editorByTitle(TEST_PAGE)
+ .toTextEditor();
jspTextEditor.save();
// Check if tag h:outputText was properly added
String editorText = jspTextEditor.getText();
- assertTrue("File " + TEST_PAGE + " has to contain string
'<h:outputText/>' but it doesn't",
- editorText.contains("<h:outputText/>"));
- }
+ assertTrue("File " + TEST_PAGE
+ + " has to contain string '<h:outputText/>' but it
doesn't",
+ editorText.contains("<h:outputText/>"));
+ }
+ /**
+ * Inserts tag to html page using JBoss Tools Palette
+ */
+ private void insertTagUsingPalette(){
+
+ openPage();
+ openPalette();
+
+ SWTBotWebBrowser swtBotWebBrowser = new SWTBotWebBrowser(TEST_PAGE, botExt);
+ nsIDOMNode node = swtBotWebBrowser.getDomNodeByTagName("INPUT", 1);
+ swtBotWebBrowser.selectDomNode(node, 0);
+ botExt.sleep(Timing.time1S());
+
+ swtBotWebBrowser.activatePaletteTool("outputText");
+ SWTBot dialogBot = botExt.shell(IDELabel.Shell.INSERT_TAG).activate().bot();
+ SWTBotTable swtBotTable = dialogBot.table();
+ String outputTextValue = "123 !! Test value !! 321";
+ new SWTBotTableExt(swtBotTable).setTableCellWithTextEditorText(
+ outputTextValue, swtBotTable.indexOf("value"), 1, "",
dialogBot);
+ dialogBot.button(IDELabel.Button.FINISH).click();
+ final SWTBotEclipseEditor jspTextEditor = botExt.editorByTitle(TEST_PAGE)
+ .toTextEditor();
+ jspTextEditor.save();
+ botExt.toolbarButtonWithTooltip(IDELabel.Button.REFRESH).click();
+ botExt.sleep(Timing.time1S());
+ String editorText = jspTextEditor.getText();
+ String testText = "<h:outputText value=\"" + outputTextValue +
"\"/>";
+ assertTrue("File " + TEST_PAGE + " has to contain string '" +
testText
+ + "' but it doesn't", editorText.contains(testText));
+ // Insert text via Visual Editor to inserted h:outputText tag
+ node = swtBotWebBrowser.getDomNodeByTagName(
+ swtBotWebBrowser.getNsIDOMDocument(), "#text", 6);
+ botExt.sleep(Timing.time2S());
+ swtBotWebBrowser.selectDomNode(node, 5);
+ String insertString = "ab9876CD";
+ KeyboardHelper.typeBasicStringUsingAWT(insertString);
+ botExt.sleep(Timing.time2S());
+ jspTextEditor.save();
+ editorText = jspTextEditor.getText();
+ outputTextValue = outputTextValue.substring(0, 5) + insertString
+ + outputTextValue.substring(5);
+ testText = "<h:outputText value=\"" + outputTextValue +
"\"/>";
+ assertTrue("File " + TEST_PAGE + " has to contain string '" +
testText
+ + "' but it doesn't", editorText.contains(testText));
+ jspTextEditor.close();
+ }
+
@Override
protected void closeUnuseDialogs() {
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2010-08-06
06:34:01 UTC (rev 23960)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2010-08-06
06:36:56 UTC (rev 23961)
@@ -13,28 +13,44 @@
import static org.junit.Assert.assertNotNull;
-import java.lang.reflect.Field;
import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.palette.PaletteEntry;
+import org.eclipse.gef.palette.ToolEntry;
+import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.eclipse.gef.finder.finders.PaletteFinder;
+import org.eclipse.swtbot.eclipse.gef.finder.matchers.ToolEntryLabelMatcher;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
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.ui.IEditorReference;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.common.model.ui.views.palette.PaletteCreator;
+import org.jboss.tools.common.model.ui.views.palette.PaletteViewPart;
import org.jboss.tools.jst.jsp.editor.IVisualEditor;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
import org.jboss.tools.ui.bot.ext.Timing;
import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
+import org.jboss.tools.ui.bot.ext.helper.ReflectionsHelper;
import org.jboss.tools.ui.bot.ext.parts.ObjectMultiPageEditorBot;
+import org.jboss.tools.ui.bot.ext.types.ViewType;
import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.mozilla.MozillaEventAdapter;
+import org.jboss.tools.vpe.ui.palette.PaletteAdapter;
import org.jboss.tools.vpe.xulrunner.util.XPCOM;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMEvent;
@@ -69,9 +85,9 @@
private Display display;
private IVisualEditor visualEditor;
private MozillaEditor mozillaEditor;
- private SWTBot bot;
+ private SWTBotExt bot;
- public SWTBotWebBrowser (String title, SWTBot bot){
+ public SWTBotWebBrowser (String title, SWTBotExt bot){
ObjectMultiPageEditorBot objectMultiPageEditorBot = new
ObjectMultiPageEditorBot(title);
IEditorReference ref = objectMultiPageEditorBot.getEditorReference();
JSPMultiPageEditor multiPageEditor = null;
@@ -81,7 +97,7 @@
assertNotNull(multiPageEditor);
this.bot = bot;
this.visualEditor = multiPageEditor.getVisualEditor();
- this.mozillaEditor =
((VpeEditorPart)multiPageEditor.getVisualEditor()).getVisualEditor();
+ this.mozillaEditor = ((VpeEditorPart)visualEditor).getVisualEditor();
this.display = getBrowser().getDisplay();
}
@@ -90,7 +106,6 @@
* @param node
* @param depth
*/
- @SuppressWarnings("unused")
private static void displayNsIDOMNode(nsIDOMNode node , int depth) {
System.out.println("");
System.out.print(fillString(' ', depth) + "<" +
node.getNodeName() + " ");
@@ -330,11 +345,11 @@
parent = parent.getParent();
}
try {
- Field menusField = Decorations.class.getDeclaredField("menus");
- menusField.setAccessible(true);
- Object menusObject = menusField.get(parent);
- if (menusObject != null){
- Menu[] menus = (Menu[])menusObject;
+ Menu[] menus = ReflectionsHelper.getPrivateFieldValue(Decorations.class,
+ "menus",
+ parent,
+ Menu[].class);
+ if (menus != null){
MenuItem topMenuItem = null;
int index = menus.length - 1;
while (topMenuItem == null && index >= 0){
@@ -372,5 +387,102 @@
ContextMenuHelper.clickContextMenu(topMenu, menuLabels);
}
+ /**
+ * Returns node corresponding to specified tagName
+ * @param parentNode
+ * @param tagName
+ * @param order - index of tagName tag in DOM model from all tagName nodes contained in
model
+ * @return
+ */
+ public nsIDOMNode getDomNodeByTagName(nsIDOMNode parentNode , String tagName, Integer
order){
+ List<nsIDOMNode> nodes = getDomNodesByTagName(parentNode,tagName);
+ nsIDOMNode result = null;
+ if (nodes != null && nodes.size() > order){
+ result = nodes.get(order);
+ }
+ return result;
+ }
+ /**
+ * Recursively search for node with specified tagName
+ * @param parentNode
+ * @param tagName
+ * @return
+ */
+ public List<nsIDOMNode> getDomNodesByTagName(nsIDOMNode parentNode , String
tagName){
+ LinkedList<nsIDOMNode> result = new LinkedList<nsIDOMNode>();
+ if (parentNode.getNodeName().equals(tagName)){
+ result.add(parentNode);
+ }
+ nsIDOMNodeList children = parentNode.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ nsIDOMNode child = children.item(i);
+ // leave out empty text nodes in test dom model
+ if ((child.getNodeType() == Node.TEXT_NODE)
+ && ((child.getNodeValue() == null) || (child.getNodeValue().trim()
+ .length() == 0)))
+ continue;
+ result.addAll(getDomNodesByTagName(child, tagName));
+
+ }
+ return result;
+
+ }
+ /**
+ * Activate JBoss Tools Palette Tool with specified Label
+ * @param toolLabel
+ */
+ public void activatePaletteTool (String toolLabel){
+
+ SWTEclipseExt.showView(bot, ViewType.JBOSS_TOOLS_PALETTE);
+
+ IViewReference ref = UIThreadRunnable.syncExec(new Result<IViewReference>() {
+ public IViewReference run() {
+ IViewReference ref = null;
+ IViewReference[] viewReferences = null;
+ viewReferences =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
+ for (IViewReference reference : viewReferences) {
+ if (reference.getTitle().equals("JBoss Tools Palette")){
+ return reference;
+ }
+ }
+ return ref;
+ }
+ });
+ // Find Palette Viewer dirty way
+ PaletteViewPart pvp = (PaletteViewPart)ref.getPart(true);
+ try {
+ PaletteCreator pc = ReflectionsHelper.getPrivateFieldValue(PaletteViewPart.class,
+ "paletteCreator",
+ pvp,
+ PaletteCreator.class);
+ PaletteAdapter pa = ReflectionsHelper.getPrivateFieldValue(PaletteCreator.class,
+ "paletteAdapter",
+ pc,
+ PaletteAdapter.class);
+ PaletteViewer paletteViewer =
ReflectionsHelper.getPrivateFieldValue(PaletteAdapter.class,
+ "viewer",
+ pa,
+ PaletteViewer.class);
+
+ EditDomain ed = new EditDomain();
+ ed.setPaletteViewer(paletteViewer);
+ ed.setPaletteRoot(paletteViewer.getPaletteRoot());
+ PaletteFinder pf = new PaletteFinder(ed);
+ ToolEntryLabelMatcher telm = new ToolEntryLabelMatcher(toolLabel);
+ PaletteEntry peJsfHtml = pf.findEntries(telm).get(0);
+ // Activate outputText Tool from Palette
+ paletteViewer.setActiveTool((ToolEntry)peJsfHtml);
+ } catch (SecurityException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
}