Project

General

Profile

Download (1.43 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

    
11
package eu.etaxonomy.dataportal.elements;
12

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

    
15
import org.openqa.selenium.WebElement;
16

    
17
/**
18
 * @author andreas
19
 * @date Jul 1, 2011
20
 *
21
 */
22
public class LinkElement extends BaseElement {
23

    
24
	private String href = null;
25

    
26
	public String getUrl() {
27
		return href;
28
	}
29

    
30
	public void setHref(String href) {
31
		this.href = href;
32
	}
33

    
34

    
35
	public LinkElement(WebElement a) {
36

    
37
		super(a);
38

    
39
		if(!a.getTagName().equals("a")){
40
			throw new RuntimeException("Invalid WebElement: <" + a.getTagName() + "> given, but must be <a>");
41
		}
42

    
43
		// read src url
44
		if (a.getAttribute("href") != null) {
45
				setHref(a.getAttribute("href"));
46
		}
47

    
48
	}
49

    
50
	@Override
51
	public String toString(){
52
		return super.toString() + ": " + (getUrl() != null ? getUrl() : "NO URL") + "";
53
	}
54

    
55
	public static boolean testIfLinkElement(BaseElement element, String text, String href) {
56
		return testIfLinkElement(element.getElement(), text, href);
57
	}
58

    
59
	public static boolean testIfLinkElement(WebElement element, String text, String href) {
60
		assertEquals("a", element.getTagName());
61
		assertEquals(href, element.getAttribute("href"));
62
		assertEquals(text, element.getText());
63
		return true;
64
	}
65

    
66
}
(9-9/15)