Revision ee5d420b
Added by Andreas Kohlbecker almost 5 years ago
src/main/java/eu/etaxonomy/dataportal/elements/DrupalBlock.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.dataportal.elements; |
10 | 10 |
|
11 |
import java.util.List; |
|
12 |
|
|
13 | 11 |
import org.apache.log4j.Level; |
14 | 12 |
import org.openqa.selenium.By; |
15 | 13 |
import org.openqa.selenium.NoSuchElementException; |
... | ... | |
23 | 21 |
*/ |
24 | 22 |
public class DrupalBlock extends BaseElement { |
25 | 23 |
|
26 |
private String header; |
|
27 |
|
|
28 |
protected WebElement content; |
|
29 |
|
|
30 |
protected List<WebElement> featureBlockelements; |
|
24 |
WebElement titleElement; |
|
31 | 25 |
|
32 | 26 |
|
33 | 27 |
public DrupalBlock(WebElement element) { |
28 |
this(element, false); |
|
29 |
} |
|
30 |
|
|
31 |
public DrupalBlock(WebElement element, boolean hasHiddenTitle) { |
|
34 | 32 |
|
35 | 33 |
super(element); |
36 | 34 |
|
37 | 35 |
logger.setLevel(Level.TRACE); |
38 | 36 |
logger.trace("DrupalBlock() - constructor after super()"); |
39 | 37 |
|
40 |
content = element.findElement(By.className("content")); |
|
41 |
featureBlockelements = element.findElements(By.className("feature-block-elements")); |
|
42 |
|
|
43 |
logger.trace("DrupalBlock() - block content loaded"); |
|
44 | 38 |
try { |
45 |
WebElement headerElement = element.findElement(By.tagName("h2")); |
|
46 |
header = headerElement.getText(); |
|
47 |
logger.trace("DrupalBlock() - header text ready"); |
|
39 |
titleElement = element.findElement(By.className("block-title")); |
|
48 | 40 |
} catch (NoSuchElementException e){ |
49 |
// IGNORE // |
|
41 |
try { |
|
42 |
titleElement = element.findElement(By.className("title")); |
|
43 |
} catch (NoSuchElementException e2){ |
|
44 |
if(!hasHiddenTitle){ |
|
45 |
throw e2; |
|
46 |
} |
|
47 |
} |
|
50 | 48 |
} |
51 | 49 |
} |
52 | 50 |
|
53 |
public String getHeader() { |
|
54 |
return header;
|
|
51 |
public String getHeaderText() {
|
|
52 |
return titleElement.getText();
|
|
55 | 53 |
} |
56 | 54 |
|
57 |
public WebElement getContent() { |
|
58 |
return content; |
|
55 |
public String getContentText() { |
|
56 |
String titleText = getHeaderText(); |
|
57 |
String elementText = getElement().getText(); |
|
58 |
if(elementText.startsWith(titleText)){ |
|
59 |
elementText = elementText.substring(titleText.length(), elementText.length()); |
|
60 |
} |
|
61 |
return elementText; |
|
59 | 62 |
} |
60 | 63 |
|
61 |
public List<WebElement> getFeatureBlockElements() { |
|
62 |
return featureBlockelements; |
|
63 |
} |
|
64 |
|
|
65 | 64 |
} |
src/main/java/eu/etaxonomy/dataportal/elements/FeatureBlock.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
private final List<WebElement> descriptionItemElements; |
49 | 49 |
|
50 |
private WebElement titleElement; |
|
51 |
|
|
52 |
private WebElement contentContainer; |
|
53 |
|
|
50 |
protected List<WebElement> featureBlockelements; |
|
54 | 51 |
|
55 | 52 |
/** |
56 | 53 |
* |
... | ... | |
125 | 122 |
return titleElement; |
126 | 123 |
} |
127 | 124 |
|
128 |
@Override |
|
129 |
public WebElement getContent() { |
|
130 |
return contentContainer; |
|
125 |
public FeatureBlock(WebDriver driver, WebElement element, String enclosingTag, String ... elementTags) { |
|
126 |
this(driver, element, false, enclosingTag, elementTags); |
|
131 | 127 |
} |
132 | 128 |
|
129 |
public FeatureBlock(WebDriver driver, WebElement element, boolean hasHiddenTitle, String enclosingTag, String ... elementTags) { |
|
133 | 130 |
|
134 |
public FeatureBlock(WebDriver driver, WebElement element, String enclosingTag, String ... elementTags) { |
|
135 |
|
|
136 |
super(element); |
|
131 |
super(element, hasHiddenTitle); |
|
137 | 132 |
// logger.setLevel(Level.TRACE); |
138 | 133 |
logger.trace("FeatureBlock() - constructor after super()"); |
139 | 134 |
|
140 | 135 |
this.driver = driver; |
141 | 136 |
this.elementTags = elementTags; |
142 | 137 |
|
143 |
titleElement = element.findElement(By.className("title"));
|
|
138 |
WebElement featureBlockElementsWrapper = element.findElement(By.className("feature-block-elements"));
|
|
144 | 139 |
|
145 |
contentContainer = element.findElement(By.className("content"));
|
|
140 |
featureBlockelements = element.findElements(By.className("feature-block-element"));
|
|
146 | 141 |
|
147 |
WebElement descriptionElementsRepresentation = element.findElement(By.className("feature-block-elements")); |
|
148 |
featureType = descriptionElementsRepresentation.getAttribute("id"); |
|
142 |
featureType = featureBlockElementsWrapper.getAttribute("id"); |
|
149 | 143 |
|
150 | 144 |
//TODO throw exception instead of making an assertion! selenium should have appropriate exceptions |
151 |
assertEquals("Unexpected tag enclosing description element representations", enclosingTag, descriptionElementsRepresentation.getTagName());
|
|
145 |
assertEquals("Unexpected tag enclosing description element representations", enclosingTag, featureBlockElementsWrapper.getTagName());
|
|
152 | 146 |
|
153 | 147 |
logger.trace("FeatureBlock() - loading all elements ..."); |
154 | 148 |
descriptionItemElements = new ArrayList<WebElement>(); |
... | ... | |
158 | 152 |
HashMap<String, List<WebElement>> elementsByTag = new HashMap<String, List<WebElement>>(); |
159 | 153 |
Integer lastSize = null; |
160 | 154 |
for (String elementTag : elementTags) { |
161 |
List<WebElement> foundElements = descriptionElementsRepresentation.findElements(By.tagName(elementTag));
|
|
155 |
List<WebElement> foundElements = featureBlockElementsWrapper.findElements(By.tagName(elementTag));
|
|
162 | 156 |
if(lastSize != null && foundElements.size() != lastSize){ |
163 | 157 |
throw new NoSuchElementException("Mulitpart element lists differ in size"); |
164 | 158 |
} |
... | ... | |
176 | 170 |
} else { |
177 | 171 |
// handle single elements |
178 | 172 |
String elementTag = elementTags[0]; |
179 |
for(WebElement el : descriptionElementsRepresentation.findElements(By.tagName( elementTag ))) {
|
|
173 |
for(WebElement el : featureBlockElementsWrapper.findElements(By.tagName( elementTag ))) {
|
|
180 | 174 |
descriptionItemElements.add(el); |
181 | 175 |
// descriptionElements.add(new DescriptionElementRepresentation(el)); |
182 | 176 |
} |
... | ... | |
186 | 180 |
} |
187 | 181 |
|
188 | 182 |
|
183 |
public List<WebElement> getFeatureBlockElements() { |
|
184 |
return featureBlockelements; |
|
185 |
} |
|
186 |
|
|
187 |
|
|
189 | 188 |
private Long jsCountElements(String jQuerySelector) { |
190 | 189 |
if(driver instanceof JavascriptExecutor) { |
191 | 190 |
String blockId = getElement().getAttribute("id"); |
Also available in: Unified diff
ref #4372 page elements DupalBlock and FeatureBlock compatible also with zen theme - solving problems