Project

General

Profile

Download (6.88 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2

    
3
/**
4
 * Copyright (C) 2009 EDIT
5
 * European Distributed Institute of Taxonomy
6
 * http://www.e-taxonomy.eu
7
 *
8
 * The contents of this file are subject to the Mozilla Public License Version 1.1
9
 * See LICENSE.TXT at the top of this package for the full license terms.
10
 */
11
package eu.etaxonomy.dataportal.pages;
12

    
13
import static org.junit.Assert.assertEquals;
14
import static org.junit.Assert.assertTrue;
15

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

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

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

    
36
/**
37
 * TODO: subpages like /cdm_dataportal/taxon/{uuid}/images are not jet suported, implement means to handle page parts
38
 *
39
 * @author andreas
40
 * @date Jul 1, 2011
41
 *
42
 */
43
public class TaxonProfilePage extends PortalPage {
44

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

    
47
    private UUID taxonUuid;
48

    
49
    protected static String drupalPagePathBase = "cdm_dataportal/taxon";
50

    
51
    /* (non-Javadoc)
52
     * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
53
     */
54
    @Override
55
    protected String getDrupalPageBase() {
56
        return drupalPagePathBase;
57
    }
58

    
59
    @FindBy(id = "taxonProfileImage")
60
    @CacheLookup
61
    private WebElement taxonProfileImage;
62

    
63
    @FindBy(id = "page-toc")
64
    @CacheLookup
65
    private WebElement tableOfContent;
66

    
67
    private List<LinkElement> tableOfContentLinks = null;
68

    
69

    
70

    
71
    /**
72
     * @param driver
73
     * @param context
74
     * @param taxonUuid
75
     * @throws MalformedURLException
76
     */
77
    public TaxonProfilePage(WebDriver driver, DataPortalContext context, UUID taxonUuid) throws MalformedURLException {
78

    
79
        super(driver, context, taxonUuid.toString());
80

    
81
        this.taxonUuid = taxonUuid;
82
    }
83

    
84

    
85
    /**
86
     * @param driver
87
     * @param context
88
     * @throws Exception
89
     */
90
    public TaxonProfilePage(WebDriver driver, DataPortalContext context) throws Exception {
91
        super(driver, context);
92
    }
93

    
94

    
95
    /**
96
     * Returns the profile image of the taxon profile page. This image is
97
     * located at the top of the page. The Profile Image can be disabled in the
98
     * DataPortal settings.
99
     *
100
     * @return The Url of the profile image or null if the image is not visible.
101
     */
102
    public ImgElement getProfileImage() {
103
        ImgElement imgElement = null;
104
        try {
105
            if(taxonProfileImage.isDisplayed()){
106
                WebElement img =  taxonProfileImage.findElement(By.tagName("img"));
107
                if (img != null) {
108
                    imgElement = new ImgElement(img);
109
                }
110
            }
111
        } catch (NoSuchElementException e) {
112
            // IGNORE //
113
        }
114
        return imgElement;
115
    }
116

    
117
    public String getTableOfContentHeader() {
118
        if(tableOfContent != null) {
119
            WebElement header = tableOfContent.findElement(By.tagName("h3"));
120
            return header.getText();
121
        }
122
        return null;
123
    }
124

    
125
    public List<LinkElement> getTableOfContentLinks() {
126
        if(tableOfContentLinks == null) {
127
            tableOfContentLinks = new ArrayList<LinkElement>();
128
            if(tableOfContent != null) {
129
                List<WebElement> listItems = tableOfContent.findElements(By.tagName("a"));
130
                for (WebElement li : listItems) {
131
                    tableOfContentLinks.add( new LinkElement( li) );
132
                }
133
            }
134
        }
135
        return tableOfContentLinks;
136
    }
137

    
138
    /**
139
     * Finds the {@link FeatureBlock} specified by the <code>featureName</code> parameter.
140
     * The following document structure is expected:
141
     * <pre>
142
     * &lt;div id="block-cdm-dataportal-feature-${featureName}" class="clear-block block block-cdm-dataportal-feature"&gt;
143
     *   &lt;div class="content"&gt;
144
     *     &lt;${enclosingTag} id="${featureName}" class="description"&gt;
145
     *       &lt;${elementTag}&gt;DescriptionElement 1&lt;/${elementTag}&gt;
146
     *       &lt;${elementTag}&gt;DescriptionElement 2&lt;/${elementTag}&gt;
147
     *     &lt;/${enclosingTag}&gt;
148
     *    &lt;/div&gt;
149
     * </pre>
150
     *
151
     * The DescriptionElements can be get from the <code>FeatureBlock</code> by {@link FeatureBlock#getDescriptionElements()}.
152
     *
153
     * @param position Zero based index of position in list of feature blocks
154
     * 			(only used to check against total number of feature blocks)
155
     * @param featureName the feature name as it is used in the class attribute: <code>block-cdm-dataportal-feature-${featureName}</code>
156
     * @param enclosingTag
157
     * @param elementTag
158
     * @return
159
     */
160
    public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String elementTag){
161

    
162
        logger.setLevel(Level.TRACE);
163
        logger.trace("getFeatureBlockAt()");
164
        List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm-dataportal-feature"));
165
        Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
166
        for(WebElement b : featureBlocks){
167
            if (b.getAttribute("id").equals("block-cdm-dataportal-feature-" + normalizeClassAttribute(featureName))){
168
                logger.trace("getFeatureBlockAt() - block found, will be instantiated ...");
169
                return new FeatureBlock( driver, b, enclosingTag, elementTag);
170
            }
171
        }
172
        return null;
173
    }
174

    
175

    
176
    public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String ... elementTag){
177

    
178
        List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm-dataportal-feature"));
179
        Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
180
        for(WebElement b : featureBlocks){
181
            if (b.getAttribute("id").equals("block-cdm-dataportal-feature-" + normalizeClassAttribute(featureName))){
182
                return new FeatureBlock( driver, b, enclosingTag, elementTag);
183
            }
184
        }
185
        return null;
186
    }
187

    
188
    /**
189
     * @param index
190
     * @param tocLinkText
191
     * @param tocLinkFragment
192
     */
193
    public void testTableOfContentEntry(int index, String tocLinkText, String tocLinkFragment) {
194
        assertEquals(tocLinkText, getTableOfContentLinks().get(index).getText());
195
        String expectedHref = getDrupalPagePath() + "#" + tocLinkFragment.replace('-', '_');
196
        assertTrue("Expecting the toc link to end with " + expectedHref,  getTableOfContentLinks().get(index).getUrl().toString().endsWith(expectedHref));
197
    }
198

    
199
}
(4-4/6)