Project

General

Profile

Download (5.95 KB) Statistics
| Branch: | Tag: | Revision:
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.UUID;
15
import java.util.concurrent.TimeUnit;
16

    
17
import org.apache.log4j.Logger;
18
import org.openqa.selenium.By;
19
import org.openqa.selenium.WebDriver;
20
import org.openqa.selenium.WebElement;
21
import org.openqa.selenium.support.CacheLookup;
22
import org.openqa.selenium.support.FindBy;
23

    
24
import eu.etaxonomy.dataportal.DataPortalContext;
25
import eu.etaxonomy.dataportal.elements.GalleryImage;
26
import eu.etaxonomy.dataportal.elements.LinkElement;
27
import eu.etaxonomy.dataportal.elements.TaxonListElement;
28
import eu.etaxonomy.dataportal.selenium.AllTrue;
29
import eu.etaxonomy.dataportal.selenium.ChildElementVisible;
30
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
31

    
32
/**
33
 * @author andreas
34
 * @date Aug 12, 2011
35
 *
36
 */
37
public class TaxonSearchResultPage extends GenericPortalPage {
38

    
39
    public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
40

    
41
    private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
42

    
43
    @FindBy(id="search_results")
44
    @CacheLookup
45
    private WebElement searchResults;
46

    
47
    //class=page_options
48
    @FindBy(className="page_options")
49
    @CacheLookup
50
    private WebElement pageOptions;
51

    
52
    //class=pager
53
    @FindBy(className="pager")
54
    @CacheLookup
55
    private WebElement pager;
56

    
57

    
58
    /* (non-Javadoc)
59
     * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
60
     */
61
    @Override
62
    protected String getDrupalPageBase() {
63
        return drupalPagePathBase;
64
    }
65

    
66
    /**
67
     * @param driver
68
     * @param context
69
     * @throws Exception
70
     */
71
    public TaxonSearchResultPage(WebDriver driver, DataPortalContext context) throws Exception {
72
        super(driver, context);
73
    }
74

    
75

    
76
    /**
77
     * Find and return the result n-th item of the result list.
78
     * The item can be specified by the index paramter.
79
     * @param index 1-based index to identify the resultset item.
80
     * This index will be used in a xpath query.
81
     * @return
82
     */
83
    public TaxonListElement getResultItem(int index) {
84

    
85
        TaxonListElement entry = new TaxonListElement(searchResults.findElement(By.xpath("ul/li[" + index + "]")));
86

    
87
        return entry;
88
    }
89

    
90
    /**
91
     * Find and returns all items of the result list.
92
     * @return
93
     */
94
    public List<TaxonListElement> getResultItems() {
95

    
96
        List<WebElement> entryList = searchResults.findElements(By.xpath("/ul/li"));
97
        List<TaxonListElement> taxonListElements = new ArrayList<TaxonListElement>();
98
        for(WebElement entry : entryList){
99
            taxonListElements.add(new TaxonListElement(entry));
100
        }
101
        return taxonListElements;
102
    }
103

    
104
    /**
105
     * @throws Exception
106
     *
107
     */
108
    @SuppressWarnings("unchecked")
109
    public <T extends PortalPage> T  clickTaxonName(TaxonListElement taxonListElement, Class<T> pageClass, UUID taxonUuid) throws Exception {
110

    
111
        LinkElement taxonlink = new LinkElement(taxonListElement.getElement().findElement(By.tagName("a")));
112
        logger.debug("taxonlink to click: " + taxonlink.toString() + " [" + taxonlink.getElement().toString() + "]");
113
        logger.debug("  waiting for visibility of css selector: .page-cdm-dataportal-taxon-" + taxonUuid.toString() + " ...");
114
        return (T) clickLink(taxonlink, new VisibilityOfElementLocated(By.cssSelector(".page-cdm-dataportal-taxon-" + taxonUuid.toString())),
115
                    pageClass, 2l, TimeUnit.MINUTES);
116

    
117
    }
118

    
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

    
172

    
173
}
(5-5/6)