Testbrowser Redirects with Fragments

by Ross Patterson last modified 2008-11-23T04:04:45+02:00
Using zope.testbrowser when a redirect URL includes a fragment

I was trying to add functional test coverage for commenting on content when I kept getting 404 NotFound errors.  I tried it in a real browser and everything worked just fine.  After a little googling, I found an answer in a post on the zope3-dev mailing list:

Note that the fragment identifier is *never* going to be passed to the server by a "real" browser: instead, the browser strips of the fragment part, submits the remainder of the URL to the server, and then does a search for the appropriate '<a name="bar">' element *on the client side*.

I'm not sure how this is pertinent to the problem you have found, but Zope will never traverse '#bar' or '%23bar' in the real world.

It seems like maybe testbrowser should not send fragments to the underlying mechanize browser.  But failing that, for now I just add a note to my tests about why we expect a 404, NotFound error in our tests that we won't see in a real browser.

Hope this saves someone else the search time.  :)