1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 * (<input type="text" name="text_field_name">
29 * <pre><source>
30 * <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">
34 * </source></pre>
35 * To use XPath for the same field:
36 * <pre><source>
37 * <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">
41 * </source></pre>
42 * To use JavaScript for the same field:
43 * <pre><source>
44 * <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">
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 }