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.pages.PortalPage;
|
24
|
import eu.etaxonomy.dataportal.selenium.AllTrue;
|
25
|
import eu.etaxonomy.dataportal.selenium.ChildElementVisible;
|
26
|
import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait;
|
27
|
|
28
|
/**
|
29
|
* @author andreas
|
30
|
* @date Sep 16, 2011
|
31
|
*
|
32
|
*/
|
33
|
public class ElementUtils {
|
34
|
|
35
|
|
36
|
public static final Logger logger = Logger.getLogger(ElementUtils.class);
|
37
|
|
38
|
/**
|
39
|
* @param fnListElements
|
40
|
* @return
|
41
|
*/
|
42
|
public static List<BaseElement> baseElementsFromFootNoteListElements(List<WebElement> fnListElements) {
|
43
|
List<BaseElement> footNotes = new ArrayList<BaseElement>();
|
44
|
for(WebElement fn : fnListElements) {
|
45
|
footNotes.add(new BaseElement(fn));
|
46
|
}
|
47
|
return footNotes;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* @param fnkListElements
|
52
|
* @return
|
53
|
*/
|
54
|
public static List<LinkElement> linkElementsFromFootNoteKeyListElements(List<WebElement> fnkListElements) {
|
55
|
List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
|
56
|
for(WebElement fnk : fnkListElements) {
|
57
|
footNoteKeys.add(new LinkElement(fnk));
|
58
|
}
|
59
|
return footNoteKeys;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* @param wait
|
64
|
* @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
|
65
|
*/
|
66
|
public static List<List<GalleryImage>> getGalleryImages(WebElement webElement, WebDriverWait wait) {
|
67
|
|
68
|
|
69
|
WebElement gallery = webElement.findElement(By.className("media_gallery"));
|
70
|
|
71
|
if( gallery == null){
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
|
76
|
|
77
|
List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
|
78
|
logger.debug("GalleryImages - total rows " + tableRows.size());
|
79
|
// loop table rows
|
80
|
for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
|
81
|
logger.debug("GalleryImages - gallery row " + rowId );
|
82
|
List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
|
83
|
logger.debug("GalleryImages - number of image cells: " + imageCells.size());
|
84
|
List<WebElement> captionCells = null;
|
85
|
if(tableRows.size() > rowId * 2 + 1){
|
86
|
captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
|
87
|
logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
|
88
|
}
|
89
|
|
90
|
galleryImageRows.add(new ArrayList<GalleryImage>());
|
91
|
|
92
|
// loop table cells in row
|
93
|
for(int cellId = 0; cellId < imageCells.size(); cellId++) {
|
94
|
logger.debug("cellId:" + cellId);
|
95
|
WebElement imageCell = imageCells.get(cellId);
|
96
|
WebElement captionCell = null;
|
97
|
if(captionCells != null && captionCells.size() > cellId){
|
98
|
captionCell = captionCells.get(cellId);
|
99
|
wait.until(new AllTrue(
|
100
|
new ChildElementVisible(imageCell, By.tagName("img")),
|
101
|
new ChildElementVisible(captionCell, By.tagName("dl"))
|
102
|
));
|
103
|
|
104
|
} else {
|
105
|
wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
|
106
|
}
|
107
|
galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
|
108
|
}
|
109
|
|
110
|
}
|
111
|
|
112
|
return galleryImageRows;
|
113
|
}
|
114
|
|
115
|
|
116
|
}
|