Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.dataportal.pages;
2

    
3
import java.net.MalformedURLException;
4
import java.net.URL;
5
import java.util.List;
6
import java.util.UUID;
7

    
8
import org.apache.log4j.Logger;
9
import org.junit.Assert;
10
import org.openqa.selenium.By;
11
import org.openqa.selenium.WebDriver;
12
import org.openqa.selenium.WebElement;
13
import org.openqa.selenium.support.CacheLookup;
14
import org.openqa.selenium.support.FindBy;
15
import org.openqa.selenium.support.PageFactory;
16

    
17
import eu.etaxonomy.dataportal.DataPortalContext;
18
import eu.etaxonomy.dataportal.selenium.AllTrue;
19
import eu.etaxonomy.dataportal.selenium.UrlLoaded;
20
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
21

    
22
public class PolytomousKeyPage extends PortalPage {
23

    
24
	public static final Logger logger = Logger.getLogger(PolytomousKeyPage.class);
25

    
26
	private static String drupalPagePathBase = "cdm_dataportal/polytomousKey";
27

    
28
	private DataPortalContext context;
29

    
30
	/* (non-Javadoc)
31
	 * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
32
	 */
33
	@Override
34
	protected String getDrupalPageBase() {
35
		return drupalPagePathBase;
36
	}
37

    
38
	@FindBy(className="polytomousKey")
39
	@CacheLookup
40
	private WebElement keyTable;
41

    
42
	private List<WebElement> keyTableRows;
43

    
44
	public PolytomousKeyPage(WebDriver driver, DataPortalContext context, UUID keyUuid) throws MalformedURLException {
45
		super(driver, context, keyUuid.toString());
46
		this.context = context;
47
	}
48

    
49
	/**
50
	 * @param driver
51
	 * @param context
52
	 * @throws Exception
53
	 */
54
	public PolytomousKeyPage(WebDriver driver, DataPortalContext context) throws Exception {
55
		super(driver, context);
56
	}
57

    
58
	public static class KeyLineData{
59

    
60
		String nodeNumber = null;
61
		String edgeText = null;
62
		LinkClass linkClass = null;
63
		String linkText = null;
64

    
65

    
66
		public String getNodeNumber() {
67
			return nodeNumber;
68
		}
69

    
70
		public String getEdgeText() {
71
			return edgeText;
72
		}
73

    
74
		public LinkClass getLinkClass() {
75
			return linkClass;
76
		}
77

    
78
		public String getLinkText() {
79
			return linkText;
80
		}
81

    
82
		public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
83
			this.nodeNumber = nodeNumber;
84
			this.edgeText = edgeText;
85
			this.linkClass = linkClass;
86
			this.linkText = linkText;
87
		}
88
	}
89

    
90
	public enum LinkClass {
91
		nodeLinkToNode,
92
		nodeLinkToTaxon;
93
	}
94

    
95
	public PortalPage followPolytomousKeyLine(int lineIndex, KeyLineData data) throws Exception {
96

    
97
		keyTableRows = keyTable.findElements(By.xpath("tbody/tr"));
98
		WebElement keyEntry = keyTableRows.get(lineIndex);
99
		Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
100
		Assert.assertEquals("edge text", data.edgeText + "\n" + data.linkText, keyEntry.findElement(By.className("edge")).getText());
101
		WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
102
		WebElement link = linkContainer.findElement(By.tagName("a"));
103
		Assert.assertEquals("link text", data.linkText, link.getText());
104
		String linkUrl = link.getAttribute("href");
105

    
106
		logger.info("clicking on " +  data.linkClass.name() + " : " + linkUrl);
107

    
108
		// click and wait
109
		link.click();
110
		wait.until(new AllTrue(new UrlLoaded(linkUrl), new VisibilityOfElementLocated(By.id("container"))));
111

    
112
		PortalPage nextPage = null;
113
		if(data.linkClass.equals(LinkClass.nodeLinkToTaxon)){
114
			nextPage = new TaxonProfilePage(driver, context);
115
		} else {
116
			// must be PolytomousKeyPage then
117
			if( !isOnPage()){
118
				nextPage = new PolytomousKeyPage(driver, context);
119
			} else {
120
				nextPage = this;
121
			}
122
		}
123

    
124
		return nextPage;
125
	}
126

    
127

    
128

    
129

    
130

    
131
}
(2-2/4)