[embjopr-commits] EMBJOPR SVN: r161 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Thu Feb 19 22:08:01 EST 2009


Author: ozizka at redhat.com
Date: 2009-02-19 22:08:01 -0500 (Thu, 19 Feb 2009)
New Revision: 161

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
Log:
 * Pagination controls

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-20 02:07:08 UTC (rev 160)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-20 03:08:01 UTC (rev 161)
@@ -21,6 +21,7 @@
  */
 package org.jboss.jopr.jsfunit;
 
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
 import java.util.List;
 import java.util.Set;
 import javax.management.*;
@@ -701,9 +702,100 @@
 		}
 
 
-	}// inner class ContentTableRow 
+	}// inner class ContentTableRow
 
 
+
+	/**
+	 *  Pagination control
+	 */
+	protected class ContentBoxPagination {
+
+		//private HtmlElement element;
+		//public HtmlElement getElement() {			return element;		}
+
+		private static final String ID_PAGE_CONTROLS = "categorySummaryForm:dataTableScroller";
+		private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
+
+		protected HtmlDivision getPageContols(){
+			return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
+		}
+
+		protected HtmlSelect getPageSizeSelect(){
+			return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
+		}
+
+
+		protected HtmlSpan getGoSpan( String spanLabel ){
+			String xPath = ".//span[normalize-string() = '"+spanLabel+"']";
+			return (HtmlSpan) getPageContols().getFirstByXPath(xPath);
+		}
+
+		protected HtmlTableCell getGoPage( int pageNumber ) throws HtmlElementNotFoundException{
+			String xPath = ".//td[normalize-string() = '"+pageNumber+"']";
+			HtmlElement td = getPageContols().getFirstByXPath(xPath);
+			if( null == td )
+				throw new HtmlElementNotFoundException(
+								"Page number "+pageNumber+" not found. Try 1 - "+this.getPageCount());
+			return (HtmlTableCell) td;
+		}
+
+
+		public void goFirst() throws IOException{
+			getGoSpan("First").click();
+		}
+
+		public void goPrev() throws IOException{
+			getGoSpan("Prev").click();
+		}
+
+		public void goNext() throws IOException{
+			getGoSpan("Next").click();
+		}
+
+		public void goLast() throws IOException{
+			getGoSpan("Last").click();
+		}
+
+		public void goPage( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+			getGoPage(pageNumber).click();
+		}
+
+
+		public boolean isPageActive( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+			return !getGoPage(pageNumber).getStyleAttribute().contains("-inact");
+		}
+
+		public int getPageCount(){
+			String xPath = ".//td[ count(./*) = 0  and  normalize-string() > 0 ]";
+			List<?> elements = getPageContols().getByXPath(xPath);
+			return elements.size();
+		}
+
+		public void setItemsPerPage( int num ) throws HtmlElementNotFoundException{
+			String optionValue = ""+num;
+			HtmlSelect pageSizeSelect = getPageSizeSelect();
+
+			try{
+				pageSizeSelect.getOptionByValue(optionValue);
+			}
+			catch( ElementNotFoundException ex ){
+				StringBuilder sb = new StringBuilder(pageSizeSelect.getOptionSize());
+				for( HtmlOption opt : pageSizeSelect.getOptions() ){
+					sb.append(" ").append(opt.getValueAttribute());
+				}
+				String possibleOptions = sb.toString().trim().replace(" ", ", ");
+
+				throw new HtmlElementNotFoundException("Specified option is invalid. Try one of: "+possibleOptions, ex);
+			}
+			
+			pageSizeSelect.setSelectedAttribute(optionValue, true);
+		}
+
+	}
+
+
+
 }// ApplicationTestBaseAS5 
 
 




More information about the embjopr-commits mailing list