1818 */
1919package net .sourceforge .jwebunit .tests ;
2020
21+ import junit .framework .AssertionFailedError ;
22+
2123import java .io .BufferedWriter ;
2224import java .io .File ;
2325import java .io .FileWriter ;
3234
3335/**
3436 * Test form submission related methods of WebTestCase.
35- *
37+ *
3638 * If there is more than one submit button on a page, WebTestCase / httpunit
3739 * require indication of which button to submit with prior to form submission.
38- *
40+ *
3941 * @author Jim Weaver
4042 */
4143public class FormSubmissionTest extends JWebUnitAPITestCase {
@@ -94,7 +96,7 @@ public void testSetFileField() {
9496 //The following depend on the browser: IE send full path (i.e. temp.getAbsolutePath()) but FF send only file name.
9597 assertTextPresent ("file=[" + temp .getName () + "{abcdefgh}]" );
9698 }
97-
99+
98100 @ Test
99101 public void testSubmitImageInput () {
100102 beginAt ("/InputImageForm.html" );
@@ -158,22 +160,22 @@ public void testCheckBoxDeselection() {
158160 submit ();
159161 assertTextPresent ("color=[blue]" );
160162 }
161-
163+
162164 @ Test
163165 public void testRadioSelection () {
164- beginAt ("/RadioForm.html" );
165- clickRadioOption ("radio" , "1" );
166- assertRadioOptionSelected ("radio" , "1" );
167- submit ();
168- assertTextPresent ("radio=[1]" );
169- clickLink ("return" );
170- clickRadioOption ("radio" , "2" );
171- clickRadioOption ("radio" , "3" );
172- assertRadioOptionNotSelected ("radio" , "1" );
173- assertRadioOptionNotSelected ("radio" , "2" );
174- assertRadioOptionSelected ("radio" , "3" );
175- submit ();
176- assertTextPresent ("radio=[3]" );
166+ beginAt ("/RadioForm.html" );
167+ clickRadioOption ("radio" , "1" );
168+ assertRadioOptionSelected ("radio" , "1" );
169+ submit ();
170+ assertTextPresent ("radio=[1]" );
171+ clickLink ("return" );
172+ clickRadioOption ("radio" , "2" );
173+ clickRadioOption ("radio" , "3" );
174+ assertRadioOptionNotSelected ("radio" , "1" );
175+ assertRadioOptionNotSelected ("radio" , "2" );
176+ assertRadioOptionSelected ("radio" , "3" );
177+ submit ();
178+ assertTextPresent ("radio=[3]" );
177179 }
178180
179181 @ Test
@@ -259,14 +261,20 @@ public void testSetWorkingFormWithSameName() {
259261 assertSubmitButtonPresent ("myInput2" );
260262 }
261263
264+ @ Test (expected =AssertionError .class )
265+ public void testSetWorkingFormWithIndexPresent () {
266+ beginAt ("/MultiFormPage.html" );
267+ setWorkingForm ("dontExists" , 2 );
268+ }
269+
262270 @ Test
263271 public void testInvalidButton () {
264272 beginAt ("/InvalidActionForm.html" );
265273 try {
266- submit ("button1" );
267- fail ("A TestingEngineResponseException was expected." );
274+ submit ("button1" );
275+ fail ("A TestingEngineResponseException was expected." );
268276 } catch (TestingEngineResponseException e ) {
269- assertEquals (404 , e .getHttpStatusCode ());
277+ assertEquals (404 , e .getHttpStatusCode ());
270278 }
271279 }
272280
@@ -325,7 +333,7 @@ public void testSelectOptionByValue() {
325333 private void gotoMultiButtonPage () {
326334 beginAt ("/MultiNamedButtonForm.html" );
327335 }
328-
336+
329337 @ Test
330338 public void testCachedForm () {
331339 beginAt ("/Submit1.html" );
@@ -335,7 +343,7 @@ public void testCachedForm() {
335343 submit ();
336344 assertTextPresent ("Page 3" );
337345 }
338-
346+
339347 /**
340348 * Submit input
341349 */
@@ -347,7 +355,7 @@ public void testClickButtonWithText1() {
347355 assertTextPresent ("Submitted parameters" );
348356 assertTextPresent ("color=[blue]" );
349357 }
350-
358+
351359 @ Test
352360 public void testSetHiddenField () {
353361 beginAt ("/SingleNamedButtonForm.html" );
0 commit comments