1
|
package eu.etaxonomy.dataportal.pages;
|
2
|
|
3
|
import java.net.MalformedURLException;
|
4
|
import java.util.List;
|
5
|
|
6
|
import org.apache.log4j.Logger;
|
7
|
import org.junit.Assert;
|
8
|
import org.openqa.selenium.By;
|
9
|
import org.openqa.selenium.RenderedWebElement;
|
10
|
import org.openqa.selenium.WebDriver;
|
11
|
import org.openqa.selenium.WebElement;
|
12
|
import org.openqa.selenium.support.CacheLookup;
|
13
|
import org.openqa.selenium.support.FindBy;
|
14
|
import org.openqa.selenium.support.PageFactory;
|
15
|
|
16
|
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
|
17
|
|
18
|
public class PolytomousKeyPage extends PortalPage{
|
19
|
|
20
|
public PolytomousKeyPage(WebDriver driver) throws MalformedURLException {
|
21
|
super(driver);
|
22
|
}
|
23
|
|
24
|
public static final Logger logger = Logger.getLogger(PolytomousKeyPage.class);
|
25
|
|
26
|
@FindBy(className="polytomousKey")
|
27
|
@CacheLookup
|
28
|
private WebElement keyTable;
|
29
|
|
30
|
private List<WebElement> keyTableRows;
|
31
|
|
32
|
|
33
|
|
34
|
public static class KeyLineData{
|
35
|
|
36
|
String nodeNumber = null;
|
37
|
String edgeText = null;
|
38
|
LinkClass linkClass = null;
|
39
|
String linkText = null;
|
40
|
|
41
|
|
42
|
public String getNodeNumber() {
|
43
|
return nodeNumber;
|
44
|
}
|
45
|
|
46
|
public String getEdgeText() {
|
47
|
return edgeText;
|
48
|
}
|
49
|
|
50
|
public LinkClass getLinkClass() {
|
51
|
return linkClass;
|
52
|
}
|
53
|
|
54
|
public String getLinkText() {
|
55
|
return linkText;
|
56
|
}
|
57
|
|
58
|
public KeyLineData(String nodeNumber, String edgeText, LinkClass linkClass, String linkText) {
|
59
|
this.nodeNumber = nodeNumber;
|
60
|
this.edgeText = edgeText;
|
61
|
this.linkClass = linkClass;
|
62
|
this.linkText = linkText;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
public enum LinkClass {
|
67
|
nodeLinkToNode,
|
68
|
nodeLinkToTaxon;
|
69
|
}
|
70
|
|
71
|
public PortalPage followPolytomousKeyLine(int lineIndex, KeyLineData data) {
|
72
|
|
73
|
keyTableRows = keyTable.findElements(By.xpath("tbody/tr"));
|
74
|
WebElement keyEntry = keyTableRows.get(lineIndex);
|
75
|
Assert.assertEquals("node number", data.nodeNumber, keyEntry.findElement(By.className("nodeNumber")).getText());
|
76
|
Assert.assertEquals("edge text", data.edgeText + data.linkText, keyEntry.findElement(By.className("edge")).getText());
|
77
|
WebElement linkContainer = keyEntry.findElement(By.className(data.linkClass.name()));
|
78
|
RenderedWebElement link = (RenderedWebElement)linkContainer.findElement(By.tagName("a"));
|
79
|
Assert.assertEquals("link text", data.linkText, link.getText());
|
80
|
logger.info("testing " + data.linkClass.name() + " : " + getInitialUrlBase() + ":" + link.getAttribute("href"));
|
81
|
link.click();
|
82
|
wait.until(new VisibilityOfElementLocated(By.id("container")));
|
83
|
|
84
|
return PageFactory.initElements(driver, PortalPage.class);
|
85
|
}
|
86
|
|
87
|
}
|