Project

General

Profile

Download (5.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.Logger;
22
import org.junit.Assert;
23
import org.openqa.selenium.By;
24
import org.openqa.selenium.NoSuchElementException;
25
import org.openqa.selenium.WebElement;
26
import org.openqa.selenium.WebDriver;
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 jet suported, implement means to handle page parts
37
 *
38
 * @author andreas
39
 * @date Jul 1, 2011
40
 *
41
 */
42
public class TaxonProfilePage extends PortalPage {
43

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

    
46
	private UUID taxonUuid;
47

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

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

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

    
62
	@FindBy(id = "featureTOC")
63
	@CacheLookup
64
	private WebElement tableOfContent;
65

    
66

    
67

    
68
	/**
69
	 * @param driver
70
	 * @param context
71
	 * @param taxonUuid
72
	 * @throws MalformedURLException
73
	 */
74
	public TaxonProfilePage(WebDriver driver, DataPortalContext context, UUID taxonUuid) throws MalformedURLException {
75

    
76
		super(driver, context, taxonUuid.toString());
77

    
78
		this.taxonUuid = taxonUuid;
79
	}
80

    
81

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

    
91

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

    
114
	public String getTableOfContentHeader() {
115
		if(tableOfContent != null) {
116
			WebElement header = tableOfContent.findElement(By.tagName("h2"));
117
			return header.getText();
118
		}
119
		return null;
120
	}
121

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

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

    
158
		List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm_dataportal-feature"));
159
		Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
160
		for(WebElement b : featureBlocks){
161
			if (b.getAttribute("id").equals("block-cdm_dataportal-feature-" + featureName)){
162
				return new FeatureBlock( b, enclosingTag, elementTag);
163
			}
164
		}
165
		return null;
166
	}
167

    
168
	public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String ... elementTag){
169

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

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

    
191
}
(4-4/6)