View Full Version : HtmlUnit - handling client side redirect
kalensr
11-02-2005, 01:16 PM
Greetings:
Below I have posted some examples of both successfully handling client
side redirect using HTTPUnit to log into an appliction, as well as my
attempt to log into the same application using HTMLUnit.
If anyone has any suggestions for me I would greatly appreciate the
help.
Thanks
___________________
Client side redirect indicated by:
<noscript><meta http-equiv="Refresh"
content="0;URL=NoJS.jsp"></noscript>
Handled in HttpUnit like such:
WebResponse response = form.submit();
WebRequest refreshReq;
refreshReq = response.getRefreshRequest();
System.out.println("refresh request: " + refreshReq.getURL());
// get new response using refreshReq URL
response = wc.getResponse(refreshReq.getURL().toString());
assertNotNull("Response from Refresh Request: ", response);
Attempting to perform same actions in HtmlUnit:
final WebClient webClient = new
WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
webClient.setRefreshHandler(new ImmediateRefreshHandler());
webClient.setRedirectEnabled(true);
webClient.setThrowExceptionOnFailingStatusCode(false);
final URL url = new URL(envUrl);
final HtmlPage page = (HtmlPage)webClient.getPage(url);
final HtmlForm form = page.getFormByName("main");
form.setAttributeValue("webId", id);
form.setAttributeValue("password", pwd);
Page newPage = form.submit();
assertNotNull("new page/", newPage);
newPage.initialize();
WebResponse response = newPage.getWebResponse();
RESULT
I am not able to log in using HtmlUnit but I am successful using
HttpUnit.
Phlip
11-02-2005, 06:48 PM
kalensr wrote:
RESULT I am not able to log in using HtmlUnit but I am successful using HttpUnit.
I'm the only one here who uses HttpUnit. I don't know the answer to this one
(except to avoid HtmlUnit for you).
Can you try the HttpUnit mailing list?
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
kalensr
11-03-2005, 05:52 AM
Thanks Phlip - I will try some other mailing lists and see what I find.
kalensr
Phlip
11-03-2005, 06:27 AM
kalensr wrote:
Thanks Phlip - I will try some other mailing lists and see what I find.
You forgot to mention why you need this feature. Just use HttpUnit, right?
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
kalensr
11-03-2005, 09:37 AM
I have some existing tests that allow me to log into a web product and
test several features. These tests are created in HttpUnit and I am
very happy with the results. I have many many more pages and features
to test in this product.
I am considering migrating to HtmlUnit to make use of its features. It
seems that HtmlUnit will allow me to focus on testing/validating
features of the application by way of html pages without focusing so
much on request/response objects such as HttpUnit. If HtmlUnit can
handle these 'behind the scenes' activities I should be able to write
my tests quicker with less code.
So; my problem with HtmlUnit at this time is not being able to log into
the application.
Phlip
11-03-2005, 08:41 PM
kalensr wrote:
So; my problem with HtmlUnit at this time is not being able to log into the application.
I thought HtmlUnit simply parsed and tested HTML. I suspect you are using an
addition to it that also drives Internet Explorer to hit a real web server.
Bind tests that use HtmlUnit directly to the low-level functions that
produce HTML. (If you can't get them, squawk on the mailing list of whatever
tool creates them. That tool should not abjectly bond to a web server.)
Then collect each HTML page as a string, not a real 'net hit. Test away.
Also, write more JUnit tests on the functions _below_ the functions that
produce HTML. The goal is most test cases directly call the tested
functionality, decoupled from other units.
HTTPUnit uses the web's native decoupling, and it makes scenarios
deceptively easy to write. But don't use it to test all the nuts and bolts
that could have more direct tests.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
kalensr
11-04-2005, 07:34 AM
You are correct in that I should not be testing 'everything and the
kitchen sink'. There is still quite a bit to automated in the
application just to complete a release check out script that provides
satisfactory coverage. In fact, I limiting my research of HtmlUnit to a
couple more days. If I have not made a considerable amount of head way
I am going back to HttpUnit.
Although there are a lot of reviews and opinions of test automation
tools, the next quote is what brought me to the conclusion that
investigating HtmlUnit might not be a bad thing.
"HtmlUnit is an excellent package that does a very good job of
automating end-to-end tests. With its focus on analyzing the result of
a Web request-its comprehensive HTML page object model-HtmlUnit is
an ideal choice for automating end-to-end tests for Web applications"
per -Testing J2EE Applications at:
http://www.javaworld.com/javaworld/jw-08-2004/jw-0830-testing.html
Also see:
http://pyre.third-bit.com/2004-fall/hippo_testing_ae.html#htmlunit
kalensr
11-04-2005, 12:03 PM
Another reason for researching HtmlUnit is the next big challenge that
I have in testing my application. I am working with iframes and
javascript. From what I understand HtmlUnit is a better tool for
working with these components.
Since this is a different subject, I will post my specific question as
a new subject in this group.
Thanks,
Kalen
dj777
11-30-2005, 02:57 AM
form.setAttributeValue("webId", id);
form.setAttributeValue("password", pwd);
I think you are setting attributes on the form itself... you probably need to get the text input objects out of the form and set the value on the input objects instead...
olivia2046
12-20-2005, 09:55 PM
Hello, kalensr, I am experiencing the same problem as you stated here.
Have you figured out the resolution yet?
MyLounge.com Site Map
Forum:
Cars,
Cell Phone,
Database,
Games,
Home Improvement,
IT,
Music,
School,
Sports,
Web Design,
Web Server,
Weight Loss
The MyLounge.com forum is intended for informational use only and should not
be relied upon and is not a substitute for any advice. The information contained
on MyLounge.com are opinions and suggestions of members and is not a representation
of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for
the accuracy, completeness or usefulness of any postings or the qualifications
of any person responding. Please consult a expert or seek the services of an
attorney in your area for more accuracy on your specific situation. Please note
that our forums also serve as mirrors to Usenet newsgroups. Many posts you see
on our forums are made by newsgroup users who may not be members of MyLounge.com
Term of Service
vBulletin v3.0.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.