1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
30
31
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
42
43
44 private void gotoRootAndOpenChild(String childName) {
45 beginAt("RootPage.html");
46 clickLink(childName);
47 }
48
49
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
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
143 assertTextNotPresent("ContentFrame");
144 gotoFrame("ContentFrame");
145 assertTextPresent("ContentFrame");
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 }