Hi Yet Again,
The relevant code in HTMLUnit seems to be in WebClient.java:
if( statusCode >= 301 && statusCode <=307 && isRedirectEnabled() ) {
URL newUrl = null;
String locationString = null;
try {
locationString = webResponse.getResponseHeaderValue("Location");
newUrl = expandUrl( fixedUrl, locationString);
}
catch( final MalformedURLException e ) {
getLog().warn("Got a redirect status code ["+statusCode+" "
+webResponse.getStatusMessage()
+"] but the location is not a valid url
["+locationString+"]. Skipping redirection processing.");
return webResponse;
}
getLog().debug("Got a redirect status code ["+statusCode
+"] new location=["+locationString+"]");
if (webRequestSettings.getSubmitMethod().equals(SubmitMethod.GET)
&&
webResponse.getUrl().toExternalForm().equals(locationString) ) {
getLog().warn("Got a redirect but the location is the
same as the page we just loaded ["
+ locationString + "]. Skipping redirection.");
}
else if ((statusCode == 301 || statusCode == 307)
&& method.equals(SubmitMethod.GET) ) {
final WebRequestSettings wrs = new
WebRequestSettings(webRequestSettings, newUrl);
wrs.setRequestParameters(parameters);
return loadWebResponse(wrs);
}
else if (statusCode <= 303) {
final WebRequestSettings wrs = new
WebRequestSettings(webRequestSettings, newUrl);
wrs.setSubmitMethod(SubmitMethod.GET);
return loadWebResponse(wrs);
}
It looks like a simple change could fix this, but not being a java
programmer I'm not all that confident. Can anyone comment as to
whether it makes sense for a GET redirect to the same page to not be
followed, or whether it would make more sense to allow it, and hence
make a fix to HTMLUnit code above? My experience suggests the latter.
If anyone could patch it and send to me I'd be most grateful,
otherwise I'll battle through and see how I go!
regards,
John
On 1/3/07, John and Pip <[EMAIL PROTECTED]> wrote:
Hi Again,
I have now tried loading these pages using Tamper Data to try to look
at what happens.
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ?review?initValidatePNR.do
returns a 302 error and then I get
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do?review?initValidatePNR.do
which returns a 200 code.
So I will try to track down the app developers and find out what is going on.
But, I still don't understand why WebTest can't handle the proper URL:
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do
When I look at this in Tamper Data it shows the first load of this
page giving a 302 error, then a second load of the same page giving a
200 result.
So I think I was on the right track below that WebTest is failing
because it can't handle the same page being reloaded as per this:
[invoke] DEBUG (com.gargoylesoftware.htmlunit.WebClient) - Got a
redirect status code [302] new
location=[https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do]
[invoke] WARN (com.gargoylesoftware.htmlunit.WebClient) - Got a
redirect but the location is the same as the page we just loaded
[https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do].
Skipping redirection.
[invoke] INFO (com.gargoylesoftware.htmlunit.WebClient) -
statusCode=[302] contentType=[text/html]
...
[invoke] DEBUG (com.canoo.webtest.steps.Step) - Step failed at
C:\WebTest\doc\ISIS\testTest.xml:9: with exception
[invoke] com.canoo.webtest.engine.StepFailedException: Step[invoke
"Get the ISIS retrieve booking page" (1/1)]: HTTP error 302, at:
invoke, Step: InvokePage at C:\WebTest\doc\ISIS\testTest.xml:9: with
(resultFilename="response_1167767144056_invoke.html",
taskName="invoke")
I tried using Canoo Webtest: R_1438 then with Canoo Webtest: R_1454
with same result.
Is this a defect in WebTest that I should raise in JIRA and is there a
workaround? Any help much appreciated!
regards,
John
On 1/3/07, John and Pip <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I posted some months back about HTTP 302 errors, and in the thread
> below (snipped down somewhat) was given advise to use ? rather than /
> in the URL so I changed it to :
>
url="https://flightbookings.airnewzealand.co.nz?isbook_en_NZ?book?initSearchForFlights.do
> and it worked.
>
> However, I now need to be able to hit a second "start page" in the
> same web application. That is the URL:
>
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do
> This is a public URL and if you hit it you get a page headed up
> "Retrieve online booking" and with a page title starting "Air New
> Zealand Bookings - Retrieve Booking".
>
> This gives the same 302 error in WebTest.
>
> <failure message="com.canoo.webtest.engine.StepFailedException:
> Step[invoke "Get the ISIS retrieve booking page" (1/1)]:
> HTTP error 302, at: invoke, Step: InvokePage at
> C:\WebTest\doc\ISIS\testTest.xml:6: with
> (resultFilename="response_1167729673189_invoke.html",
> taskName="invoke")"/>
>
> At warn level the console shows:
>
> [invoke] WARN (com.gargoylesoftware.htmlunit.WebClient) - Got a
> redirect but the location is the same as the page we just loaded
>
[https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do].
> Skipping redirection.
>
> Which perhaps is the clue - does this site require a redirection to
> the same URL, and if so is there any way to make WebTest / HTMLUnit
> *not* ignore this?
>
> However, when I follow the same trick of changing / to ? as per:
>
>
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ?review?initValidatePNR.do
>
> I get taken to a completely different page - specifically to
>
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do
>
> The same thing happens if I put that URL directly into a browser so
> I'm just completely confused. Can anyone shed any further light on
> this for me please?
>
> thanks and regards,
> John
>
> Here is the script:
>
> <webtest name="Retrieve PNR" description="no desc yet" >
> &config;
> <steps>
> <invoke
>
url="https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/review/initValidatePNR.do"/>
> </steps>
> </webtest>
>
> and here is the config content:
> <config
> host="registration.airnewzealand.com"
> port="443"
> protocol="https"
> basepath=""
> summary="true"
> saveresponse="true"
> resultpath="..\webtest-results"
> resultfile="results.xml"
> showhtmlparseroutput="false"
> autorefresh="true"
> haltonfailure="false"
> timeout="120">
> <option name="RedirectEnabled" value="true" />
> </config>
>
> I had appended the full debug level output but it exceeded the 40k
> limit so have omitted it.
>
> On 11/18/06, John and Pip <[EMAIL PROTECTED]> wrote:
> > Hi Aarathi and Paul,
> >
> > I tried it and it works. I'm kind of amazed at the apparent black arts
> > involved here - is it some sort of strange handling of pseudo-directory
> > paths in URLS? I notice the URL with the ?s works directly into a browser as
> > well.
> >
> > But I don't understand your comment paul. I wanted it to follow redirects so
> > if default behaviour is to do so why do I need to replace / with ? in the
> > URLs?
> >
> > Thanks and regards,
> > John
> >
> >
> > On 11/17/06, Paul King <[EMAIL PROTECTED]> wrote:
> > > Rob Manthey wrote:
> > > > ok, a moment to learn something ... is this simply the final url (after
> > > > the 302 redirect) or is there something else going on here?
> > >
> > > The default behaviour is to follow redirects. If you want to visit
> > > the 302 page you have to turn redirects off among other things.
> > > I guess we should document this better as it arises quite frequently.
> > >
> > > Cheers,
> > >
> > > Paul.
> > >
> > > > on 17/11/06 11:49 Aarathi Niranjan said the following:
> > > >>
> > > >> Just a suggestion … this works for me … try it:
> > > >>
> > > >>
> > > >>
> > > >> …
> > > >>
> > > >> <steps>
> > > >>
> > > >> <invoke description="ISIS SFF NZ search page"
> > > >>
> >
url="https://flightbookings.airnewzealand.co.nz?isbook_en_NZ?book?initSearchForFlights.do
> > "
> > > >> />
> > > >>
> > > >> </steps>
> > > >>
> > > >> …
> > > >>
> > > >>
> > > >>
> > > >> Hope that helps.
> > > >>
> > > >>
> > > >>
> > > >>
> > ------------------------------------------------------------------------
> > > >>
> > > >> *From:* [EMAIL PROTECTED]
> > > >> [mailto: [EMAIL PROTECTED] *On Behalf Of *Charlie Kuharski
> > > >> *Sent:* Thursday, November 16, 2006 2:50 PM
> > > >> *To:* [EMAIL PROTECTED]
> > > >> *Subject:* Re: [Webtest] HTTP error 302
> > > >>
> > > >>
> > > >>
> > > >> Reaching via a browser is fine. I can see it also. Know that WebTest
> > > >> is build upon the HtmlUnit's API.
> > > >> As far as being reachable via HtmlUnit, this is only a guess, but I'm
> > > >> guessing the URL is passed through to be used by HtmlUnit. So I'm
> > > >> guess it's the culprit. There is a slight chance it's WebTest
> > > >> mangling the name somehow, but I doubt it. Wouldn't know for sure
> > > >> until someone looks at the source.
> > > >> Try using the IP address instead.
> > > >>
> > > >> John and Pip wrote:
> > > >>
> > > >> Hi Charlie,
> > > >>
> > > >> Thanks for your response.
> > > >>
> > > >> Do you mean you couldn't reach
> > > >>
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do
> > > >> from a browser or that you think WebTest believes it is not reachable?
> > > >> This is the main public URL of the Air New Zealand flight booking
> > > >> engine, and we have a screen up in the office showing bookings coming
> > > >> through every minute!
> > > >>
> > > >> re testing with HTMLUnit: I'm not a java programmer - just a tester,
> > > >> trying to figure out whether I need to be a java programmer to use
> > > >> WebTest!
> > > >>
> > > >> Thanks for the hint re version number. I see this is R_1389. In fact
> > > >> to my embarrassment I see this even appears in my email below!
> > > >>
> > > >> regards,
> > > >> John
> > > >>
> > > >> On 11/17/06, *Charlie Kuharski* <[EMAIL PROTECTED]
> > > >> <mailto: [EMAIL PROTECTED]>> wrote:
> > > >>
> > > >> Your host is not reachable. I'm guessing it HtmlUnit. Try using
> > > >> something without the "...co.nz". You could try and test with HtmlUnit.
> > > >> An ugly was to discover the version is to
> > > >>
> > > >> 1) replace your steps with this only:
> > > >> <verifyTitle
> > > >> description="we should see the login title"
> > > >> text="Login Page" />
> > > >>
> > > >> 2) you should see something like:
> > > >> C:\test\Translink\gtest1.xml:12: Canoo Webtest:
> > R_1393.
> > > >> Test failed.
> > > >> Exception raised:
> > com.canoo.webtest.engine.StepExecutionException : No
> > > >> current response available! Is previous invoke miss
> > > >> itle at C:\test\Translink\gtest1.xml:30: with
> > (description="we should
> > > >> see the login title", taskName="verifyTitle", text
> > > >> anoo.webtest.engine.StepExecutionException: No current
> > response
> > > >> available! Is previous invoke missing?, Step: VerifyTitle
> > > >> nk\gtest1.xml:30: with (description="we should see the login title",
> > > >> taskName="verifyTitle", text="Login Page")
> > > >>
> > > >> Good luck.
> > > >>
> > > >>
> > > >>
> > > >> John and Pip wrote:
> > > >>
> > > >> Hi,
> > > >>
> > > >> I have a test that is failing to follow a 302 error. I've searched the
> > > >> archives and played around trying to enable redirects but nothing
> > > >> seems to work.
> > > >>
> > > >> Below is the stripped-down test (just one invoke) and the output. This
> > > >> is a publicly available page so you can hit
> > > >>
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do
> > > >> from either IE or Firefox so I'm hoping someone can help me figure out
> > > >> how to hit this page from WebTest! Note that I've tried an internal
> > > >> page that is http rather than https and get the same problem so it
> > > >> isn't related to SSL.
> > > >>
> > > >> I am using Java 1.5.0.6 < http://1.5.0.6>, HTMLUnit 1.10 and WebTest
> > > >> R_1393 (I think! How can I verify this?).
> > > >>
> > > >> Regards,
> > > >>
> > > >> John
> > > >>
> > > >> <?xml version="1.0"?>
> > > >>
> > > >> <!DOCTYPE project SYSTEM "WebTest.dtd">
> > > >>
> > > >> <project name="OLH" basedir="." default="main">
> > > >>
> > > >> <property name="webtest.home" location="..\.."/>
> > > >>
> > > >> <import file="${ webtest.home}/lib/taskdef.xml"/>
> > > >>
> > > >> <target name="main">
> > > >>
> > > >> <webtest name="ISIS SFF NZ Search">
> > > >>
> > > >> <steps>
> > > >>
> > > >>
> > <invoke
> > > >> description="ISIS SFF NZ search page" url="
> > > >>
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do"
> > > >> />
> > > >>
> > > >> </steps>
> > > >>
> > > >> </webtest>
> > > >>
> > > >> </target>
> > > >>
> > > >> </project>
> > > >>
> > > >>
> > > >>
> > > >> Here is the output:
> > > >>
> > > >>
> > > >>
> > > >> <?xml version=" 1.0" encoding="UTF-8"?>
> > > >>
> > > >> <summary Implementation-Title="Canoo Webtest"
> > > >> Implementation-Version="R_1389">
> > > >>
> > > >> <testresult endtime="Fri Nov 17 09:25:42 NZDT 2006"
> > > >>
> > > >> location="F:\WebTest\doc\ISIS\tempTest.xml:7:
> > " starttime="Fri
> > > >> Nov 17 09:25:40 NZDT 2006"
> > > >>
> > > >> successful="no" testspecname="ISIS SFF NZ Search">
> > > >>
> > > >> <config>
> > > >>
> > > >> [snipped because I give the full URL below – get same
> > > >> result if set up config properly including port 443]
> > > >>
> > > >> </config>
> > > >>
> > > >> <results>
> > > >>
> > > >> <step>
> > > >>
> > > >> <parameter name="description" value="ISIS SFF NZ
> > > >> search page"/>
> > > >>
> > > >> <parameter name="method" value="GET"/>
> > > >>
> > > >> <parameter name="resultFilename"
> > > >> value="response_1163708742276_invoke.html"/>
> > > >>
> > > >> <parameter name="taskName" value="invoke"/>
> > > >>
> > > >> <parameter name="url"
> > > >> value="
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do
> > > >> <
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do
> > >"/>
> > > >>
> > > >>
> > > >> <result>
> > > >>
> > > >> <failed duration="1469"/>
> > > >>
> > > >> </result>
> > > >>
> > > >> <htmlparser>
> > > >>
> > > >> <error col="1" line="1" url="
> > > >>
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do">Empty
> > > >> document.</error>
> > > >>
> > > >> </htmlparser>
> > > >>
> > > >> </step>
> > > >>
> > > >> <failure
> > > >> message="com.canoo.webtest.engine.StepFailedException:
> > Step[invoke
> > > >> "ISIS SFF NZ search page" (1/1)]: HTTP error 302, at:
> > > >> invoke, Step: InvokePage at
> > F:\WebTest\doc\ISIS\tempTest.xml:9: with
> > > >> (description="ISIS SFF NZ search page",
> > > >> method="GET",
> > > >>
> > resultFilename="response_1163708742276_invoke.html",
> > > >> taskName="invoke",
> > > >>
> >
url="https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do"
> > > >> <
> >
https://flightbookings.airnewzealand.co.nz/isbook_en_NZ/book/initSearchForFlights.do">;)"/>
> > > >>
> > > >> </results>
> > > >>
> > > >> </testresult>
> > > >>
> > > >> </summary>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > >
> > > _______________________________________________
> > > WebTest mailing list
> > > [email protected]
> > > http://lists.canoo.com/mailman/listinfo/webtest
> > >
> >
> >
>
_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest