File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Trouble using HttpUnit with Struts 2 tabbedpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Trouble using HttpUnit with Struts 2 tabbedpanel" Watch "Trouble using HttpUnit with Struts 2 tabbedpanel" New topic
Author

Trouble using HttpUnit with Struts 2 tabbedpanel

Brandon Headrick
Greenhorn

Joined: Jun 03, 2009
Posts: 4
So, I'm trying to use HttpUnit to test a webpage. However, I'm not sure how to follow tabbedpanel(s) from Struts 2. I tried treating it like a normal webpage, in the code below; however, the submit() method for the button I'm trying to select, "New," either doesn't appear to work or, what I suspect is more likely, it just pushes the button and doesn't know to go anywhere because of the tabbedpanel. I'm new to Struts 2 and HttpUnit, so any help would be useful. I've commented heavily, and to some degree, unnecessarily, so I hope it's enough to get some help.

Thanks.


Here's the code snippet.

public void testNewOrder() throws Exception
{

//turn off scripting for certain tests; Turn off javascript interpreting; required because of depricated dojo conflicts.
HttpUnitOptions.setScriptingEnabled(false);

//webConv represents browser (emulates browser behavior)
WebConversation webConversation = new WebConversation();
//webResp represents page (actual response from website).
//Pass address to getResponse method from browser, put that into the page
// instance
WebResponse webResponse = webConversation.getResponse(ADDRESS);

WebForm form = webResponse.getForms()[0]; //select first form in page

//create a submitButton Array populated with the buttons from the form
SubmitButton[] buttons = form.getSubmitButtons();

System.out.println(buttons[0]);//New //just s.o.p code to remind me which buttons are which.
System.out.println(buttons[1]);//Edit
System.out.println(buttons[2]);//Delete
System.out.println(buttons[3]);//<<
System.out.println(buttons[4]);//<
System.out.println(buttons[5]);//Go
System.out.println(buttons[6]);//>
System.out.println(buttons[7]);//>>


//follow the "New" button.
WebResponse newOrderPage = form.submit(buttons[0]);

//populate this form with the forms on the "New" page
WebForm newOrderPageForm = newOrderPage.getForms()[0];

String[] parameterList = newOrderPageForm.getParameterNames();

System.out.println(parameterList[0]); //This s.o.p. tells me that the parameters of the new page, which should contain 6 variables,
System.out.println(parameterList[1]); //that correspond to different textfields, are not on the page, instead it pulls the parameters
System.out.println(parameterList[2]); //from the "home" page (which has 5 parameters).
System.out.println(parameterList[3]);
System.out.println(parameterList[4]);

}

EDIT: I now believe it to be more of an Ajax issue than a tabbedpanel issue. I'm going to post a different problem, however, it is still slightly related, on the testing board if you think you can still help me.
Ahmed Ashour
Greenhorn

Joined: Jun 03, 2009
Posts: 2
HtmlUnit is far more better
Brandon Headrick
Greenhorn

Joined: Jun 03, 2009
Posts: 4
Maybe so, I don't really know. However, I have to use HttpUnit for my job; those are my instructions, and there may be a reason that I have to use HttpUnit in their design.

EDIT: I've talked to my boss; I may be changing over the work to HtmlUnit instead. Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble using HttpUnit with Struts 2 tabbedpanel
 
Similar Threads
HttpUnit- Installation
sensing submit in servlet
button.click() not working ,ie HTTPUNIT
Session problem while trying to login automatically into app using httpunit API
HttpUnit and Ajax enabled submit buttons