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