View Javadoc

1   /*
2       Jameleon Selenium plug-in - A plug-in that uses Selenium (http://www.openqa.org/selenium/) to drive web sites
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library 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 GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon.plugin.selenium.tags;
20  
21  /***
22   * Validates a form field's value. 
23   * When validating select fields, only the value attribute 
24   * will be validated with this tag. A textarea's value is validated from the text
25   * nested between the opening and closing textare tags.
26   * 
27   * To validate a form field named <b>text_field_name</b> has the value <b>some value</b>:
28   * (&lt;input type="text" name="text_field_name"&gt;
29   * <pre><source>
30   *     &lt;selenium-assert-field-value-equals
31   *            functionId="Validate the text field, 'text_field_name', has a value of 'some value'"
32   *            locator="text_field_name"
33   *            value="some value"&gt;
34   * </source></pre>
35   * To use XPath for the same field:
36   * <pre><source>
37   *     &lt;selenium-assert-field-value-equals
38   *            functionId="Validate the text field, 'text_field_name', has a value of 'some value'"
39   *            locator="xpath=//input[@type='text' and @name='text_field_name']"
40   *            value="some value"&gt;
41   * </source></pre>
42   * To use JavaScript for the same field:
43   * <pre><source>
44   *     &lt;selenium-assert-field-value-equals
45   *            functionId="Validate the text field, 'text_field_name', has a value of 'some value'"
46   *            locator="dom=document.forms[0].text_field_name"
47   *            value="some value"&gt;
48   * </source></pre>
49   * @jameleon.function name="selenium-assert-field-value-equals" type="validation"
50   */
51  public class SeleniumAssertFieldValueEqualsTag extends AbstractSeleniumLocatorTag{
52  
53      /***
54       * The expected value of the field
55       * @jameleon.attribute
56       */
57      protected String value;
58      /***
59       * The error message to output if the validation fails.
60       * @jameleon.attribute
61       */
62      protected String msg;
63  
64      public void testBlock(){
65          assertTrue(getStringOrDefault(msg, "Element " + locator + " not found!"), session.isElementPresent(locator));
66          assertEquals(getStringOrDefault(msg, locator), value, session.getValue(locator));
67      }
68  
69  }