1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2011 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.dataportal;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.openqa.selenium.By;
|
17
|
import org.openqa.selenium.WebElement;
|
18
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
19
|
|
20
|
import eu.etaxonomy.dataportal.elements.BaseElement;
|
21
|
import eu.etaxonomy.dataportal.elements.GalleryImage;
|
22
|
import eu.etaxonomy.dataportal.elements.LinkElement;
|
23
|
import eu.etaxonomy.dataportal.selenium.AllTrue;
|
24
|
import eu.etaxonomy.dataportal.selenium.ChildElementVisible;
|
25
|
|
26
|
/**
|
27
|
* @author andreas
|
28
|
* @date Sep 16, 2011
|
29
|
*
|
30
|
*/
|
31
|
public class ElementUtils {
|
32
|
|
33
|
|
34
|
public static final Logger logger = Logger.getLogger(ElementUtils.class);
|
35
|
|
36
|
/**
|
37
|
* @param fnListElements
|
38
|
* @return
|
39
|
*/
|
40
|
public static List<BaseElement> baseElementsFromFootNoteListElements(List<WebElement> fnListElements) {
|
41
|
List<BaseElement> footNotes = new ArrayList<BaseElement>();
|
42
|
for(WebElement fn : fnListElements) {
|
43
|
footNotes.add(new BaseElement(fn));
|
44
|
}
|
45
|
return footNotes;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @param fnkListElements
|
50
|
* @return
|
51
|
*/
|
52
|
public static List<LinkElement> linkElementsFromFootNoteKeyListElements(List<WebElement> fnkListElements) {
|
53
|
List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
|
54
|
for(WebElement fnk : fnkListElements) {
|
55
|
footNoteKeys.add(new LinkElement(fnk));
|
56
|
}
|
57
|
return footNoteKeys;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* @param wait
|
62
|
* @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
|
63
|
*/
|
64
|
public static List<List<GalleryImage>> getGalleryImages(WebElement webElement, WebDriverWait wait) {
|
65
|
|
66
|
|
67
|
WebElement gallery = webElement.findElement(By.className("media_gallery"));
|
68
|
|
69
|
if( gallery == null){
|
70
|
return null;
|
71
|
}
|
72
|
|
73
|
ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
|
74
|
|
75
|
List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
|
76
|
logger.debug("GalleryImages - total rows " + tableRows.size());
|
77
|
// loop table rows
|
78
|
for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
|
79
|
logger.debug("GalleryImages - gallery row " + rowId );
|
80
|
List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
|
81
|
logger.debug("GalleryImages - number of image cells: " + imageCells.size());
|
82
|
List<WebElement> captionCells = null;
|
83
|
if(tableRows.size() > rowId * 2 + 1){
|
84
|
captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
|
85
|
logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
|
86
|
}
|
87
|
|
88
|
galleryImageRows.add(new ArrayList<GalleryImage>());
|
89
|
|
90
|
// loop table cells in row
|
91
|
for(int cellId = 0; cellId < imageCells.size(); cellId++) {
|
92
|
logger.debug("cellId:" + cellId);
|
93
|
WebElement imageCell = imageCells.get(cellId);
|
94
|
WebElement captionCell = null;
|
95
|
if(captionCells != null && captionCells.size() > cellId){
|
96
|
captionCell = captionCells.get(cellId);
|
97
|
wait.until(new AllTrue(
|
98
|
new ChildElementVisible(imageCell, By.tagName("img")),
|
99
|
new ChildElementVisible(captionCell, By.tagName("dl"))
|
100
|
));
|
101
|
|
102
|
} else {
|
103
|
wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
|
104
|
}
|
105
|
galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
|
106
|
}
|
107
|
|
108
|
}
|
109
|
|
110
|
return galleryImageRows;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Expected DOM:
|
115
|
*
|
116
|
* <ul class="footnotes">
|
117
|
* <li class="footnotes footnotes-taxon_relationships "><span class="footnote footnote-1">...</span></li>
|
118
|
* <li class="footnotes footnotes-taxon_relationships-annotations ">...</li>
|
119
|
* </ul>
|
120
|
* @param element
|
121
|
* @return
|
122
|
*/
|
123
|
public static List<BaseElement> findFootNotes(WebElement element){
|
124
|
List<WebElement> fnListElements = element.findElements(
|
125
|
By.xpath("./ul[contains(@class,'footnotes')]/li[contains(@class, 'footnotes')]/span[contains(@class, 'footnote')]")
|
126
|
);
|
127
|
return ElementUtils.baseElementsFromFootNoteListElements(fnListElements);
|
128
|
}
|
129
|
|
130
|
|
131
|
}
|