Project

General

Profile

Download (6.74 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
/**
3
 * Copyright (C) 2009 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 static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertTrue;
14

    
15
import java.net.MalformedURLException;
16
import java.util.ArrayList;
17
import java.util.List;
18
import java.util.UUID;
19

    
20
import org.apache.log4j.Level;
21
import org.apache.log4j.Logger;
22
import org.junit.Assert;
23
import org.openqa.selenium.By;
24
import org.openqa.selenium.NoSuchElementException;
25
import org.openqa.selenium.WebDriver;
26
import org.openqa.selenium.WebElement;
27
import org.openqa.selenium.support.CacheLookup;
28
import org.openqa.selenium.support.FindBy;
29

    
30
import eu.etaxonomy.dataportal.DataPortalContext;
31
import eu.etaxonomy.dataportal.elements.FeatureBlock;
32
import eu.etaxonomy.dataportal.elements.ImgElement;
33
import eu.etaxonomy.dataportal.elements.LinkElement;
34

    
35
/**
36
 * TODO: subpages like /cdm_dataportal/taxon/{uuid}/images are not yet supported, implement means to handle page parts
37
 *
38
 * @author andreas
39
 * @since Jul 1, 2011
40
 *
41
 */
42
public class TaxonProfilePage extends TaxonPage {
43

    
44
    public static final Logger logger = Logger.getLogger(TaxonProfilePage.class);
45

    
46
    protected static String drupalPagePathBase = "cdm_dataportal/taxon";
47

    
48

    
49
    @FindBy(id = "taxonProfileImage")
50
    @CacheLookup
51
    private WebElement taxonProfileImage;
52

    
53
    @FindBy(id = "page-toc")
54
    @CacheLookup
55
    private WebElement tableOfContent;
56

    
57
    private List<LinkElement> tableOfContentLinks = null;
58

    
59

    
60
    /**
61
     * @param driver
62
     * @param context
63
     * @param taxonUuid
64
     * @throws MalformedURLException
65
     */
66
    public TaxonProfilePage(WebDriver driver, DataPortalContext context, UUID taxonUuid) throws MalformedURLException {
67

    
68
        super(driver, context, taxonUuid);
69
    }
70

    
71

    
72
    /**
73
     * @param driver
74
     * @param context
75
     * @throws Exception
76
     */
77
    public TaxonProfilePage(WebDriver driver, DataPortalContext context) throws Exception {
78
        super(driver, context);
79
    }
80

    
81

    
82
    /**
83
     * Returns the profile image of the taxon profile page. This image is
84
     * located at the top of the page. The Profile Image can be disabled in the
85
     * DataPortal settings.
86
     *
87
     * @return The Url of the profile image or null if the image is not visible.
88
     */
89
    public ImgElement getProfileImage() {
90
        ImgElement imgElement = null;
91
        try {
92
            if(taxonProfileImage.isDisplayed()){
93
                WebElement img =  taxonProfileImage.findElement(By.tagName("img"));
94
                if (img != null) {
95
                    imgElement = new ImgElement(img);
96
                }
97
            }
98
        } catch (NoSuchElementException e) {
99
            // IGNORE //
100
        }
101
        return imgElement;
102
    }
103

    
104
    public String getTableOfContentHeader() {
105
        if(tableOfContent != null) {
106
            WebElement header = tableOfContent.findElement(By.tagName("h3"));
107
            return header.getText();
108
        }
109
        return null;
110
    }
111

    
112
    public List<LinkElement> getTableOfContentLinks() {
113
        if(tableOfContentLinks == null) {
114
            tableOfContentLinks = new ArrayList<LinkElement>();
115
            if(tableOfContent != null) {
116
                List<WebElement> listItems = tableOfContent.findElements(By.tagName("a"));
117
                for (WebElement li : listItems) {
118
                    tableOfContentLinks.add( new LinkElement( li) );
119
                }
120
            }
121
        }
122
        return tableOfContentLinks;
123
    }
124

    
125
    /**
126
     * Finds the {@link FeatureBlock} specified by the <code>featureName</code> parameter.
127
     * The following document structure is expected:
128
     * <pre>
129
     * &lt;div id="block-cdm-dataportal-feature-${featureName}" class="clear-block block block-cdm-dataportal-feature"&gt;
130
     *   &lt;div class="content"&gt;
131
     *     &lt;${enclosingTag} id="${featureName}" class="description"&gt;
132
     *       &lt;${elementTag}&gt;DescriptionElement 1&lt;/${elementTag}&gt;
133
     *       &lt;${elementTag}&gt;DescriptionElement 2&lt;/${elementTag}&gt;
134
     *     &lt;/${enclosingTag}&gt;
135
     *    &lt;/div&gt;
136
     * </pre>
137
     *
138
     * The DescriptionElements can be get from the <code>FeatureBlock</code> by {@link FeatureBlock#getDescriptionElement(int)}.
139
     *
140
     * @param position Zero based index of position in list of feature blocks
141
     * 			(only used to check against total number of feature blocks)
142
     * @param featureName the feature name as it is used in the class attribute: <code>block-cdm-dataportal-feature-${featureName}</code>
143
     * @param enclosingTag
144
     * @param elementTag
145
     */
146
    public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String elementTag){
147

    
148
        logger.setLevel(Level.TRACE);
149
        logger.trace("getFeatureBlockAt()");
150
        List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm-dataportal-feature"));
151
        Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
152
        for(WebElement b : featureBlocks){
153
            if(logger.isTraceEnabled()) {
154
                logger.trace("getFeatureBlockAt() - checking block '" + b.getAttribute("id") + "");
155
            }
156
            if (b.getAttribute("id").equals("block-cdm-dataportal-feature-" + normalizeClassAttribute(featureName))){
157
                logger.debug("getFeatureBlockAt() - block found, will be instantiated ...");
158
                return new FeatureBlock( driver, b, enclosingTag, elementTag);
159
            }
160
        }
161
        return null;
162
    }
163

    
164

    
165
    public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String ... elementTag){
166

    
167
        List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm-dataportal-feature"));
168
        Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
169
        for(WebElement b : featureBlocks){
170
            if (b.getAttribute("id").equals("block-cdm-dataportal-feature-" + normalizeClassAttribute(featureName))){
171
                return new FeatureBlock( driver, b, enclosingTag, elementTag);
172
            }
173
        }
174
        return null;
175
    }
176

    
177
    /**
178
     * @param index
179
     * @param tocLinkText
180
     * @param tocLinkFragment
181
     */
182
    public void testTableOfContentEntry(int index, String tocLinkText, String tocLinkFragment) {
183
        assertEquals(tocLinkText, getTableOfContentLinks().get(index).getText());
184
        String expectedHref = getDrupalPagePath() + "#" + tocLinkFragment.replace('-', '_');
185
        assertTrue("Expecting the toc link to end with " + expectedHref,  getTableOfContentLinks().get(index).getUrl().toString().endsWith(expectedHref));
186
    }
187

    
188
}
(6-6/8)