01: /******************************************************************************
02: * jWebUnit project (http://jwebunit.sourceforge.net) *
03: * Distributed open-source, see full license under LICENCE.txt *
04: ******************************************************************************/package net.sourceforge.jwebunit.tests;
05:
06: import junit.framework.Test;
07: import junit.framework.TestSuite;
08: import net.sourceforge.jwebunit.tests.util.JettySetup;
09:
10: /**
11: * @author henryju
12: */
13:
14: public class JavaScriptTest extends JWebUnitAPITestCase {
15:
16: public static Test suite() {
17: Test suite = new TestSuite(JavaScriptTest.class);
18: return new JettySetup(suite);
19: }
20:
21: public void setUp() throws Exception {
22: super .setUp();
23: getTestContext().setBaseUrl(HOST_PATH + "/JavaScriptTest");
24: }
25:
26: public void testDocumentWrite() {
27: beginAt("DocumentWrite.html");
28: //FIXME Fails with HtmlUnit
29: //assertTextPresent("Hello World");
30: }
31:
32: public void testAlert() {
33: setExpectedJavaScriptAlert("Foo Bar");
34: beginAt("Alert.html");
35: }
36:
37: public void testInvalidAlertOnPageLoad() {
38: setExpectedJavaScriptAlert("invalid");
39: try {
40: beginAt("Alert.html");
41: fail();
42: } catch (RuntimeException e) {
43: //OK
44: }
45: }
46:
47: public void testMultipleAlerts() {
48: setExpectedJavaScriptAlert(new String[] { "Alert 1", "Alert 2" });
49: beginAt("MultipleAlerts.html");
50: }
51:
52: public void testConfirm() {
53: setExpectedJavaScriptConfirm("Foo Bar", true);
54: beginAt("Confirm.html");
55: assertLinkPresent("Toto");
56: assertLinkNotPresent("Titi");
57: }
58:
59: public void testPrompt() {
60: setExpectedJavaScriptPrompt("Foo Bar", "toto");
61: beginAt("Prompt.html");
62: assertTextPresent("Toto");
63: }
64:
65: public void testPromptCanceled() {
66: setExpectedJavaScriptPrompt("Foo Bar", null);
67: beginAt("Prompt.html");
68: assertTextPresent("Cancel");
69: }
70: }
|