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.pages;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
import java.util.concurrent.TimeUnit;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.openqa.selenium.By;
|
18
|
import org.openqa.selenium.WebDriver;
|
19
|
import org.openqa.selenium.WebElement;
|
20
|
import org.openqa.selenium.support.CacheLookup;
|
21
|
import org.openqa.selenium.support.FindBy;
|
22
|
|
23
|
import eu.etaxonomy.dataportal.DataPortalContext;
|
24
|
import eu.etaxonomy.dataportal.elements.GalleryImage;
|
25
|
import eu.etaxonomy.dataportal.elements.LinkElement;
|
26
|
import eu.etaxonomy.dataportal.elements.TaxonListElement;
|
27
|
import eu.etaxonomy.dataportal.selenium.AllTrue;
|
28
|
import eu.etaxonomy.dataportal.selenium.ChildElementVisible;
|
29
|
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
|
30
|
|
31
|
/**
|
32
|
* @author andreas
|
33
|
* @date Aug 12, 2011
|
34
|
*
|
35
|
*/
|
36
|
public class TaxonSearchResultPage extends GenericPortalPage {
|
37
|
|
38
|
public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
|
39
|
|
40
|
private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
|
41
|
|
42
|
@FindBy(id="search_results")
|
43
|
@CacheLookup
|
44
|
private WebElement searchResults;
|
45
|
|
46
|
//class=page_options
|
47
|
@FindBy(className="page_options")
|
48
|
@CacheLookup
|
49
|
private WebElement pageOptions;
|
50
|
|
51
|
//class=pager
|
52
|
@FindBy(className="pager")
|
53
|
@CacheLookup
|
54
|
private WebElement pager;
|
55
|
|
56
|
|
57
|
/* (non-Javadoc)
|
58
|
* @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
|
59
|
*/
|
60
|
@Override
|
61
|
protected String getDrupalPageBase() {
|
62
|
return drupalPagePathBase;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* @param driver
|
67
|
* @param context
|
68
|
* @throws Exception
|
69
|
*/
|
70
|
public TaxonSearchResultPage(WebDriver driver, DataPortalContext context) throws Exception {
|
71
|
super(driver, context);
|
72
|
}
|
73
|
|
74
|
|
75
|
/**
|
76
|
* Find and return the result n-th item of the result list.
|
77
|
* The item can be specified by the index paramter.
|
78
|
* @param index 1-based index to identify the resultset item.
|
79
|
* This index will be used in a xpath query.
|
80
|
* @return
|
81
|
*/
|
82
|
public TaxonListElement getResultItem(int index) {
|
83
|
|
84
|
TaxonListElement entry = new TaxonListElement(searchResults.findElement(By.xpath("ul/li[" + index + "]")));
|
85
|
|
86
|
return entry;
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Find and returns all items of the result list.
|
91
|
* @return
|
92
|
*/
|
93
|
public List<TaxonListElement> getResultItems() {
|
94
|
|
95
|
List<WebElement> entryList = searchResults.findElements(By.xpath("/ul/li"));
|
96
|
List<TaxonListElement> taxonListElements = new ArrayList<TaxonListElement>();
|
97
|
for(WebElement entry : entryList){
|
98
|
taxonListElements.add(new TaxonListElement(entry));
|
99
|
}
|
100
|
return taxonListElements;
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* @throws Exception
|
105
|
*
|
106
|
*/
|
107
|
@SuppressWarnings("unchecked")
|
108
|
public <T extends PortalPage> T clickTaxonName(TaxonListElement taxonListElement) throws Exception {
|
109
|
|
110
|
LinkElement taxonlink = new LinkElement(taxonListElement.getElement().findElement(By.tagName("a")));
|
111
|
return (T) clickLink(taxonlink, new VisibilityOfElementLocated(By.id("featureTOC")), TaxonProfilePage.class, 2l, TimeUnit.MINUTES);
|
112
|
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
|
117
|
*/
|
118
|
public List<List<GalleryImage>> getGalleryImagesOf(TaxonListElement taxonListElement) {
|
119
|
|
120
|
|
121
|
WebElement gallery = taxonListElement.getElement().findElement(By.className("media_gallery"));
|
122
|
|
123
|
if( gallery == null){
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
|
128
|
|
129
|
List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
|
130
|
logger.debug("GalleryImages - total rows " + tableRows.size());
|
131
|
// loop table rows
|
132
|
for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
|
133
|
logger.debug("GalleryImages - gallery row " + rowId );
|
134
|
List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
|
135
|
logger.debug("GalleryImages - number of image cells: " + imageCells.size());
|
136
|
List<WebElement> captionCells = null;
|
137
|
if(tableRows.size() > rowId * 2 + 1){
|
138
|
captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
|
139
|
logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
|
140
|
}
|
141
|
|
142
|
galleryImageRows.add(new ArrayList<GalleryImage>());
|
143
|
|
144
|
// loop table cells in row
|
145
|
for(int cellId = 0; cellId < imageCells.size(); cellId++) {
|
146
|
logger.debug("cellId:" + cellId);
|
147
|
WebElement imageCell = imageCells.get(cellId);
|
148
|
WebElement captionCell = null;
|
149
|
if(captionCells != null && captionCells.size() > cellId){
|
150
|
captionCell = captionCells.get(cellId);
|
151
|
wait.until(new AllTrue(
|
152
|
new ChildElementVisible(imageCell, By.tagName("img")),
|
153
|
new ChildElementVisible(captionCell, By.tagName("dl"))
|
154
|
));
|
155
|
|
156
|
} else {
|
157
|
wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
|
158
|
}
|
159
|
galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
|
160
|
}
|
161
|
|
162
|
}
|
163
|
|
164
|
return galleryImageRows;
|
165
|
}
|
166
|
|
167
|
|
168
|
|
169
|
}
|