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 an element is visible.
23   *
24   * You can specify whether you expect true(item is visible) or 
25   * false (item is not visible).  True is the default
26   * 
27   * To see if something IS visible:
28   * <pre><source>
29   *     &lt;selenium-assert-visible
30   *            functionId="Assert that the div is visible"
31   *            expected="true"
32   *            msg="We expected the div to be visible"
33   *            locator="mydiv" /&gt;
34   * </source></pre>
35   *
36   * To see if something is NOT visible:
37   * <pre><source>
38   *     &lt;selenium-assert-visible
39   *            functionId="Assert that the div is not visible"
40   *            expected="false"
41   *            msg="We expected the div to be not visible"
42   *            locator="div_2" /&gt;
43   * </source></pre>
44   *
45   * @jameleon.function name="selenium-assert-visible" type="validation"
46   */
47  public class SeleniumAssertVisibleTag 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 + " is not visible!"), session.isVisible(locator));
65          } else {
66              assertFalse(getStringOrDefault(msg, locator + " was visible!"), session.isVisible(locator));
67          }
68      }
69  }