Project

General

Profile

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

    
3
import java.net.MalformedURLException;
4
import java.util.ArrayList;
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

    
16
import eu.etaxonomy.dataportal.DataPortalContext;
17
import eu.etaxonomy.dataportal.elements.BaseElement;
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
	/* (non-Javadoc)
29
	 * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
30
	 */
31
	@Override
32
	protected String getDrupalPageBase() {
33
		return drupalPagePathBase;
34
	}
35

    
36
	@FindBy(className="polytomousKey")
37
	@CacheLookup
38
	private WebElement keyTable;
39

    
40
	@FindBy(css="#identificationKey .sources span.reference")
41
	@CacheLookup
42
	private List<WebElement> sourceReferences;
43

    
44
	@FindBy(css="#identificationKey .annotations")
45
    @CacheLookup
46
    private WebElement annotations;
47

    
48
	private List<WebElement> keyTableRows;
49

    
50
	public PolytomousKeyPage(WebDriver driver, DataPortalContext context, UUID keyUuid) throws MalformedURLException {
51
		super(driver, context, keyUuid.toString());
52
	}
53

    
54
	public PolytomousKeyPage(WebDriver driver, DataPortalContext context) throws Exception {
55
		super(driver, context);
56
	}
57

    
58
	public String getKeyAnnotationsText(){
59
	    return annotations.getText();
60
	}
61

    
62
	public List<BaseElement> getSources() {
63
	    List<BaseElement> baseElements = new ArrayList<BaseElement>();
64
//	    List<WebElement> references = sources.findElements(By.className("reference"));
65
	    for(WebElement sr : sourceReferences) {
66
	        baseElements.add(new BaseElement(sr));
67
	    }
68
	    return baseElements;
69
	}
70

    
71
	public static class KeyLineData{
72

    
73
		String nodeNumber = null;
74
		String edgeText = null;
75
		LinkClass linkClass = null;
76
		String linkText = null;
77
        String suffix = "";
78

    
79

    
80
		public String getNodeNumber() {
81
			return nodeNumber;
82
		}
83

    
84
		public String getEdgeText() {
85
			return edgeText;
86
		}
87

    
88
		public LinkClass getLinkClass() {
89
			return linkClass;
90
		}
91

    
92
		public String getLinkText() {
93
			return linkText;
94
		}
95

    
96
		public String getLinkTextWithSuffix() {
97
            return linkText + (suffix != null ? suffix : "");
98
        }
99

    
100
		public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
101
			this.nodeNumber = nodeNumber;
102
			this.edgeText = edgeText;
103
			this.linkClass = linkClass;
104
			this.linkText = linkText;
105
		}
106

    
107
		/**
108
		 * @param suffix In cases where the linkText is a taxonName the link may be suffixed with the nomenclatural reference.
109
		 */
110
		public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText, String suffix) {
111
            this.nodeNumber = nodeNumber;
112
            this.edgeText = edgeText;
113
            this.linkClass = linkClass;
114
            this.linkText = linkText;
115
            this.suffix = suffix;
116
        }
117
	}
118

    
119
	public enum LinkClass {
120
		nodeLinkToNode,
121
		nodeLinkToTaxon;
122
	}
123

    
124
	public PortalPage followPolytomousKeyLine(int lineIndex, KeyLineData data) throws Exception {
125

    
126
		keyTableRows = keyTable.findElements(By.xpath("tbody/tr"));
127
		WebElement keyEntry = keyTableRows.get(lineIndex);
128
		Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
129
		Assert.assertEquals("edge text", composeFullEdgeText(data), keyEntry.findElement(By.className("edge")).getText());
130
		WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
131
		WebElement link = linkContainer.findElement(By.tagName("a"));
132
		Assert.assertEquals("link text", data.linkText, link.getText());
133
		String linkUrl = link.getAttribute("href");
134

    
135
		logger.info("clicking on " +  data.linkClass.name() + " : " + linkUrl);
136

    
137
		// click and wait
138
		link.click();
139
		wait.until(new AllTrue(new UrlLoaded(linkUrl), new VisibilityOfElementLocated(By.id("container"))));
140

    
141
		PortalPage nextPage = null;
142
		if(data.linkClass.equals(LinkClass.nodeLinkToTaxon)){
143
			nextPage = new TaxonProfilePage(driver, context);
144
		} else {
145
			// must be PolytomousKeyPage then
146
			if( !isOnPage()){
147
				nextPage = new PolytomousKeyPage(driver, context);
148
			} else {
149
				nextPage = this;
150
			}
151
		}
152

    
153
		return nextPage;
154
	}
155

    
156

    
157
    private String composeFullEdgeText(KeyLineData data) {
158
        return data.edgeText + "\n" + data.getLinkTextWithSuffix();
159
    }
160

    
161

    
162

    
163

    
164

    
165
}
(2-2/7)