View Javadoc

1   /*
2       Jameleon Watij plug-in - A plug-in that uses Watij (http://www.watij.com/) to drive web sites
3       Copyright (C) 2008 Christian W. Hargraves (engrean@hotmail.com)
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  
19  */
20  package net.sf.jameleon.plugin.watij.tags;
21  
22  import net.sf.jameleon.plugin.watij.WatijFunctionTag;
23  /***
24   * Looks for the given text on the page.
25   * It then stores whether it was found or not under the provided context 
26   * variable name.
27   * 
28   * An example of its use might be:
29   * 
30   * <pre><source>
31   * &lt;testcase xmlns="jelly:jameleon"&gt;
32   *     &lt;watij-session baseUrl="http://jameleon.sourceforge.net" beginSession="true"&gt;
33   *       &lt;watij-contains-text
34   *           functionId="Check that the word 'Testing' exists on the page."
35   *           text="Testing"/&gt;
36   *       &lt;ju-assert-true
37   *           functionId="Validate that the text was found"
38   *           test="${watijTextPresent}"/&gt;
39   *     &lt;/watij-session&gt;
40   * &lt;/testcase&gt;
41   * </source></pre>
42   * 
43   * To change the context variable name:
44   * 
45   * <pre><source>
46   * &lt;testcase xmlns="jelly:jameleon"&gt;
47   *     &lt;watij-session baseUrl="http://jameleon.sourceforge.net" beginSession="true"&gt;
48   *       &lt;watij-contains-text
49   *           functionId="Check that the word 'Testing' exists on the page."
50   *           text="Testing"
51   *           contextVar="testingExists"/&gt;
52   *       &lt;ju-assert-true
53   *           functionId="Validate that the text was found"
54   *           test="${testingExists}"/&gt;
55   *     &lt;/watij-session&gt;
56   * &lt;/testcase&gt;
57   * </source></pre>
58   * 
59   * @jameleon.function name="watij-contains-text" type="action"
60   */
61  public class WatijContainsTextTag extends WatijFunctionTag{
62  
63      /***
64       * The text to check for against the currently active IE.
65       * @jameleon.attribute
66       */
67      protected String text;
68      /***
69       * The context variable to store the title in
70       * @jameleon.attribute default="watijTextPresent" required="true"
71       */
72      protected String contextVar;
73  
74      public void testBlock() throws Exception{
75          if (text != null) {
76              setVariable(contextVar, new Boolean(ie().containsText(text)));
77          }
78      }
79  
80  
81  }