1 6 package net.sourceforge.jwebunit; 7 8 public class FormAssertionsTest extends JWebUnitTest { 9 10 public void setUp() throws Exception { 11 super.setUp(); 12 addTestPage(); 13 beginAt("/testPage.html"); 14 } 15 16 public void testAssertFormParameterPresent() throws Throwable { 17 assertPassFail("assertFormElementPresent", "testInputElement", "noSuchElement"); 18 assertPass("assertFormElementPresent", "checkboxselected"); 19 assertPass("assertFormElementEmpty", "testInputElement2"); 20 } 21 22 public void testAssertFormParameterNotPresent() throws Throwable { 23 assertPassFail("assertFormElementNotPresent", "noSuchElement", "testInputElement"); 24 } 25 26 public void testAssertFormParameterPresentWithLabel() throws Throwable { 27 assertPassFail("assertFormElementPresentWithLabel", "Test Input", "No Such Label"); 28 assertFail("assertFormElementPresentWithLabel", "This is a test page"); 29 } 30 31 public void testAssertFormParameterNotPresentWithLabel() throws Throwable { 32 assertPassFail("assertFormElementNotPresentWithLabel", "No Such Label", "Test Input"); 33 assertPass("assertFormElementNotPresentWithLabel", "This is a test page"); 34 } 35 36 public void testAssertHasForm() throws Throwable { 37 assertPass("assertFormPresent", NOARGS); 38 beginAt("/noFormPage.html"); 39 assertFail("assertFormPresent", NOARGS); 40 assertPass("assertFormNotPresent", NOARGS); 41 } 42 43 public void testAssertHasNamedForm() throws Throwable { 44 assertPass("assertFormPresent", new String []{"form2"}); 45 assertFail("assertFormPresent", new String []{"noform"}); 46 assertPass("assertFormNotPresent", new String []{"noform"}); 47 } 48 49 public void testAssertFormParameterEquals() throws Throwable { 50 assertPass("assertFormElementEquals", new Object []{"testInputElement", "testValue"}); 51 assertFail("assertFormElementEquals", new Object []{"testInputElement", "noSuchValue"}); 52 assertFail("assertFormElementEquals", new Object []{"noSuchElement", "testValue"}); 53 } 54 55 public void testCheckboxSelected() throws Throwable { 56 assertPassFail("assertCheckboxSelected", "checkboxselected", "checkboxnotselected"); 57 assertFail("assertCheckboxSelected", "nosuchbox"); 58 } 59 60 public void testCheckboxNotSelected() throws Throwable { 61 assertPassFail("assertCheckboxNotSelected", "checkboxnotselected", "checkboxselected"); 62 assertFail("assertCheckboxNotSelected", "nosuchbox"); 63 } 64 65 public void testAssertSubmitButtonPresent() throws Throwable { 66 assertPassFail("assertSubmitButtonPresent", "submitButton", "noSuchButton"); 67 } 68 69 public void testAssertSubmitButtonNotPresent() throws Throwable { 70 assertPassFail("assertSubmitButtonNotPresent", "noSuchButton", "submitButton"); 71 } 72 73 public void testAssertSubmitButtonValue() throws Throwable { 74 assertPassFail("assertSubmitButtonValue", 75 new Object []{"submitButton", "buttonLabel"}, 76 new Object []{"submitButton", "noSuchLabel"}); 77 } 78 79 public void testAssertRadioOptionPresent() throws Throwable { 80 assertPassFail("assertRadioOptionPresent", 81 new String []{"cool", "cat"}, 82 new String []{"cool", "fish"}); 83 } 84 85 public void testAssertRadioOptionNotPresent() throws Throwable { 86 assertPassFail("assertRadioOptionNotPresent", 87 new String []{"cool", "fish"}, 88 new String []{"cool", "cat"}); 89 } 90 91 public void testAssertRadioOptionSelected() throws Throwable { 92 assertPassFail("assertRadioOptionSelected", 93 new String []{"cool", "dog"}, 94 new String []{"cool", "cat"}); 95 } 96 97 public void testAssertRadioOptionNotSelected() throws Throwable { 98 assertPassFail("assertRadioOptionNotSelected", new String []{"cool", "cat"}, new String []{"cool", "dog"}); 99 } 100 101 public void testAssertOptionsEqual() throws Throwable { 102 assertPass("assertOptionsEqual", new Object []{"select1", new String []{"one", "two", "three", "four"}}); 103 assertFail("assertOptionsEqual", new Object []{"select1", new String []{"one", "four", "three", "two"}}); 104 assertFail("assertOptionsEqual", new Object []{"select1", new String []{"one", "two", "three", "four", "five"}}); 105 } 106 107 public void testAssertOptionsNotEqual() throws Throwable { 108 assertFail("assertOptionsNotEqual", new Object []{"select1", new String []{"one", "two", "three", "four"}}); 109 assertPass("assertOptionsNotEqual", new Object []{"select1", new String []{"one", "four", "three", "two"}}); 110 assertPass("assertOptionsNotEqual", new Object []{"select1", new String []{"one", "two", "three", "four", "five"}}); 111 } 112 113 public void testAssertOptionValuesEqual() throws Throwable { 114 assertPass("assertOptionValuesEqual", new Object []{"select1", new String []{"1", "2", "3", "4"}}); 115 assertFail("assertOptionValuesEqual", new Object []{"select1", new String []{"1", "4", "3", "2"}}); 116 assertFail("assertOptionValuesEqual", new Object []{"select1", new String []{"1", "2", "3", "4", "5"}}); 117 } 118 119 public void testAssertOptionValuesNotEqual() throws Throwable { 120 assertFail("assertOptionValuesNotEqual", new Object []{"select1", new String []{"1", "2", "3", "4"}}); 121 assertPass("assertOptionValuesNotEqual", new Object []{"select1", new String []{"1", "4", "3", "2"}}); 122 assertPass("assertOptionValuesNotEqual", new Object []{"select1", new String []{"1", "2", "3", "4", "5"}}); 123 } 124 125 public void testAssertSelectedOptionEquals() throws Throwable { 126 assertPassFail("assertOptionEquals", new String []{"select1", "one"}, new String []{"select1", "two"}); 127 } 128 129 public void testAssertButtonPresent() throws Throwable { 130 assertPassFail("assertButtonPresent", "b1", "nobutton"); 131 } 132 133 public void testAssertButtonNotPresent() throws Throwable { 134 assertPassFail("assertButtonNotPresent", "nobutton", "b1"); 135 } 136 137 private void addTestPage() { 138 defineWebPage("testPage", "This is a test page." + 139 "<table summary=\"testTable\">" + 140 "<tr><td>table text</td></tr>" + 141 "<tr><td>table text row 2</td></tr>" + 142 "<tr><td>table text row 3</td><td>row 3 col 1</td>" + 143 "<a HREF=\"someurl.html\">test link</a>" + 144 "<form id=\"form1\">" + 145 "<input type=\"button\" id=\"b1\"/>" + 146 "<select name=\"selectOption\"><option value=\"1\">One</option><option value=\"2\">Two</option><option value=\"3\">Three</option></select>" + 147 "Test Input : <input type=\"text\" name=\"testInputElement\" value=\"testValue\"/>" + 148 "Test Input 2: <input type=\"text\" name=\"testInputElement2\" value=\"\"/>" + 149 "<input type=\"submit\" name=\"submitButton\" value=\"buttonLabel\"/>" + 150 "<input type=\"checkbox\" name=\"checkboxselected\" CHECKED>" + 151 "<input type=\"checkbox\" name=\"checkboxnotselected\">" + 152 "<textarea name=\"text\" cols=\"44\" rows=\"3\" wrap=\"VIRTUAL\"></textarea>" + 153 "</form>" + 154 "<form name=\"form2\"></form>" + 155 "<form id=\"form3\">" + 156 "<input type=\"radio\" name=\"cool\" value=\"dog\" checked=\"checked\"/>" + 157 "<input type=\"radio\" name=\"cool\" value=\"cat\"/>" + 158 "<input type=\"radio\" name=\"cool\" value=\"chicken\"/>" + 159 "</form>" + 160 "<form id=\"form4\">" + 161 "<select name=\"select1\">" + 162 "<option value=\"1\">one</option>" + 163 "<option value=\"2\">two</option>" + 164 "<option value=\"3\">three</option>" + 165 "<option value=\"4\">four</option>" + 166 "</select>" + 167 "</form>" + 168 "</table>"); 169 defineWebPage("noFormPage", ""); 170 } 171 172 } 173 | Popular Tags |