1
|
package eu.etaxonomy.dataportal.pages;
|
2
|
|
3
|
import java.net.MalformedURLException;
|
4
|
import java.net.URL;
|
5
|
import java.util.ArrayList;
|
6
|
import java.util.List;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.openqa.selenium.By;
|
10
|
import org.openqa.selenium.RenderedWebElement;
|
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.FindBys;
|
16
|
import org.openqa.selenium.support.PageFactory;
|
17
|
|
18
|
import eu.etaxonomy.dataportal.TestConfiguration;
|
19
|
import eu.etaxonomy.dataportal.elements.LinkElement;
|
20
|
import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait;
|
21
|
|
22
|
public class PortalPage {
|
23
|
|
24
|
public static final Logger logger = Logger.getLogger(PortalPage.class);
|
25
|
|
26
|
protected WebDriver driver;
|
27
|
protected final JUnitWebDriverWait wait;
|
28
|
protected URL initialUrl;
|
29
|
|
30
|
@FindBy(id="cdm_dataportal.node")
|
31
|
@CacheLookup
|
32
|
private RenderedWebElement portalContent;
|
33
|
|
34
|
@FindBy(tagName="title")
|
35
|
@CacheLookup
|
36
|
private RenderedWebElement title;
|
37
|
|
38
|
//tabs primary
|
39
|
@FindBys({@FindBy(id="tabs-wrapper"), @FindBy(className="primary")})
|
40
|
@CacheLookup
|
41
|
private RenderedWebElement primaryTabs;
|
42
|
|
43
|
public PortalPage(WebDriver driver) throws MalformedURLException {
|
44
|
this.driver = driver;
|
45
|
this.initialUrl = new URL(driver.getCurrentUrl());
|
46
|
this.wait = new JUnitWebDriverWait(driver, 25);
|
47
|
|
48
|
logger.info("loading " + initialUrl);
|
49
|
}
|
50
|
|
51
|
public void goToInitialPage() {
|
52
|
driver.get(initialUrl.toString());
|
53
|
PageFactory.initElements(driver, this);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* returns the string from the <code>title</code> tag.
|
58
|
* @return
|
59
|
*/
|
60
|
public String getTitle() {
|
61
|
return title.getText();
|
62
|
}
|
63
|
|
64
|
public List<LinkElement> getPrimaryTabs(){
|
65
|
List<LinkElement> tabs = new ArrayList<LinkElement>();
|
66
|
List<WebElement> links = primaryTabs.findElements(By.tagName("a"));
|
67
|
for(WebElement a : links) {
|
68
|
RenderedWebElement renderedLink = (RenderedWebElement)a;
|
69
|
if(renderedLink.isDisplayed()){
|
70
|
tabs.add(new LinkElement(renderedLink));
|
71
|
}
|
72
|
}
|
73
|
|
74
|
return tabs;
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* Returns the current URL string from the {@link WebDriver}
|
80
|
* @return
|
81
|
*/
|
82
|
public String getURL() {
|
83
|
return driver.getCurrentUrl();
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* return the <code>scheme://domain:port</code> part of the initial url of this page.
|
88
|
* @return
|
89
|
*/
|
90
|
public String getInitialUrlBase() {
|
91
|
return initialUrl.getProtocol() + "://" + initialUrl.getHost() + initialUrl.getPort();
|
92
|
}
|
93
|
|
94
|
public boolean equals(Object obj) {
|
95
|
if (PortalPage.class.isAssignableFrom(obj.getClass())) {
|
96
|
PortalPage page = (PortalPage) obj;
|
97
|
return this.getURL().equals(page.getURL());
|
98
|
|
99
|
} else {
|
100
|
return false;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
}
|