commit cb03d03fd1ab09a7881116a5fa660e0dbfe71afa
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed Jun 1 15:12:15 2011 +0000

    using PageFactory

diff --git a/.gitattributes b/.gitattributes
index 4ad53bce..ec4e2631 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -258,10 +258,11 @@ modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etax
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/CdmDataPortalSeleniumRCTestBase.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/CdmDataPortalTestBase.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java -text
+modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PolytomousKeyPage.java -text
+modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/selenium/JUnitWebDriverWait.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/selenium/VisibilityOfElementLocated.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/selenium/WebDriverFactory.java -text
-modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/testutils/PolytomousKeyTestTool.java -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/resources/eu/etaxonomy/dataportal/DataPortalTest.properties -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/resources/log4j.properties -text
 modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java -text
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PolytomousKeyPage.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PolytomousKeyPage.java
new file mode 100644
index 00000000..20cfd67f
--- /dev/null
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PolytomousKeyPage.java
@@ -0,0 +1,87 @@
+package eu.etaxonomy.dataportal.pages;
+
+import java.net.MalformedURLException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.openqa.selenium.By;
+import org.openqa.selenium.RenderedWebElement;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.CacheLookup;
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.support.PageFactory;
+
+import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
+
+public class PolytomousKeyPage extends PortalPage{
+
+	public PolytomousKeyPage(WebDriver driver) throws MalformedURLException {
+		super(driver);
+	}
+
+	public static final Logger logger = Logger.getLogger(PolytomousKeyPage.class);
+
+	@FindBy(className="polytomousKey")
+  	@CacheLookup
+	private WebElement keyTable;
+
+	private List<WebElement> keyTableRows;
+
+
+
+	public static class KeyLineData{
+
+		String nodeNumber = null;
+		String edgeText = null;
+		LinkClass linkClass = null;
+		String linkText = null;
+
+
+		public String getNodeNumber() {
+			return nodeNumber;
+		}
+
+		public String getEdgeText() {
+			return edgeText;
+		}
+
+		public LinkClass getLinkClass() {
+			return linkClass;
+		}
+
+		public String getLinkText() {
+			return linkText;
+		}
+
+		public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
+			this.nodeNumber = nodeNumber;
+			this.edgeText = edgeText;
+			this.linkClass = linkClass;
+			this.linkText = linkText;
+		}
+	}
+
+	public enum LinkClass {
+		nodeLinkToNode,
+		nodeLinkToTaxon;
+	}
+
+	public PortalPage followPolytomousKeyLine(int lineIndex, KeyLineData data) {
+
+		keyTableRows = keyTable.findElements(By.xpath("tbody/tr"));
+		WebElement keyEntry = keyTableRows.get(lineIndex);
+		Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
+		Assert.assertEquals("edge text", data.edgeText + data.linkText, keyEntry.findElement(By.className("edge")).getText());
+		WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
+		RenderedWebElement link = (RenderedWebElement)linkContainer.findElement(By.tagName("a"));
+		Assert.assertEquals("link text", data.linkText, link.getText());
+		logger.info("testing " +  data.linkClass.name() + " : " + getInitialUrlBase() + ":" + link.getAttribute("href"));
+		link.click();
+		wait.until(new VisibilityOfElementLocated(By.id("container")));
+
+		return PageFactory.initElements(driver, PortalPage.class);
+	}
+
+}
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java
new file mode 100644
index 00000000..5a97f35e
--- /dev/null
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java
@@ -0,0 +1,70 @@
+package eu.etaxonomy.dataportal.pages;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.log4j.Logger;
+import org.openqa.selenium.RenderedWebElement;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.CacheLookup;
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.support.PageFactory;
+
+import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait;
+
+public class PortalPage {
+
+	public static final Logger logger = Logger.getLogger(PortalPage.class);
+
+	protected WebDriver driver;
+	protected final JUnitWebDriverWait wait;
+	protected URL initialUrl;
+
+	@FindBy(id= "cdm_dataportal.node")
+	@CacheLookup
+	private RenderedWebElement portalContent;
+
+	@FindBy(tagName= "title")
+	@CacheLookup
+	private RenderedWebElement title;
+
+	public PortalPage(WebDriver driver) throws MalformedURLException {
+		this.driver = driver;
+		this.initialUrl = new URL(driver.getCurrentUrl());
+		this.wait = new JUnitWebDriverWait(driver, 25);
+		logger.info("new " + this.getClass().getSimpleName() + " for " + initialUrl);
+	}
+
+	public void goToInitialPage() {
+		driver.get(initialUrl.toString());
+		PageFactory.initElements(driver, this);
+	}
+
+	public String getTitle() {
+		return title.getText();
+	}
+
+	public String getURL() {
+		return driver.getCurrentUrl();
+	}
+
+	/**
+	 * return the <code>scheme://domain:port</code> part of the initial url of this page.
+	 * @return
+	 */
+	public String getInitialUrlBase() {
+		return initialUrl.getProtocol() + "://" + initialUrl.getHost() + initialUrl.getPort();
+	}
+
+	public boolean equals(Object obj) {
+		if (PortalPage.class.isAssignableFrom(obj.getClass())) {
+			PortalPage page = (PortalPage) obj;
+			return this.getTitle().equals(page.getTitle())
+					&& this.getURL().equals(page.getURL());
+
+		} else {
+			return false;
+		}
+	}
+
+}
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/testutils/PolytomousKeyTestTool.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/testutils/PolytomousKeyTestTool.java
deleted file mode 100644
index 5d5b5611..00000000
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/testutils/PolytomousKeyTestTool.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- *
- */
-package eu.etaxonomy.dataportal.testutils;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.junit.Assert;
-import org.openqa.selenium.By;
-import org.openqa.selenium.JavascriptExecutor;
-import org.openqa.selenium.RenderedWebElement;
-import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.WebElement;
-import org.openqa.selenium.support.ui.WebDriverWait;
-
-import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait;
-import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
-import eu.etaxonomy.dataportal.selenium.WebDriverFactory;
-
-/**
- * @author a.kohlbecker
- *
- */
-public class PolytomousKeyTestTool {
-
-	public static final Logger logger = Logger.getLogger(PolytomousKeyTestTool.class);
-
-	Map<Integer, KeyLineData> linesUnderTest; //  = new HashMap<Integer, KeyLineData>();
-	List<WebElement> keyTableRows;
-	private final WebDriver webDriver;
-	private final JUnitWebDriverWait wait;
-
-	public PolytomousKeyTestTool(List<WebElement> keyTableRows, Map<Integer, KeyLineData> linesUnderTest, WebDriver webDriver){
-		this.linesUnderTest = linesUnderTest;
-		this.keyTableRows = keyTableRows;
-		this.webDriver = webDriver;
-		wait = new JUnitWebDriverWait(webDriver, 15);
-	}
-
-	public void runTest(){
-		for(Integer key : linesUnderTest.keySet()){
-			testPolytomousKeyLine(keyTableRows.get(key), linesUnderTest.get(key));
-		}
-		webDriver.close();
-	}
-
-	public static class KeyLineData{
-
-		String nodeNumber = null;
-		String edgeText = null;
-		LinkClass linkClass = null;
-		String linkText = null;
-
-		public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
-			this.nodeNumber = nodeNumber;
-			this.edgeText = edgeText;
-			this.linkClass = linkClass;
-			this.linkText = linkText;
-		}
-
-	}
-
-	public enum LinkClass {
-		nodeLinkToNode,
-		nodeLinkToTaxon;
-	}
-
-	public void testPolytomousKeyLine(WebElement keyEntry, KeyLineData data) {
-		Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
-		Assert.assertEquals("edge text", data.edgeText + data.linkText, keyEntry.findElement(By.className("edge")).getText());
-		WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
-		RenderedWebElement link = (RenderedWebElement)linkContainer.findElement(By.tagName("a"));
-		Assert.assertEquals("link text", data.linkText, link.getText());
-		logger.info("testing " +  data.linkClass.name() + " : " + link.getAttribute("href"));
-		link.click();
-		wait.until(new VisibilityOfElementLocated(By.id("container")));
-		webDriver.navigate().back();
-	}
-
-}
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/FloraMalesianaPolytomousKeyTest.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/FloraMalesianaPolytomousKeyTest.java
index 77725151..2b5e1e1d 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/FloraMalesianaPolytomousKeyTest.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/FloraMalesianaPolytomousKeyTest.java
@@ -9,86 +9,86 @@
  */
 package eu.etaxonomy.dataportal.selenium.tests;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.junit.Assert;
 import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.RenderedWebElement;
-import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.PageFactory;
 
 import eu.etaxonomy.dataportal.DataPortalContext;
 import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
 import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
-import eu.etaxonomy.dataportal.testutils.PolytomousKeyTestTool;
-import eu.etaxonomy.dataportal.testutils.PolytomousKeyTestTool.KeyLineData;
-import eu.etaxonomy.dataportal.testutils.PolytomousKeyTestTool.LinkClass;
+import eu.etaxonomy.dataportal.pages.PolytomousKeyPage;
+import eu.etaxonomy.dataportal.pages.PolytomousKeyPage.KeyLineData;
+import eu.etaxonomy.dataportal.pages.PolytomousKeyPage.LinkClass;
+import eu.etaxonomy.dataportal.pages.PortalPage;
 
 /**
  * @author a.kohlbecker
  *
  */
 
-@DataPortalContexts( { DataPortalContext.floramalesiana })
-public class FloraMalesianaPolytomousKeyTest extends CdmDataPortalTestBase{
+@DataPortalContexts({ DataPortalContext.floramalesiana })
+public class FloraMalesianaPolytomousKeyTest extends CdmDataPortalTestBase {
 
 	/**
 	 * see http://dev.e-taxonomy.eu/trac/ticket/2350
+	 *
 	 * @param WebDriver
 	 */
 	@Test
-	public void key_to_Malaysian_Sapindaceae_Genera(){
-		driver.get(getBaseUrl() + "?q=cdm_dataportal/polytomousKey/40cf3253-ce7a-4ad6-9a32-27695c36eb5d");
+	public void key_to_Malaysian_Sapindaceae_Genera() {
 
-		// Page title
-		RenderedWebElement element = (RenderedWebElement)driver.findElement(By.xpath(".//*[@id='squeeze']/div/div/h2"));
-		Assert.assertEquals("KEY I TO THE MALESIAN GENERA (based on vegetative and flower characters) (F. Adema)", element.getText());
+		String pageUrlString = getBaseUrl() + "?q=cdm_dataportal/polytomousKey/40cf3253-ce7a-4ad6-9a32-27695c36eb5d";
 
-		List<WebElement> keyTableList = driver.findElements(By.className("polytomousKey"));
-		Assert.assertEquals("Only one polytomousKey table expected", 1, keyTableList.size());
-		WebElement keyTable = keyTableList.get(0);
+		driver.get(pageUrlString);
 
-		List<WebElement> tableRows = keyTable.findElements(By.xpath("tbody/tr"));
+		PolytomousKeyPage p = PageFactory.initElements(driver, PolytomousKeyPage.class);
+		PortalPage targetPage;
+		KeyLineData keyLineData;
 
-		Map<Integer, PolytomousKeyTestTool.KeyLineData> keyLineDataMap = new HashMap<Integer, PolytomousKeyTestTool.KeyLineData>();
+		Assert.assertEquals("KEY I TO THE MALESIAN GENERA (based on vegetative and flower characters) (F. Adema)", p.getTitle());
 
-		keyLineDataMap.put(0, new KeyLineData(
-				"0",
+		// -------- //
+		keyLineData = new KeyLineData("0",
 				"Trees or shrubs, exceptionally lianas. Leaves simple, unifoliolate, (bi)pinnate or digitate. Inflorescences without basal tendrils",
-				LinkClass.nodeLinkToNode,
-				"1"));
-
-		keyLineDataMap.put(1, new KeyLineData("0'",
-				"Herbaceous or woody climbers. Leaves biternate. Inflorescences with basal tendrils",
-				LinkClass.nodeLinkToTaxon,
-				"Cardiospermum"));
-
-		keyLineDataMap.put(2, new KeyLineData("1",
-				"Leaves simple, unifoliolate, (im)paripinnate or digitate",
-				LinkClass.nodeLinkToNode,
-				"2"));
-
-		keyLineDataMap.put(3, new KeyLineData("1'",
-				"Leaves bipinnate",
-				LinkClass.nodeLinkToTaxon,
-				"Tristiropsis"));
-
-		keyLineDataMap.put(126, new KeyLineData("116",
+				LinkClass.nodeLinkToNode, "1");
+		targetPage = p.followPolytomousKeyLine(0, keyLineData);
+		Assert.assertEquals(p, targetPage);
+
+		// -------- //
+		keyLineData = new KeyLineData("0'", "Herbaceous or woody climbers. Leaves biternate. Inflorescences with basal tendrils",
+				LinkClass.nodeLinkToTaxon, "Cardiospermum");
+		targetPage = p.followPolytomousKeyLine(1, keyLineData);
+		Assert.assertEquals(keyLineData.getLinkText(), targetPage.getTitle());
+		p.goToInitialPage();
+
+		// -------- //
+		keyLineData = new KeyLineData("1", "Leaves simple, unifoliolate, (im)paripinnate or digitate", LinkClass.nodeLinkToNode, "2");
+		p.followPolytomousKeyLine(2, keyLineData);
+		Assert.assertEquals(p, targetPage);
+
+		// -------- //
+		keyLineData = new KeyLineData("1'", "Leaves bipinnate", LinkClass.nodeLinkToTaxon, "Tristiropsis");
+		p.followPolytomousKeyLine(3, keyLineData);
+		Assert.assertEquals(keyLineData.getLinkText(), targetPage.getTitle());
+		p.goToInitialPage();
+
+		// -------- //
+		keyLineData = new KeyLineData(
+				"116",
 				"Leaflets entire or crenulate, lower surface without small glands. Inflorescences axillary, sometimes together pseudoterminal; cymes dense, many-flowered",
-				LinkClass.nodeLinkToTaxon,
-				"Synima cordierorum"));
-
-		keyLineDataMap.put(127, new KeyLineData("116'",
+				LinkClass.nodeLinkToTaxon, "Synima cordierorum");
+		Assert.assertEquals(keyLineData.getLinkText(), targetPage.getTitle());
+		p.followPolytomousKeyLine(126, keyLineData);
+		p.goToInitialPage();
+
+		// -------- //
+		keyLineData = new KeyLineData(
+				"116'",
 				"Leaflets entire, lower surface usually with small glands. Inflorescences axillary, together mostly pseudoterminal, by the shifting aside and suppression of the terminal bud sometimes seemingly truly terminal; cymes lax, 1- or few-flowered",
-				LinkClass.nodeLinkToTaxon,
-				"Trigonachras"));
+				LinkClass.nodeLinkToTaxon, "Trigonachras");
+		Assert.assertEquals(keyLineData.getLinkText(), targetPage.getTitle());
+		p.followPolytomousKeyLine(127, keyLineData);
 
-		PolytomousKeyTestTool tester = new PolytomousKeyTestTool(tableRows, keyLineDataMap, driver);
-
-		tester.runTest();
 	}
 
-
 }
