1 package net.sourceforge.jwebunit; 2 3 import net.sourceforge.jwebunit.JWebUnitTest; 4 5 12 public class WebAssertionsTest extends JWebUnitTest { 13 14 public void setUp() throws Exception { 15 super.setUp(); 16 addTestPage(); 17 beginAt("/testPage.html"); 18 } 19 20 public void testAssertTitleEquals() throws Throwable { 21 assertPass("assertTitleEquals", new String []{"testPage"}); 22 assertFail("assertTitleEquals", "wrong title"); 23 } 24 25 public void testAssertTextPresent() throws Throwable { 26 assertPassFail("assertTextPresent", "This is a test page.", "no such text"); 27 } 28 29 public void testAssertTextNotPresent() throws Throwable { 30 assertPassFail("assertTextNotPresent", "no such text", "This is a test page."); 31 } 32 33 public void testAssertLinkPresentWithText() throws Throwable { 34 assertPassFail("assertLinkPresentWithText", "test link", "no such link"); 35 } 36 37 public void testAssertLinkNotPresentWithText() throws Throwable { 38 assertPassFail("assertLinkNotPresentWithText", "no such link", "test link"); 39 } 40 41 public void testAssertLinkPresentWithTextN() throws Throwable { 42 assertPass( 43 "assertLinkPresentWithText", 44 new Object [] { "test link", new Integer (0)}); 45 assertFail( 46 "assertLinkPresentWithText", 47 new Object [] { "test link", new Integer (1)}); 48 } 49 50 public void testAssertLinkNotPresentWithTextN() throws Throwable { 51 assertPass( 52 "assertLinkNotPresentWithText", 53 new Object [] { "test link", new Integer (1)}); 54 assertFail( 55 "assertLinkNotPresentWithText", 56 new Object [] { "test link", new Integer (0)}); 57 } 58 59 public void testAssertLinkPresent() throws Throwable { 60 assertPassFail("assertLinkPresent", "test_link_id", "no_link_id"); 61 } 62 63 public void testAssertLinkNotPresent() throws Throwable { 64 assertPassFail("assertLinkNotPresent", "no_link_id", "test_link_id"); 65 } 66 67 public void testAssertLinkPresentWithImage() throws Throwable { 68 assertPassFail("assertLinkPresentWithImage", "graphic.jpg", "nosuchgraphic.jsp"); 69 } 70 71 public void testAssertLinkNotPresentWithImage() throws Throwable { 72 assertPassFail("assertLinkNotPresentWithImage", "nosuchgraphic.jpg", "graphic.jpg"); 73 } 74 75 public void testAssertElementPresent() throws Throwable { 76 assertElementPresent("row1"); 77 assertPassFail("assertElementPresent", "span_id", "no_id"); 78 } 79 80 public void testAssertElementNotPresent() throws Throwable { 81 assertPassFail("assertElementNotPresent", "no_id", "span_id"); 82 } 83 84 public void testAssertTextNotInElement() throws Throwable { 85 assertTextNotInElement("outer_id", "nosuchtext"); 86 assertTextNotInElement("inner_id", "Outer"); 87 assertFail("assertTextNotInElement", new Object [] {"outer_id", "Outer"}); 88 } 89 90 public void testAssertElementContainsText() throws Throwable { 91 assertTextInElement("span_id", "Span"); 92 assertTextInElement("span_id", "Text"); 93 assertTextInElement("span_id", "Span Text"); 94 assertFail("assertTextInElement", new Object [] {"span_id", "Not Text"}); 95 } 96 public void testAssertElementContainsTextInChild() throws Throwable { 97 assertTextInElement("outer_id", "Outer"); 98 assertTextInElement("outer_id", "Text"); 99 assertTextInElement("outer_id", "Inner Text"); 100 assertTextInElement("outer2", "$100,000/$300,000"); 101 } 102 103 104 private void addTestPage() { 105 defineWebPage("testPage", "This is a test page." + 106 "<table summary=\"testTable\">" + 107 "<tr ID=\"row1\"><td>table text</td></tr>" + 108 "<tr><td>table text row 2</td></tr>" + 109 "<tr><td>table text row 3</td><td>row 3 col 1</td>" + 110 "<a id=\"test_link_id\" HREF=\"someurl.html\">test link</a>" + 111 112 "<a HREF=\"somepage.html\">" + 113 "<img height=\"22\" width=\"22\" alt=\"New User\" SRC=\"firstimage.gif\">" + 114 "<img SRC=\"graphic.jpg\"alt=\"New User\" /></a>" + 115 "<form>" + 116 "<input type=\"text\" name=\"testInputElement\" value=\"testValue\"/>" + 117 "<input type=\"submit\" name=\"submitButton\" value=\"buttonLabel\"/>" + 118 "<input type=\"checkbox\" name=\"checkboxselected\" CHECKED>" + 119 "<input type=\"checkbox\" name=\"checkboxnotselected\">" + 120 "</form>" + 121 "<span id=\"span_id\">Span Text</span>" + 122 "<span id=\"outer_id\">Outer <span id=\"inner_id\">Inner Text</span> Text</span>" + 123 "<form name=\"form2\"></form>" + 124 "<form name=\"form3\">" + 125 "<table><tr><td>" + 126 "<span id=\"outer2\" >" + 127 "<input type=\"hidden\" name=\"hidden\" value=\"h\" />$100,000/$300,000</span>" + 128 "</td></tr></table>" + "</table>" + 129 "</form>"); 130 defineWebPage("noFormPage", ""); 131 } 132 133 } 134 | Popular Tags |