wood burning stoves 2.0*
The moose likes Testing and the fly likes Unit Testing the page validation errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Unit Testing the page validation errors" Watch "Unit Testing the page validation errors" New topic
Author

Unit Testing the page validation errors

Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi All,

I'm developing a set of unit/integration tests using HttpUnit. So far went fine checking the functionality of the system. However, I'm facing the problem for checking the validation errors.

Scenario is like this
a) On a page , we enter few values in the form and click on submit.
b) If the values entered pass through validations (Client Side) then
it is pushed to the servlet for further processing.
So far, on happy path and other alternative paths, where in input values pass the validation is working fine.

c) Now I need to provide some wrong data and the input page should be returned back saying asking to correct the values.

Implementation of the point "C" is not yet finalized, but we assume that error messages are displayed beside the corresponding form elements with some red color.

Now the challenge I have here is to parse the response and assert that proper error messages are displayed for the wrong data.


The approach, which I'm thinking is to parse the response (WebResponse) and make DOM tree, since basically the response is a html. Once this is done, I need to handle each of these elements separately. I tried to use JDOM but failed, as the response I may get back may not be well formed. So I need to make a similar API like JDOM or some thing else to accomplish this. I get a feeling that, I'm trying to reach my nose from the other direction round back my head. Can some one suggest me a better solution here.

By the way, we are permitted to use JUnit and HttpUnit only.


Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hello All,

Can some one throw some light on my problem.

My basic question is "How to" unit test page level, field level validations.

Say, if I enter date of birth in a wrong format the client side validation would throw me an error. How can I ensure that it is happening through an automated tests. Please suggest some frameworks that I can use to test in generic way for Plain HTML, XML, JSP and JSF based pages. I found different frameworks for different technologies, but I'm looking for some generic framework (which can be tweaked) to solve my issue.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Schandha Ravi:
Say, if I enter date of birth in a wrong format the client side validation would throw me an error. How can I ensure that it is happening through an automated tests. Please suggest some frameworks that I can use to test in generic way for Plain HTML, XML, JSP and JSF based pages. I found different frameworks for different technologies, but I'm looking for some generic framework (which can be tweaked) to solve my issue.

The only generic framework I can think of for something like this would be JUnit. After all, it is a generic test framework. JSP and JSF as technologies are worlds apart and therefore you're unlikely to find a single framework that supports both, other than by deploying the whole application to a web container and pointing a tool such as HttpUnit at the running application.

Earlier you said that you tried parsing the HTML as XML:
Originally posted by Schandha Ravi:
I tried to use JDOM but failed, as the response I may get back may not be well formed.

What if you'd first run the response through JTidy? I've done that in the past and it worked alright for me.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Thanks Lasse,

I believe I may try JTidy to check my problem.
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
Here's how I dealt with this ine one of my Acceptance Tests, using JWebUnit, DbUnit, and JUnit.

"tester" is simple WebTester from JWebUnit (needed since I couldn't use their base class for my test case)


This is slightly more frail than i would like as it hard codes the exact error message.... Now if the exact wording is a formal requirement and isn't likely to change, that might be acceptable. For me I'm not too happy with it and I've been playing with alternatives, but nothing has struck be a sufficiently better yet. (Though I'm leaning towards simply searching for an element with id="error-email") ... That would be flexible against wording changes and styling changes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unit Testing the page validation errors
 
Similar Threads
Presentation of the Validation Warnings
Java Script for testing
link css style sheet
How to test validation errors in Struts
Displaying error in multi page form.