KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jwebunit > FramesAndWindowsTest


1 /********************************************************************************
2  * Copyright (c) 2001, ThoughtWorks, Inc.
3  * Distributed open-source, see full license under licenses/jwebunit_license.txt
4  **********************************/

5 package net.sourceforge.jwebunit;
6
7 /**
8  * User: djoiner
9  * Date: Nov 21, 2002
10  * Time: 11:35:52 AM
11  */

12
13 public class FramesAndWindowsTest extends JWebUnitTest {
14
15     public void setUp() throws Exception JavaDoc {
16         super.setUp();
17         defineWebPage("RootPage",
18                 "This is the Root" +
19                 "<form name='realform'><input name='color' value='blue'></form>" +
20                 "<a id=\"SetColorGreen\" HREF='nothing.html' onClick=\"JavaScript:document.realform.color.value='green';return false;\">green</a>" +
21                 "<a id=\"ChildPage1\" HREF=\"\" onClick=\"JavaScript:window.open('ChildPage1.html', 'ChildPage1');\">green</a>" +
22                 "<a id=\"ChildPage2\">Child Page 2</a>\n");
23         defineWebPage("ChildPage1", "This is child 1");
24         defineWebPage("ChildPage2", "This is child 2");
25         defineResource("Frames.html", "<html><head></head><frameset rows=\"33%, 33%, 33%\"><frame name=\"TopFrame\" SRC=\"TopFrame.html\"><frame name=\"ContentFrame\" SRC=\"ContentFrame.html\"><frame name=\"BottomFrame\" SRC=\"BottomFrame.html\"></frameset></html>");
26         defineWebPage("TopFrame", "<html><body>TopFrame</body></html>");
27         defineWebPage("ContentFrame", "<html><body>ContentFrame" +
28                         "<form name='frameForm' method ='GET' action='TargetPage'>" +
29                         " <input name='color' value='blue'>" +
30                         " <input type='submit'>" +
31                         "</form></body></html>");
32         defineWebPage("BottomFrame", "<html><body>BottomFrame</body></html>");
33         defineResource("TargetPage?color=red", "<html><body>This is the red page</html></body>");
34         defineResource("TargetPage?color=green", "<html><head><title>Frames2</title></head><frameset rows=\"33%, 33%, 33%\"><frame name=\"TopFrame\" SRC=\"TopFrame.html\"><frame name=\"ContentFrame\" SRC=\"ContentFrame.html\"><frame name=\"BottomFrame\" SRC=\"BottomFrame.html\"></frameset></html>");
35         defineResource("InlineFrame.html",
36         "<html><head></head><body>TopFrame<br/><iframe name=\"ContentFrame\" SRC=\"ContentFrame.html\"/></body></html>");
37         defineWebPage("ContentFrame", "<html><body>ContentFrame" +
38                         "<form name='frameForm' method ='GET' action='TargetPage'>" +
39                         " <input name='color' value='blue'>" +
40                         " <input type='submit'>" +
41                         "</form></body></html>");
42
43     }
44
45     public void testOpenWindow() throws Throwable JavaDoc {
46         gotoRootAndOpenChild("ChildPage1");
47         assertPassFail("assertWindowPresent", new Object JavaDoc[]{"ChildPage1"}, new Object JavaDoc[]{"NoSuchChild"});
48     }
49
50     //todo: move to javascript events test
51
public void testGreenLink() {
52         beginAt("RootPage.html");
53         assertFormElementEquals("color", "blue");
54         clickLink("SetColorGreen");
55         assertFormElementEquals("color", "green");
56     }
57
58     public void testGotoWindow() {
59         gotoRootAndOpenChild("ChildPage1");
60         gotoWindow("ChildPage1");
61         assertTextPresent("child 1");
62     }
63
64     public void testSwitchWindows() {
65         gotoRootAndOpenChild("ChildPage1");
66         gotoWindow("ChildPage1");
67         gotoRootWindow();
68         assertTextPresent("This is the Root");
69     }
70
71     private void gotoRootAndOpenChild(String JavaDoc childName) {
72         beginAt("RootPage.html");
73         clickLink(childName);
74     }
75
76     public void testGotoFrame() {
77         beginAt("Frames.html");
78         assertFramePresent("TopFrame");
79         gotoFrame("TopFrame");
80         assertTextPresent("TopFrame");
81         assertFramePresent("BottomFrame");
82         gotoFrame("BottomFrame");
83         assertTextPresent("BottomFrame");
84         assertFramePresent("ContentFrame");
85         gotoFrame("ContentFrame");
86         assertTextPresent("ContentFrame");
87     }
88
89     /**
90      * Broken in httpunit
91      *
92      */

93     public void testGotoInlineFrame() {
94         beginAt("InlineFrame.html");
95         assertTextPresent("TopFrame");
96         gotoFrame("ContentFrame");
97         assertTextPresent("ContentFrame");
98     }
99
100     public void testFormInputInFrame() {
101         beginAt("Frames.html");
102         gotoFrame("ContentFrame");
103         setFormElement("color", "red");
104         submit();
105         assertTextPresent("This is the red page");
106     }
107
108     public void testFormInputInFrameToFrame() {
109         beginAt("Frames.html");
110         gotoFrame("ContentFrame");
111         setFormElement("color", "green");
112         submit();
113         assertTitleEquals("Frames2");
114     }
115
116 }
117
Popular Tags