[embjopr-commits] EMBJOPR SVN: r835 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5.
embjopr-commits at lists.jboss.org
embjopr-commits at lists.jboss.org
Wed Nov 4 21:18:28 EST 2009
Author: ozizka at redhat.com
Date: 2009-11-04 21:18:28 -0500 (Wed, 04 Nov 2009)
New Revision: 835
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java
Log:
* RootNodeTest refactored - original pre-EJTT code dumped, EJTT used instead.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java 2009-11-05 01:33:44 UTC (rev 834)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java 2009-11-05 02:18:28 UTC (rev 835)
@@ -1,17 +1,16 @@
package org.jboss.jopr.jsfunit.as5;
import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
-import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
-import java.net.URL;
import java.net.UnknownHostException;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
import org.jboss.jopr.jsfunit.EmbjoprTestCase;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.TabContentBox;
/**
@@ -28,10 +27,10 @@
try{
- new NavTree().clickRootNode();
+ ejtt.navTree.clickRootNode();
//if( !tabMenu.isTabActive("Summary")) // we can click either
- tabMenu.clickTab("Summary");
+ ejtt.tabMenu.clickTab("Summary");
//HtmlElement box = tabMenu.getTabContentBox().getElement();
@@ -92,15 +91,15 @@
try{
- navTree.clickRootNode();
+ ejtt.navTree.clickRootNode();
- if( tabMenu.isTabDisabled("Control") )
+ if( ejtt.tabMenu.isTabDisabled("Control") )
fail("Root (server) node's Control tab is disabled.");
- tabMenu.clickTab("Control");
- TabContentBox box = tabMenu.getTabContentBox();
+ ejtt.tabMenu.clickTab("Control");
+ TabContentBox box = ejtt.tabMenu.getTabContentBox();
- HtmlButtonInput button = box.getButtonByLabel("Manual Autodiscovery");
+ HtmlButtonInput button = box.getButtonInputByLabel("Manual Autodiscovery");
button.click();
// TODO: check the result.
@@ -124,15 +123,15 @@
try{
- navTree.clickRootNode();
+ ejtt.navTree.clickRootNode();
- if( tabMenu.isTabDisabled("Control") )
+ if( ejtt.tabMenu.isTabDisabled("Control") )
fail("Root (server) node's Control tab is disabled.");
- tabMenu.clickTab("Control");
- TabContentBox box = tabMenu.getTabContentBox();
+ ejtt.tabMenu.clickTab("Control");
+ TabContentBox box = ejtt.tabMenu.getTabContentBox();
- HtmlButtonInput button = box.getButtonByLabel("View Process List");
+ HtmlButtonInput button = box.getButtonInputByLabel("View Process List");
button.click();
// TODO: check the result.
@@ -168,7 +167,7 @@
*/
private String getSummaryValue(String name) throws EmbJoprTestException{
- HtmlElement box = tabMenu.getTabContentBox().getElement();
+ HtmlElement box = ejtt.tabMenu.getTabContentBox().getElement();
String xPath = "//td//strong[contains(string(), '"+name+":')]/ancestor::td[1]";
HtmlElement tableCell = (HtmlElement) box.getFirstByXPath(xPath);
if( null == tableCell )
@@ -222,162 +221,4 @@
-
-
-
-
-
- // TODO: Move to EmbJopr base class? Or make some order there?
-
-
- private NavTree navTree = new NavTree();
-
- /**
- * Inner class to encapsulate navigation tree operations.
- */
- class NavTree {
-
- private void clickRootNode() throws IOException, EmbJoprTestException {
- DomElement element = (DomElement)client.getElement("navTreeForm");
- if( null == element )
- throw new HtmlElementNotFoundException("Can't find #navTreeForm.");
-
- // ID changes upon core build?
- //HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
-
- // javax.xml.transform.TransformerException: Can't find function: matches
- //HtmlAnchor rootNodeLink = element.getFirstByXPath(
- // "//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
-
-
- String xPath = "//a[ starts-with( @id, 'navTreeForm:navTree:' ) " +
- " and contains( @id, '::homeLink' ) ]"; // XPath 2.0: ends-with( @id, '::homeLink' )
- HtmlAnchor rootNodeLink = element.getFirstByXPath(xPath);
-
- if( null == rootNodeLink )
- throw new HtmlElementNotFoundException("Root node not found using XPath: "+xPath);
-
- rootNodeLink.click();
- }
-
- }
-
-
-
-
-
- private final TabMenu tabMenu = new TabMenu();
-
- /**
- * Inner class to encapsulate tab menu operations.
- */
- class TabMenu {
-
- public TabContentBox getTabContentBox() throws EmbJoprTestException {
-
- HtmlElement contentElement = (HtmlElement) client.getElement("content");
- HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
- if( null == tabContentBox )
- throw new EmbJoprTestException("Tab content box not found using div[@class='tabmenubox'] XPath");
-
- return new TabContentBox(tabContentBox);
- }
-
- public StyledElement getTab( String label ) throws EmbJoprTestException {
-
- DomElement element = (DomElement)client.getElement("tabmenu");
- String xPath = "ul/li/span[normalize-space(string())='"+label+"'] | ul/li/a[normalize-space(string())='"+label+"']";
- StyledElement tabContent = element.getFirstByXPath(xPath);
-
- if( null == tabContent )
- throw new EmbJoprTestException("Tab '"+label+" not found using XPath '"+xPath+"'");
-
- return tabContent;
-
- }
-
- public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
-
- StyledElement tabContent = getTab(label);
- return "span".equals( tabContent.getTagName() )
- && tabContent.getClassAttribute().contains("active");
- }
-
-
- public boolean isTabDisabled( String label ) throws EmbJoprTestException {
- StyledElement tabContent = getTab(label);
- return "span".equals( tabContent.getTagName() )
- && tabContent.getClassAttribute().contains("disabled");
- }
-
- public void clickTab( String label ) throws IOException, EmbJoprTestException {
-
- StyledElement tabContent = getTab(label);
-
- //if( !"a".equals( tabContent.getTagName() ) )
- //if( !( tabContent instanceof HtmlAnchor ) )
- // throw new AssertException("Tab is not an anchor: "+label);
-
- if( !( tabContent instanceof ClickableElement ) )
- throw new EmbJoprTestException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
-
- ((ClickableElement)tabContent).click();
-
- }
-
- }
-
-
- /**
- * Inner class for manipulation with tab content box.
- */
- class TabContentBox {
-
- private HtmlElement box;
- private URL validForURL;
- private String validForDate;
-
- public HtmlElement getElement() { return box; }
-
-
-
- public TabContentBox(HtmlElement box) {
- this.box = box;
-
- // TODO: Check whether the page changed;
- this.validForDate = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
- this.validForURL = client.getContentPage().getWebResponse().getUrl();
- }
-
-
- public void checkIfStillValid() throws ActionOutOfSyncException {
-
- String validForDate = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
- URL validForURL = client.getContentPage().getWebResponse().getUrl();
-
- if( !validForDate.equals(this.validForDate) ||
- !validForURL.equals(this.validForURL) )
- {
- throw new ActionOutOfSyncException(
- "This tab content box was created from another page and is not valid now.");
- }
- }
-
- public HtmlButtonInput getButtonByLabel( String label )
- throws HtmlElementNotFoundException, ActionOutOfSyncException {
-
- checkIfStillValid();
-
- HtmlButtonInput button = this.box.getFirstByXPath("//input[@value='"+label+"']");
- if( null == button )
- throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
-
- return button;
-
- }
-
- }
-
-
-
}
More information about the embjopr-commits
mailing list