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  import static org.junit.Assert.*;
23  
24  import static org.hamcrest.Matchers.containsString;
25  
26  import org.junit.Test;
27  
28  /**
29   * User: djoiner
30   * Date: Nov 21, 2002
31   * Time: 11:35:52 AM
32   */
33  public class FramesAndWindowsTest extends JWebUnitAPITestCase {
34      
35      public void setUp() throws Exception {
36          super.setUp();
37          setBaseUrl(HOST_PATH + "/FramesAndWindowsTest");
38      }
39      
40      /**
41       * helper function
42       * @param childName
43       */
44      private void gotoRootAndOpenChild(String childName) {
45          beginAt("RootPage.html");
46          clickLink(childName);
47      }
48      
49      // ------------ windows test ------------    
50      
51      @Test public void testOpenWindow() throws Throwable {
52          gotoRootAndOpenChild("ChildPage1");
53          assertPassFail("assertWindowPresent", new Object[]{"ChildPage1"}, new Object[]{"NoSuchChild"});
54      }   
55  
56      @Test
57      public void testGotoWindow() {
58          gotoRootAndOpenChild("ChildPage1");
59          gotoWindow("ChildPage1");
60          assertTextPresent("Child Page 1");
61      }
62      
63      @Test
64      public void testGotoWindowByTitle() {
65          gotoRootAndOpenChild("ChildPage2");
66          gotoWindowByTitle("Child Page 2");
67          assertTextPresent("This is child 2");
68      }
69      
70      @Test public void testAssertWindowWithTitle() throws Throwable {
71          gotoRootAndOpenChild("ChildPage2");
72          assertPassFail("assertWindowPresentWithTitle", new Object[]{"Child Page 2"}, new Object[]{"NoSuchTitle"});
73      }
74  
75      @Test
76      public void testCloseWindow() {
77          beginAt("RootPage.html");
78          assertTitleEquals("This is the Root");
79          clickLink("ChildPage1");
80          gotoWindow("ChildPage1");
81          assertTextPresent("Child Page 1");
82          closeWindow();
83          assertWindowCountEquals(1);
84          assertTitleEquals("This is the Root");
85      }
86  
87      @Test public void testAssertWindowCountEquals() {
88          beginAt("RootPage.html");
89          assertWindowCountEquals(1);
90          clickLink("ChildPage1");
91          assertWindowCountEquals(2);
92          gotoWindow("ChildPage1");
93          closeWindow();
94          assertWindowCountEquals(1);
95      }
96  
97      // ----------- frames test --------------
98  
99      @Test public void testGotoFrame() {
100         beginAt("Frames.html");
101 		assertFramePresent("TopFrame");
102         gotoFrame("TopFrame");
103         assertTextPresent("TopFrame");
104         gotoRootWindow();
105         assertFramePresent("BottomFrame");
106         gotoFrame("BottomFrame");
107         assertTextPresent("BottomFrame");
108         gotoRootWindow();
109 		assertFramePresent("ContentFrame");
110         gotoFrame("ContentFrame");
111         assertTextPresent("ContentFrame");
112         assertException(RuntimeException.class, "gotoFrame",
113 				new Object[] { "BottomFrame" });
114 	}
115     
116     @Test public void testGetFrameSource() {
117         beginAt("Frames.html");
118         assertThat(getPageSource(), containsString("<frameset rows=\"33%, 33%, 33%\">"));
119         gotoFrame("TopFrame");
120         assertTextPresent("TopFrame");
121 	}
122 
123 	@Test public void testGotoFrameById() {
124         beginAt("Frames.html");
125         assertFramePresent("frame1");
126         gotoFrame("frame1");
127         assertTextPresent("TopFrame");
128         gotoRootWindow();
129         assertFramePresent("frame3");
130         gotoFrame("frame3");
131         assertTextPresent("BottomFrame");
132         gotoRootWindow();
133         assertFramePresent("frame2");
134         gotoFrame("frame2");
135         assertTextPresent("ContentFrame");
136         assertException(RuntimeException.class, "gotoFrame", new Object[] { "TopFrame" });
137     }
138 
139     @Test public void testGotoInlineFrame() {
140         beginAt("InlineFrame.html");
141         assertTextPresent("TopFrame");
142         // Is this how it should work? see also the test below
143         assertTextNotPresent("ContentFrame");
144         gotoFrame("ContentFrame");
145         assertTextPresent("ContentFrame"); // only 'ContentFrame' matches frameset tag too
146     }
147 
148     @Test public void testFormInputInFrame() {
149         beginAt("Frames.html");
150         gotoFrame("ContentFrame");
151         assertFormPresent();
152         setTextField("color", "red");
153         submit("submit");
154         assertTextPresent("color=[red]");
155     }
156 
157     @Test public void testFormInputInInlineFrame() {
158         beginAt("InlineFrame.html");
159         gotoFrame("ContentFrame");
160         assertFormPresent();
161         setTextField("color", "red");
162         submit("submit");
163         assertTextPresent("color=[red]");
164     }
165 
166 }