View Javadoc

1   /*
2       Jiffie Plugin for Jameleon - An Internet Explorer plug-in for Jameleon
3       Copyright (C) 2004-2006 Christian W. Hargraves (engrean@hotmail.com) 
4                          and Matthias Marschall (matthias@marschalls.de)
5   
6       This program is free software; you can redistribute it and/or modify
7       it under the terms of the GNU General Public License as published by
8       the Free Software Foundation; either version 2 of the License, or
9       (at your option) any later version.
10  
11      This program is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the GNU General Public License
17      along with this program; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.jameleon.plugin.jiffie.tags;
21  
22  import net.sf.jameleon.plugin.jiffie.IEFunctionTag;
23  import net.sf.jiffie.IHTMLAnchorElement;
24  
25  /***
26   * Clicks on a given link.
27   *
28   * Some example uses might be:
29   * 
30   * Clicking on <a href="http://sf.net">link text</a>
31   * <pre><source>
32   *  &lt;ie-click-link functionId="Click an link with the text underlined"
33   *                     link="link text"/&gt;
34   * </source></pre>
35   * Clicking on &lt;a href="http://sf.net" id="link id"&gt;link text&lt;/a&gt;
36   * <pre><source>
37   *  &lt;ie-click-link functionId="Click an link with the id"
38   *                     link="link id"/&gt;
39   * </source></pre>
40   * Clicking on &lt;a href="http://sf.net" name="link name"&gt;link text&lt;/a&gt;
41   * <pre><source>
42   *  &lt;ie-click-link functionId="Click an link with the name"
43   *                     link="link name"/&gt;
44   * </source></pre>
45   * Clicking on &lt;a href="http://sf.net"&gt;&lt;img src="jameleon.jpg"&gt;&lt;/a&gt;
46   * <pre><source>
47   *  &lt;ie-click-link functionId="Click an link with the img src"
48   *                     link="jameleon.jpg"/&gt;
49   * </source></pre>
50   * Clicking on &lt;a href="http://sf.net"&gt;&lt;img src="jameleon.jpg" alt="img alt"&gt;&lt;/a&gt;
51   * <pre><source>
52   *  &lt;ie-click-link functionId="Click an link with the img alt text"
53   *                     link="img alt"/&gt;
54   * </source></pre>
55   * @jameleon.function name="ie-click-link" type="navigation"
56   * @jameleon.step Validate that the given link is present on the page.
57   * @jameleon.step Click on the given link.
58   */
59  public class IEClickLinkTag extends IEFunctionTag {
60  
61      /***
62       * Link (link text, id, alt, name or img src) in page to be clicked.
63       *
64       * @jameleon.attribute required="false" contextName="ieClickLink"
65       */
66      protected String link;
67      /***
68       * Ignore target
69       * If set to 'true', will not open link in new window (if the link has a target).
70       *
71       * @jameleon.attribute required="false" contextName="ieClickLinkIgnoreTarget" default="false"
72       */
73      protected boolean ignoreTarget;
74      /***
75       * Link (link text, id, alt, name, regex or img src) in the page to be clicked.
76       *
77       * @jameleon.attribute required="false" contextName="ieClickLinkHref"
78       */
79      protected String href;
80  
81      public void testBlock() {
82          IHTMLAnchorElement anchor;
83          if (href != null && href.length() > 0) {
84              anchor = assertLinkWithHrefPresent(href, link);
85          } else {
86              assertLinkPresent(link);
87              anchor = getLink(link);
88          }
89          clickLink(anchor, ignoreTarget);
90      }
91  }