geektron has asked for the wisdom of the Perl Monks concerning the following question:

I'm about halfway through my first (painful) day of writing tests for the web application mentioned in starting to write automated tests, and i've run into an impasse ... because the current incarnation is *very* dependent on cookies.

I've read and re-read the perldoc for WWW::Mechanize and Test::WWW::Mechanize, and it *appears* that I'm creating a valid cookie jar, but there are no cookies to be found.

I've looked through the source code to be sure, and not *all* of the cookies are set via Javascript, so my assumption is that I'm doing something wrong with the cookie jar ...

my $robot = Test::WWW::Mechanize->new( cookie_jar => {} ); $robot->get( $frontPage ); warn Dumper $robot->{cookie_jar};
Now, if the frontpage *does* in fact set a cookie, I should see something in the Dumper output that indicates an accepted cookie, correct?

Replies are listed 'Best First'.
Re: WWW::Mechanize and cookies
by Errto (Vicar) on Dec 30, 2004 at 02:02 UTC
      well, both ways actually work.

      one is direct access to the hashref ( $robot->{cookie_jar} ) and the other is the "right" way to do it ... through an accessor method.

      it turns out that all cookies for the action-set i was following *are* set by javascript, hence, no cookies for the Test::WWW::Mech based agent.

Re: WWW::Mechanize and cookies
by Solo (Deacon) on Dec 30, 2004 at 14:36 UTC
    I'm creating a valid cookie jar, but there are no cookies to be found.

    When this happens, I enable autosave and ignore_discard.

    HTTP::Cookies->new( file => "lwpcookies.txt", autosave => 1, ignore_discard => 1, );

    --Solo

    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.