RE: [Httpunit-develop] Javascript submit of a form; how to retrieve resulting WebResponse
Brought to you by:
russgold
From: Michael S. <mic...@dy...> - 2003-09-29 23:52:57
|
Yep, works beautifully. I replaced the WebClientListener code with a = call to getCurrentPage() instead and the tests run fine. =20 Thanks heaps, =20 Michael =20 P.S. as a separate issue, I think the reason I was having difficulty = with the WebClientListener code was because HttpUnit seems to be = sometimes(?) sending 2 get requests but my server side code detects this = (to stop multiple payments for the same item) and returns an error. =20 When I replaced the code to use getCurrentPage() I've yet to see any = tests fail because of this so far. -----Original Message----- From: Vinu Rukmini [mailto:vin...@ya...] Sent: Tuesday, 30 September 2003 12:54 AM To: htt...@li... Subject: Re: [Httpunit-develop] Javascript submit of a form; how to = retrieve resulting WebResponse Use the WebConversation method getCurrentPage()=20 Hope this helps. =20 Vinu =20 ex:=20 =20 =20 // create a webConversation object WebConversation browser =3D new WebConversation(); // create webresponse object and use getCurrent Page to examine the page = you are on WebResponse response =3D browser.getCurrentPage(); System.out.println("Current Page Title =3D " + = response.getTitle()); // now let's get the form on the current page WebForm resultForm =3D = response.getFormWithName("searchPage"); assertNotNull("Page Does not contain Form: = searchPage",resultForm); // Let's find the table which displays search resultset = rows. =20 =20 // get all the buttons on the form. Button[] buttons =3D resultForm.getButtons(); // let's verify that all expected buttons are present assertEquals( "Select All", buttons[0].getValue().trim() ); assertEquals( "Clear", buttons[1].getValue().trim() ); assertEquals( "Review Data buttons[2].getValue().trim() ); // let's execute Select All onClick() javascript for ( int i =3D0; i < buttons.length ; i++ ) { =20 if ( buttons[i].getValue().trim().equals ("Select All")) { buttons[i].click(); break; } } =20 // navigate to Next page by clicking the submit =20 response =3D resultForm.submit(); =20 // here we sue the same rspons eobject and examine th etitle = of the page we are on.=20 assertFalse("Unable to reach the search page - Application = Error!", response.getTitle().trim().equalsIgnoreCase("Application = Error!")); System.out.println("Detail Page title : >" + = response.getTitle()+"<"); =20 //You can also use this line again if you want to do the same.=20 response =3D browser.getCurrentPage(); =20 =20 _____ =20 Do you Yahoo!? The = <http://shopping.yahoo.com/?__yltc=3Ds%3A150000443%2Cd%3A22708228%2Cslk%3= Atext%2Csec%3Amail> New Yahoo! Shopping - with improved product search |