From: Rares Portan/SPR/RO <rp...@sa...> - 2005-03-04 14:54:06
|
Hello Dan, thank for the feedback. The bean was just an example, but there are other cases(like when the page requested by the user may be Page1 if some server conditions are meet, or Page2 otherwise) that depend on "invisible" session attributes. Anyway I know now what HtmlUnit can do and cannot do, it;s a great tool, but I still need the other tests. So because others may need the same thing I'm sharing with them how I do test my session objects also using only HtmlUnit. I've created a new servlet - named TestServlet :) - that will be used only for my tests. When you need to know a server side object value, create a request to this servlet passing these string parameters: 1) the object name - used by session.getAttribute("objectName") to get the object from session. 2) the method name - the method that will be invoked using reflection on the object retrieved from session 3) the method parameters - parameters used to invoke the method( hint: name parameters P0,P1,P2.. to find them easy) The response of the invoked method will be "converted" to string and send back as html something like this: <textarea>method_response</textarea>. I can use then HtmlUnit to parse the response and create my assert stuff. Thanks "Dan Levine" <dl...@ca...> Sent by: htm...@li... 03/03/2005 08:26 PM Please respond to htm...@li... To <htm...@li...> cc Subject RE: [Htmlunit-user] htmlunit and sessions (I am not a Htmlunit veteran, so someone else feel free to correct me) That is not what HtmlUnit is for. You cannot access server side variables. You can check their values though, if the variables are ever used to fill the values of a page (either a form default value or a text display). Similar to what I suggested in my last email, you have to make a page that displays the value of that bean, and then check against that. Usually, this already exists! For instance, since this is a login bean, does the next page show the login name somewhere? (i.e. "hello JoUser") Then you could wrap that username in a span tag and say: (pseudocode obviously) var name = "JoUser" HtmlUnit.setValueInForm(name, formElement) HtmlUnit.submitForm() HtmlUnit.getNewPageThatShowsUsername() AssertEquals(HtmlUnit.getNameElementInNewPage().asText(), name) Since the value on the page comes from the bean, if it matches what you put in the form than the bean was set successfully. You could also create a test page that prints out all of the session object values and then use that for testing all of you bean submit comparisons. You might also want to look into using Cactus for these tests, as that is a server side unit testing tool. HtmlUnit is made for black box testing of web apps on the Web tier. Dan -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Rares Portan/SPR/RO Sent: Wednesday, March 02, 2005 11:13 PM To: htm...@li... Subject: Re: [Htmlunit-user] htmlunit and sessions Hi, I have some objects kept in session, for example let say I have a LoginBean that has a username field. This object is updated when the form is submitted with the username entered by user in the textfield. And the bean is then used by the middlelayer to get the username. This data is not saved in the database, is just kept in session to identify the user. What I want is to compare the bean.getUsername() value with the value set in the textfield. This is just an example, the problem is that I have some session objects that are updated all the time based on user actions and I feel that I can't make complete tests for my application without testing them. HtmlForm form=.. HtmlInput username=.. String newValue="MyNewValue"; //update the field value username.setValueAttribute(newValue); //submit the form form.submit(); //get object from session LoginBean bean=session.getAttribute("LoginBean"); assertEquals(newValue,bean.getUsername()); Brad Clarke <yo...@br...> Sent by: htm...@li... 03/02/2005 06:25 PM Please respond to htm...@li... To htm...@li... cc Subject Re: [Htmlunit-user] htmlunit and sessions I'm not sure exactly what you mean by "access to the session". Could you give an example? --- Rares Portan/SPR/RO <rp...@sa...> wrote: > Hello, > > I'm using HtmlUnit for a couple of days to create tests for a web app. > To test some of the pages I need to compare the form values with the > values of some objects kept in session. > > I wasn't able to get access to the session, is it possible? How can I do > that? > > Thank you ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |