Revision 50607782
Added by Andreas Kohlbecker almost 13 years ago
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java | ||
---|---|---|
6 | 6 |
import java.util.List; |
7 | 7 |
|
8 | 8 |
import org.apache.log4j.Logger; |
9 |
import org.junit.Assert; |
|
9 | 10 |
import org.openqa.selenium.By; |
11 |
import org.openqa.selenium.NoSuchElementException; |
|
10 | 12 |
import org.openqa.selenium.RenderedWebElement; |
11 | 13 |
import org.openqa.selenium.WebDriver; |
12 | 14 |
import org.openqa.selenium.WebElement; |
... | ... | |
14 | 16 |
import org.openqa.selenium.support.FindBy; |
15 | 17 |
import org.openqa.selenium.support.FindBys; |
16 | 18 |
import org.openqa.selenium.support.PageFactory; |
19 |
import org.openqa.selenium.support.ui.LoadableComponent; |
|
17 | 20 |
|
21 |
import eu.etaxonomy.dataportal.DataPortalContext; |
|
18 | 22 |
import eu.etaxonomy.dataportal.TestConfiguration; |
19 | 23 |
import eu.etaxonomy.dataportal.elements.LinkElement; |
20 | 24 |
import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait; |
21 | 25 |
|
22 |
public class PortalPage {
|
|
26 |
public abstract class PortalPage {
|
|
23 | 27 |
|
24 | 28 |
public static final Logger logger = Logger.getLogger(PortalPage.class); |
25 | 29 |
|
30 |
protected final static String DRUPAL_PAGE_QUERY_BASE = "?q="; |
|
31 |
|
|
26 | 32 |
protected WebDriver driver; |
33 |
|
|
27 | 34 |
protected final JUnitWebDriverWait wait; |
28 |
protected URL initialUrl; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Implementations of this method will supply the raltive |
|
39 |
* path to the Drupal page. This path will usally have the form |
|
40 |
* <code>cdm_dataportal/{nodetype}</code>. For example the taxon pages all |
|
41 |
* have the page base <code>cdm_dataportal/taxon</code> |
|
42 |
* @return |
|
43 |
*/ |
|
44 |
protected abstract String getDrupalPageBase(); |
|
45 |
|
|
46 |
private String drupalPagePath; |
|
47 |
|
|
48 |
protected URL pageUrl; |
|
49 |
|
|
50 |
// ==== WebElements === // |
|
29 | 51 |
|
30 | 52 |
@FindBy(id="cdm_dataportal.node") |
31 |
@CacheLookup |
|
32 |
private RenderedWebElement portalContent; |
|
53 |
protected RenderedWebElement portalContent; |
|
33 | 54 |
|
34 | 55 |
@FindBy(tagName="title") |
35 | 56 |
@CacheLookup |
36 |
private RenderedWebElement title; |
|
57 |
protected RenderedWebElement title; |
|
58 |
|
|
59 |
@FindBy(className="node") |
|
60 |
protected RenderedWebElement node; |
|
61 |
|
|
37 | 62 |
|
38 |
//tabs primary |
|
39 | 63 |
@FindBys({@FindBy(id="tabs-wrapper"), @FindBy(className="primary")}) |
40 | 64 |
@CacheLookup |
41 |
private RenderedWebElement primaryTabs; |
|
65 |
protected RenderedWebElement primaryTabs; |
|
66 |
|
|
67 |
|
|
68 |
public PortalPage(WebDriver driver, DataPortalContext context, String pagePathSuffix) throws MalformedURLException { |
|
42 | 69 |
|
43 |
public PortalPage(WebDriver driver) throws MalformedURLException { |
|
44 | 70 |
this.driver = driver; |
45 |
this.initialUrl = new URL(driver.getCurrentUrl()); |
|
71 |
|
|
46 | 72 |
this.wait = new JUnitWebDriverWait(driver, 25); |
47 | 73 |
|
48 |
logger.info("loading " + initialUrl); |
|
74 |
this.drupalPagePath = getDrupalPageBase() + "/" + pagePathSuffix; |
|
75 |
|
|
76 |
this.pageUrl = new URL(context.getBaseUri().toString() + DRUPAL_PAGE_QUERY_BASE + drupalPagePath); |
|
77 |
|
|
78 |
// tell browser to navigate to the page |
|
79 |
driver.get(pageUrl.toString()); |
|
80 |
|
|
81 |
// This call sets the WebElement fields. |
|
82 |
PageFactory.initElements(driver, this); |
|
83 |
|
|
84 |
|
|
85 |
logger.info("loading " + pageUrl); |
|
49 | 86 |
} |
50 | 87 |
|
51 |
public void goToInitialPage() { |
|
52 |
driver.get(initialUrl.toString()); |
|
53 |
PageFactory.initElements(driver, this); |
|
88 |
public void get() { |
|
89 |
if(!driver.getCurrentUrl().equals(pageUrl.toString())){ |
|
90 |
driver.get(pageUrl.toString()); |
|
91 |
PageFactory.initElements(driver, this); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
public String getDrupalPagePath() { |
|
96 |
return drupalPagePath; |
|
54 | 97 |
} |
55 | 98 |
|
56 | 99 |
/** |
... | ... | |
61 | 104 |
return title.getText(); |
62 | 105 |
} |
63 | 106 |
|
107 |
public String getAuthorInformationText() { |
|
108 |
|
|
109 |
RenderedWebElement authorInformation = null; |
|
110 |
|
|
111 |
try { |
|
112 |
authorInformation = (RenderedWebElement)node.findElement(By.className("submitted")); |
|
113 |
} catch (NoSuchElementException e) { |
|
114 |
// IGNORE // |
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
if(authorInformation != null){ |
|
119 |
return authorInformation.getText(); |
|
120 |
} else { |
|
121 |
return null; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
64 | 125 |
public List<LinkElement> getPrimaryTabs(){ |
65 | 126 |
List<LinkElement> tabs = new ArrayList<LinkElement>(); |
66 | 127 |
List<WebElement> links = primaryTabs.findElements(By.tagName("a")); |
... | ... | |
83 | 144 |
return driver.getCurrentUrl(); |
84 | 145 |
} |
85 | 146 |
|
147 |
|
|
86 | 148 |
/** |
87 | 149 |
* return the <code>scheme://domain:port</code> part of the initial url of this page. |
88 | 150 |
* @return |
89 | 151 |
*/ |
90 | 152 |
public String getInitialUrlBase() { |
91 |
return initialUrl.getProtocol() + "://" + initialUrl.getHost() + initialUrl.getPort();
|
|
153 |
return pageUrl.getProtocol() + "://" + pageUrl.getHost() + pageUrl.getPort();
|
|
92 | 154 |
} |
93 | 155 |
|
94 | 156 |
public boolean equals(Object obj) { |
... | ... | |
101 | 163 |
} |
102 | 164 |
} |
103 | 165 |
|
166 |
|
|
104 | 167 |
} |
Also available in: Unified diff
refacoring and fine grained testing of taxon profile pages