View Javadoc

1   /**
2    * Copyright (c) 2002-2015, JWebUnit team.
3    *
4    * This file is part of JWebUnit.
5    *
6    * JWebUnit is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * JWebUnit is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with JWebUnit.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package net.sourceforge.jwebunit.tests;
20  
21  import static net.sourceforge.jwebunit.junit.JWebUnit.*;
22  
23  import net.sourceforge.jwebunit.junit.WebTester;
24  
25  import org.junit.Test;
26  
27  public class ButtonAssertionsTest extends JWebUnitAPITestCase {
28  
29      public void setUp() throws Exception {
30          super.setUp();
31          setBaseUrl(HOST_PATH + "/ButtonAssertionsTest");
32      }
33  
34      @Test
35      public void testAssertButtonwithOneFormfound() {
36          beginAt("/pageWithOneForm.html");
37          assertSubmitButtonPresent();
38          assertButtonPresent("button1");
39          assertButtonPresent("buttonOutside");
40          setWorkingForm("form1");
41          assertSubmitButtonPresent();
42          assertButtonPresent("button1");
43          assertButtonPresent("buttonOutside");
44          assertButtonPresent("button1");
45          assertButtonPresent("buttonOutside");
46          
47          // test for issue 1874971 
48          assertButtonPresentWithText("Input button");
49      }
50  
51      @Test
52      public void testAssertButtonwithTwoFormsFound() {
53          beginAt("/pageWithTwoForms.html");
54          assertButtonPresent("button1");
55          assertButtonPresent("button2");
56          assertButtonPresent("buttonOutside");
57          setWorkingForm("form1");
58          assertButtonPresent("button1");
59          assertButtonPresent("button2");
60          assertButtonPresent("buttonOutside");
61          setWorkingForm("form2");
62          assertButtonPresent("button1");
63          assertButtonPresent("button2");
64          assertButtonPresent("buttonOutside");
65          assertButtonPresent("button1");
66          assertButtonPresent("button2");
67          assertButtonPresent("buttonOutside");
68      }
69      
70      @Test
71      public void testAssertButtonWithText() {
72          beginAt("/pageWithTwoForms.html");
73          assertButtonPresentWithText("Testbutton");
74          assertButtonPresentWithText("Testbutton2");
75          assertButtonPresentWithText("Outside");
76          setWorkingForm("form1");
77          assertButtonPresentWithText("Testbutton");
78          assertButtonPresentWithText("Testbutton2");
79          assertButtonPresentWithText("Outside");
80          assertButtonPresentWithText("the submit btn");
81          assertButtonPresentWithText("the reset btn");
82          assertButtonPresentWithText("the btn btn");
83          setWorkingForm("form2");
84          assertButtonPresentWithText("Testbutton");
85          assertButtonPresentWithText("Testbutton2");
86          assertButtonPresentWithText("Outside");
87          assertButtonPresentWithText("Testbutton");
88          assertButtonPresentWithText("Testbutton2");
89          assertButtonPresentWithText("Outside");
90      }
91      
92      /**
93       * As per the semantics of {@link WebTester#assertButtonPresentWithText(String)}, 
94       * buttons that are not currently displayed are still "present".
95       */
96      @Test
97      public void testHiddenButtonsAreStillFound() {
98      	beginAt("/pageWithOneForm.html");
99      	assertButtonPresentWithText("Hidden Input");
100     	assertButtonPresentWithText("Hidden Button");
101     }
102 
103 }