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 something is selected in a drop-down("select") field.
23   * 
24   * You can specify whether you expect true(something is selected) or 
25   * false (nothing is selected).  True is the default
26   * 
27   * To see if something IS selected in the <b>fruits</b> select field:
28   * <pre><source>
29   *     &lt;selenium-assert-something-selected
30   *            functionId="Assert if something is selected in 'fruits' field"
31   *            expected="true"
32   *            msg="no fruits were selected"
33   *            locator="fruits" /&gt;
34   * </source></pre>
35   *
36   * To see if something is NOT selected in the <b>states</b> select field:
37   * <pre>
38   *     &lt;selenium-assert-something-selected
39   *            functionId="Assert if something is selected in 'states' field"
40   *            expected="false"
41   *            msg="no states should be selected"
42   *            locator="states" /&gt;
43   * </pre>
44   *
45   * @jameleon.function name="selenium-assert-something-selected" type="validation"
46   */
47  public class SeleniumAssertSomethingSelectedTag extends AbstractSeleniumLocatorTag{
48  
49      /***
50       * The error message to output if the validation fails.
51       * @jameleon.attribute
52       */
53      protected boolean expected = true;
54  
55      /***
56       * The error message to output if the validation fails.
57       * @jameleon.attribute
58       */
59      protected String msg;
60  
61      public void testBlock(){
62          if (expected == true)
63          {
64              assertTrue(getStringOrDefault(msg, locator + " had no selected items!"), session.isSomethingSelected(locator));
65          } else {
66              assertFalse(getStringOrDefault(msg, locator + " had selected items!"), session.isSomethingSelected(locator));
67          }
68      }
69  }