Project

General

Profile

Download (4.01 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 java.net.MalformedURLException;
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.UUID;
17

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

    
27
import eu.etaxonomy.dataportal.DataPortalContext;
28
import eu.etaxonomy.dataportal.elements.FeatureBlock;
29
import eu.etaxonomy.dataportal.elements.ImgElement;
30
import eu.etaxonomy.dataportal.elements.LinkElement;
31

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

    
41
	public static final Logger logger = Logger.getLogger(TaxonProfilePage.class);
42

    
43
	private UUID taxonUuid;
44

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

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

    
55
	@FindBy(id = "taxonProfileImage")
56
	@CacheLookup
57
	private WebElement taxonProfileImage;
58

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

    
63

    
64

    
65
	/**
66
	 * @param driver
67
	 * @param context
68
	 * @param taxonUuid
69
	 * @throws MalformedURLException
70
	 */
71
	public TaxonProfilePage(WebDriver driver, DataPortalContext context, UUID taxonUuid) throws MalformedURLException {
72

    
73
		super(driver, context, taxonUuid.toString());
74

    
75
		this.taxonUuid = taxonUuid;
76
	}
77

    
78

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

    
88

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

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

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

    
131
	/**
132
	 * @param position Zero based index of position in list of feature blocks
133
	 * 			(only used to check against total number of feature blocks)
134
	 * @param featureName
135
	 * @param enclosingTag
136
	 * @param elementTag
137
	 * @return
138
	 */
139
	public FeatureBlock getFeatureBlockAt(int position, String featureName, String enclosingTag, String elementTag){
140

    
141
		List<WebElement> featureBlocks = portalContent.findElements(By.className("block-cdm_dataportal-feature"));
142
		Assert.assertTrue("Too few feature block elements", featureBlocks.size() >= position);
143
		for(WebElement b : featureBlocks){
144
			if (b.getAttribute("id").equals("block-cdm_dataportal-feature-" + featureName)){
145
				return new FeatureBlock( b, enclosingTag, elementTag);
146
			}
147
		}
148
		return null;
149
	}
150

    
151
}
(4-4/4)