Project

General

Profile

Download (3.53 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.LinkElement;
26
import eu.etaxonomy.dataportal.elements.TaxonListElement;
27
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
28

    
29
/**
30
 * @author andreas
31
 * @date Aug 12, 2011
32
 *
33
 */
34
public class TaxonSearchResultPage extends GenericPortalPage {
35

    
36
    public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
37

    
38
    private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
39

    
40
    @FindBy(id="search_results")
41
    @CacheLookup
42
    private WebElement searchResults;
43

    
44
    //class=page_options
45
    @FindBy(className="page_options")
46
    @CacheLookup
47
    private WebElement pageOptions;
48

    
49
    //class=pager
50
    @FindBy(className="pager")
51
    @CacheLookup
52
    private WebElement pager;
53

    
54

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

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

    
72

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

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

    
84
        return entry;
85
    }
86

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

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

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

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

    
114
    }
115

    
116

    
117

    
118
}
(5-5/6)