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.VisibilityOfElementLocated;
|
19
|
|
20
|
public class PolytomousKeyPage extends PortalPage {
|
21
|
|
22
|
public static final Logger logger = Logger.getLogger(PolytomousKeyPage.class);
|
23
|
|
24
|
private static String drupalPagePathBase = "cdm_dataportal/polytomousKey";
|
25
|
|
26
|
private DataPortalContext context;
|
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
|
private List<WebElement> keyTableRows;
|
41
|
|
42
|
public PolytomousKeyPage(WebDriver driver, DataPortalContext context, UUID keyUuid) throws MalformedURLException {
|
43
|
super(driver, context, keyUuid.toString());
|
44
|
this.context = context;
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @param driver
|
49
|
* @param context
|
50
|
* @throws Exception
|
51
|
*/
|
52
|
public PolytomousKeyPage(WebDriver driver, DataPortalContext context) throws Exception {
|
53
|
super(driver, context);
|
54
|
}
|
55
|
|
56
|
public static class KeyLineData{
|
57
|
|
58
|
String nodeNumber = null;
|
59
|
String edgeText = null;
|
60
|
LinkClass linkClass = null;
|
61
|
String linkText = null;
|
62
|
|
63
|
|
64
|
public String getNodeNumber() {
|
65
|
return nodeNumber;
|
66
|
}
|
67
|
|
68
|
public String getEdgeText() {
|
69
|
return edgeText;
|
70
|
}
|
71
|
|
72
|
public LinkClass getLinkClass() {
|
73
|
return linkClass;
|
74
|
}
|
75
|
|
76
|
public String getLinkText() {
|
77
|
return linkText;
|
78
|
}
|
79
|
|
80
|
public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
|
81
|
this.nodeNumber = nodeNumber;
|
82
|
this.edgeText = edgeText;
|
83
|
this.linkClass = linkClass;
|
84
|
this.linkText = linkText;
|
85
|
}
|
86
|
}
|
87
|
|
88
|
public enum LinkClass {
|
89
|
nodeLinkToNode,
|
90
|
nodeLinkToTaxon;
|
91
|
}
|
92
|
|
93
|
public PortalPage followPolytomousKeyLine(int lineIndex, KeyLineData data) throws Exception {
|
94
|
|
95
|
keyTableRows = keyTable.findElements(By.xpath("tbody/tr"));
|
96
|
WebElement keyEntry = keyTableRows.get(lineIndex);
|
97
|
Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
|
98
|
Assert.assertEquals("edge text", data.edgeText + "\n" + data.linkText, keyEntry.findElement(By.className("edge")).getText());
|
99
|
WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
|
100
|
WebElement link = linkContainer.findElement(By.tagName("a"));
|
101
|
Assert.assertEquals("link text", data.linkText, link.getText());
|
102
|
logger.info("testing " + data.linkClass.name() + " : " + getInitialUrlBase() + ":" + link.getAttribute("href"));
|
103
|
link.click();
|
104
|
wait.until(new VisibilityOfElementLocated(By.id("container")));
|
105
|
|
106
|
PortalPage nextPage = null;
|
107
|
if(data.linkClass.equals(LinkClass.nodeLinkToTaxon)){
|
108
|
nextPage = new TaxonProfilePage(driver, context);
|
109
|
} else {
|
110
|
// must be PolytomousKeyPage then
|
111
|
if( !isOnPage()){
|
112
|
nextPage = new PolytomousKeyPage(driver, context);
|
113
|
} else {
|
114
|
nextPage = this;
|
115
|
}
|
116
|
}
|
117
|
|
118
|
return nextPage;
|
119
|
}
|
120
|
|
121
|
|
122
|
|
123
|
|
124
|
|
125
|
}
|