Project

General

Profile

Download (1.83 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2011 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

    
10
package eu.etaxonomy.dataportal.elements;
11

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

    
15
import org.openqa.selenium.WebElement;
16

    
17
/**
18
 * @author andreas
19
 * @since 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 href) {
56
		return testIfLinkElement(element.getElement(), null, href);
57
	}
58

    
59

    
60
	public static boolean testIfLinkElement(BaseElement element, String text, String href) {
61
        return testIfLinkElement(element.getElement(), text, href);
62
    }
63

    
64
    /**
65
     * @param hrefEndsWith
66
     *   The actual link is must end with this. The full URL works of course also.
67
     */
68
    public static boolean testIfLinkElement(WebElement element, String text, String hrefEndsWith) {
69
        assertEquals("a", element.getTagName());
70
        assertTrue(element.getAttribute("href").endsWith(hrefEndsWith));
71
        if(text != null){
72
            assertEquals(text, element.getText());
73
        }
74
        return true;
75
    }
76

    
77
}
(11-11/22)