Revision f0d48bd8
Added by Andreas Kohlbecker almost 10 years ago
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/ElementUtils.java | ||
---|---|---|
12 | 12 |
import java.util.ArrayList; |
13 | 13 |
import java.util.List; |
14 | 14 |
|
15 |
import org.apache.log4j.Logger; |
|
15 | 16 |
import org.openqa.selenium.By; |
16 | 17 |
import org.openqa.selenium.WebElement; |
18 |
import org.openqa.selenium.support.ui.WebDriverWait; |
|
17 | 19 |
|
18 | 20 |
import eu.etaxonomy.dataportal.elements.BaseElement; |
21 |
import eu.etaxonomy.dataportal.elements.GalleryImage; |
|
19 | 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; |
|
20 | 27 |
|
21 | 28 |
/** |
22 | 29 |
* @author andreas |
... | ... | |
25 | 32 |
*/ |
26 | 33 |
public class ElementUtils { |
27 | 34 |
|
28 |
/** |
|
29 |
* @param fnListElements |
|
30 |
* @return |
|
31 |
*/ |
|
32 |
public static List<BaseElement> baseElementsFromFootNoteListElements(List<WebElement> fnListElements) { |
|
33 |
List<BaseElement> footNotes = new ArrayList<BaseElement>(); |
|
34 |
for(WebElement fn : fnListElements) { |
|
35 |
footNotes.add(new BaseElement(fn)); |
|
36 |
} |
|
37 |
return footNotes; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* @param fnkListElements |
|
42 |
* @return |
|
43 |
*/ |
|
44 |
public static List<LinkElement> linkElementsFromFootNoteKeyListElements(List<WebElement> fnkListElements) { |
|
45 |
List<LinkElement> footNoteKeys = new ArrayList<LinkElement>(); |
|
46 |
for(WebElement fnk : fnkListElements) { |
|
47 |
footNoteKeys.add(new LinkElement(fnk)); |
|
48 |
} |
|
49 |
return footNoteKeys; |
|
50 |
} |
|
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 |
|
|
51 | 115 |
|
52 | 116 |
} |
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/elements/FeatureBlock.java | ||
---|---|---|
154 | 154 |
} |
155 | 155 |
} |
156 | 156 |
|
157 |
public List<GalleryImage> getGalleryMedia() { |
|
158 |
List<GalleryImage> galleryImages = null; //getGalleryImages(getElement()); |
|
159 |
|
|
160 |
return galleryImages; |
|
161 |
|
|
162 |
} |
|
163 |
|
|
157 | 164 |
} |
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/GenericPortalPage.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.dataportal.pages; |
11 | 11 |
|
12 | 12 |
import java.net.MalformedURLException; |
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
13 | 15 |
|
14 | 16 |
import org.openqa.selenium.By; |
15 | 17 |
import org.openqa.selenium.WebDriver; |
18 |
import org.openqa.selenium.WebElement; |
|
16 | 19 |
|
17 | 20 |
import eu.etaxonomy.dataportal.DataPortalContext; |
21 |
import eu.etaxonomy.dataportal.elements.GalleryImage; |
|
18 | 22 |
import eu.etaxonomy.dataportal.selenium.AllTrue; |
23 |
import eu.etaxonomy.dataportal.selenium.ChildElementVisible; |
|
19 | 24 |
import eu.etaxonomy.dataportal.selenium.PageTitleValidated; |
20 | 25 |
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated; |
21 | 26 |
|
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/TaxonSearchResultPage.java | ||
---|---|---|
22 | 22 |
import org.openqa.selenium.support.FindBy; |
23 | 23 |
|
24 | 24 |
import eu.etaxonomy.dataportal.DataPortalContext; |
25 |
import eu.etaxonomy.dataportal.elements.GalleryImage; |
|
26 | 25 |
import eu.etaxonomy.dataportal.elements.LinkElement; |
27 | 26 |
import eu.etaxonomy.dataportal.elements.TaxonListElement; |
28 |
import eu.etaxonomy.dataportal.selenium.AllTrue; |
|
29 |
import eu.etaxonomy.dataportal.selenium.ChildElementVisible; |
|
30 | 27 |
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated; |
31 | 28 |
|
32 | 29 |
/** |
... | ... | |
116 | 113 |
|
117 | 114 |
} |
118 | 115 |
|
119 |
/** |
|
120 |
* @return a two dimensional array representing the media items in the gallery, or null if no gallery exists. |
|
121 |
*/ |
|
122 |
public List<List<GalleryImage>> getGalleryImagesOf(TaxonListElement taxonListElement) { |
|
123 |
|
|
124 |
|
|
125 |
WebElement gallery = taxonListElement.getElement().findElement(By.className("media_gallery")); |
|
126 |
|
|
127 |
if( gallery == null){ |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>(); |
|
132 |
|
|
133 |
List<WebElement> tableRows = gallery.findElements(By.tagName("tr")); |
|
134 |
logger.debug("GalleryImages - total rows " + tableRows.size()); |
|
135 |
// loop table rows |
|
136 |
for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){ |
|
137 |
logger.debug("GalleryImages - gallery row " + rowId ); |
|
138 |
List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td")); |
|
139 |
logger.debug("GalleryImages - number of image cells: " + imageCells.size()); |
|
140 |
List<WebElement> captionCells = null; |
|
141 |
if(tableRows.size() > rowId * 2 + 1){ |
|
142 |
captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td")); |
|
143 |
logger.debug("GalleryImages - number of caption cells: " + captionCells.size()); |
|
144 |
} |
|
145 |
|
|
146 |
galleryImageRows.add(new ArrayList<GalleryImage>()); |
|
147 |
|
|
148 |
// loop table cells in row |
|
149 |
for(int cellId = 0; cellId < imageCells.size(); cellId++) { |
|
150 |
logger.debug("cellId:" + cellId); |
|
151 |
WebElement imageCell = imageCells.get(cellId); |
|
152 |
WebElement captionCell = null; |
|
153 |
if(captionCells != null && captionCells.size() > cellId){ |
|
154 |
captionCell = captionCells.get(cellId); |
|
155 |
wait.until(new AllTrue( |
|
156 |
new ChildElementVisible(imageCell, By.tagName("img")), |
|
157 |
new ChildElementVisible(captionCell, By.tagName("dl")) |
|
158 |
)); |
|
159 |
|
|
160 |
} else { |
|
161 |
wait.until(new ChildElementVisible(imageCell, By.tagName("img"))); |
|
162 |
} |
|
163 |
galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell)); |
|
164 |
} |
|
165 |
|
|
166 |
} |
|
167 |
|
|
168 |
return galleryImageRows; |
|
169 |
} |
|
170 |
|
|
171 | 116 |
|
172 | 117 |
|
173 | 118 |
} |
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/cichorieae/Cichorieae_SearchTest.java | ||
---|---|---|
23 | 23 |
import org.openqa.selenium.WebElement; |
24 | 24 |
|
25 | 25 |
import eu.etaxonomy.dataportal.DataPortalContext; |
26 |
import eu.etaxonomy.dataportal.ElementUtils; |
|
26 | 27 |
import eu.etaxonomy.dataportal.elements.GalleryImage; |
27 | 28 |
import eu.etaxonomy.dataportal.elements.TaxonListElement; |
28 | 29 |
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase; |
... | ... | |
87 | 88 |
|
88 | 89 |
TaxonListElement lapsanaCommunnis = searchResultPage.getResultItem(1); |
89 | 90 |
|
90 |
List<List<GalleryImage>> galleryImageRows = searchResultPage.getGalleryImagesOf(lapsanaCommunnis);
|
|
91 |
List<List<GalleryImage>> galleryImageRows = ElementUtils.getGalleryImages(lapsanaCommunnis.getElement(), searchResultPage.getWait());
|
|
91 | 92 |
|
92 | 93 |
assertEquals("Expecting one row of images", 1, galleryImageRows.size()); |
93 | 94 |
assertEquals("Expecting 4 images in row", 4, galleryImageRows.get(0).size()); |
Also available in: Unified diff
test for #4423 (DescriptionElement media no longer visible)