Loading ...
Sorry, an error occurred while loading the content.

RE: [junit] Httpunit test - how to retrieve cookie value

Expand Messages
  • Cecilia Crasto
    Ji Jenny, Your code test looks perfect... so am not sure why it should not work, unless ofcourse the cookie you are seraching does not exist in the resp obj, I
    Message 1 of 5 , Nov 30, 2004
    View Source
    • 0 Attachment
      Ji Jenny,

      Your code test looks perfect... so am not sure why it should not work,
      unless ofcourse the cookie you are seraching does not exist in the resp obj,
      I am just a novice to JUNit, but I think this should work.... Atleast it
      will enable you to debug and check if the cookie you want is present in the
      response.

      WebConversation wc = new WebConversation();
      WebRequest req = new GetMethodWebRequest( "http://<the URL>" );
      WebResponse resp = wc.getResponse( req );
      String s2[] = resp.getNewCookieNames();
      String cookval;
      if (s2.length >= 1);
      {
      for(int i = 0; i < s2.length; i++)
      {
      cookval = resp.getNewCookieValue(s2[i]);
      }
      }

      -Cecilia

      From: "jenny_jingwang" <jenny_jingwang@...>
      Reply-To: junit@yahoogroups.com
      To: junit@yahoogroups.com
      Subject: [junit] Httpunit test - how to retrieve cookie value
      Date: Mon, 29 Nov 2004 21:57:18 -0000
      MIME-Version: 1.0
      X-Originating-IP: 199.181.134.220
      X-Sender: jenny_jingwang@...
      Received: from n2a.bulk.scd.yahoo.com ([66.94.237.36]) by
      mc12-f21.hotmail.com with Microsoft SMTPSVC(5.0.2195.6824); Mon, 29 Nov 2004
      16:15:31 -0800
      Received: from [66.218.66.58] by n2.bulk.scd.yahoo.com with NNFMP; 30 Nov
      2004 00:14:24 -0000
      Received: from [66.218.66.159] by mailer7.bulk.scd.yahoo.com with NNFMP; 30
      Nov 2004 00:14:24 -0000
      Received: (qmail 97798 invoked from network); 30 Nov 2004 00:01:48 -0000
      Received: from unknown (66.218.66.216) by m19.grp.scd.yahoo.com with QMQP;
      30 Nov 2004 00:01:48 -0000
      Received: from unknown (HELO n14a.bulk.scd.yahoo.com) (66.94.237.28) by
      mta1.grp.scd.yahoo.com with SMTP; 30 Nov 2004 00:01:45 -0000
      Received: from [66.218.69.3] by n14.bulk.scd.yahoo.com with NNFMP; 30 Nov
      2004 00:00:49 -0000
      Received: from [66.218.67.130] by mailer3.bulk.scd.yahoo.com with NNFMP; 30
      Nov 2004 00:00:49 -0000
      Received: (qmail 16680 invoked from network); 29 Nov 2004 21:57:42 -0000
      Received: from unknown (66.218.66.166) by m15.grp.scd.yahoo.com with QMQP;
      29 Nov 2004 21:57:42 -0000
      Received: from unknown (HELO n7a.bulk.scd.yahoo.com) (66.94.237.41) by
      mta5.grp.scd.yahoo.com with SMTP; 29 Nov 2004 21:57:42 -0000
      Received: from [66.218.69.6] by n7.bulk.scd.yahoo.com with NNFMP; 29 Nov
      2004 21:57:21 -0000
      Received: from [66.218.67.157] by mailer6.bulk.scd.yahoo.com with NNFMP; 29
      Nov 2004 21:57:21 -0000
      X-Message-Info: JGTYoYF78jFA0E3zouPFgY+z7TQzOpfR
      X-Yahoo-Newman-Property: groups-email
      X-Apparently-To: junit@yahoogroups.com
      User-Agent: eGroups-EW/0.82
      X-Mailer: Yahoo Groups Message Poster
      X-eGroups-Remote-IP: 66.94.237.41
      X-Yahoo-Profile: jenny_jingwang
      X-eGroups-Approved-By: nails762 <jbrains@...> via web; 30 Nov 2004
      00:00:40 -0000
      X-eGroups-Remote-IP: 66.94.237.28
      Mailing-List: list junit@yahoogroups.com; contact
      junit-owner@yahoogroups.com
      Delivered-To: mailing list junit@yahoogroups.com
      Precedence: bulk
      List-Unsubscribe: <mailto:junit-unsubscribe@yahoogroups.com>
      Return-Path:
      sentto-2423328-12414-1101773653-octivianac=hotmail.com@...
      X-OriginalArrivalTime: 30 Nov 2004 00:15:31.0116 (UTC)
      FILETIME=[B3E786C0:01C4D671]



      I hope someone with Httpunit experience can point me to the right
      direction.

      One test I'm trying to write with Httpunit is to retrieve the cookie
      value after hitting a webpage.
      Here is part of my Java code:

      WebConversation wc = new WebConversation();
      WebRequest req = new GetMethodWebRequest( "http://<the URL>" );
      WebResponse resp = wc.getResponse( req );

      I used resp.getNewCookieValue("GUID") to try to retrieve the GUID
      cookie value. However, getNewCookieValue returns nothing.

      Am I missing anything or using the wrong function? The website I'm
      hitting does set a GUID cookie value in xx.com domain. What is the
      right way to retrieve the cookie?

      Thanks so much in advance,
      Jenny
    • jenny_jingwang
      Thanks so much! It worked perfectly! The documentation and examples are not easy to follow on their web site. Do you recommend anywhere else I can get more
      Message 2 of 5 , Nov 30, 2004
      View Source
      • 0 Attachment
        Thanks so much!
        It worked perfectly!
        The documentation and examples are not easy to follow on their web
        site.
        Do you recommend anywhere else I can get more examples or docs?

        Thanks agin! You made my day!
        --- In junit@yahoogroups.com, Russell Gold <russgold@g...> wrote:
        > On Mon, 29 Nov 2004 21:57:18 -0000, jenny_jingwang
        > <jenny_jingwang@y...> wrote:
        > >
        > >
        > > I hope someone with Httpunit experience can point me to the right
        > > direction.
        > >
        > > One test I'm trying to write with Httpunit is to retrieve the
        cookie
        > > value after hitting a webpage.
        > > Here is part of my Java code:
        > >
        > > WebConversation wc = new WebConversation();
        > > WebRequest req = new GetMethodWebRequest( "http://<the
        URL>" );
        > > WebResponse resp = wc.getResponse( req );
        > >
        > > I used resp.getNewCookieValue("GUID") to try to retrieve the GUID
        > > cookie value. However, getNewCookieValue returns nothing.
        > >
        > > Am I missing anything or using the wrong function? The website I'm
        > > hitting does set a GUID cookie value in xx.com domain. What is the
        > > right way to retrieve the cookie?
        >
        > wc.getCookieValue( "GUID" )
        >
        > if everything goes properly, the cookie should be recorded in the
        web
        > conversation. If it is not showing up, enable header logging to see
        > what is actually being sent from the server.
      • jenny_jingwang
        Could I ask one more question? If I use jwebunit test instead of HttpUnit, I guess I need to call the assertCookiePresent( GUID ) function in WebTestCase
        Message 3 of 5 , Nov 30, 2004
        View Source
        • 0 Attachment
          Could I ask one more question?
          If I use jwebunit test instead of HttpUnit,
          I guess I need to call the assertCookiePresent("GUID") function in
          WebTestCase class, but that doesn't return true even when the cookie
          is present.
          Is this the correct call in jwebunit?
          Is there anyway I can get the cookie value in jwebunit as I can from
          Httpunit using wc.getCookieValue("GUID")?

          Thanks a lot again!

          --- In junit@yahoogroups.com, "jenny_jingwang" <jenny_jingwang@y...>
          wrote:
          >
          >
          > I hope someone with Httpunit experience can point me to the right
          > direction.
          >
          > One test I'm trying to write with Httpunit is to retrieve the
          cookie
          > value after hitting a webpage.
          > Here is part of my Java code:
          >
          > WebConversation wc = new WebConversation();
          > WebRequest req = new GetMethodWebRequest( "http://<the URL>" );
          > WebResponse resp = wc.getResponse( req );
          >
          > I used resp.getNewCookieValue("GUID") to try to retrieve the GUID
          > cookie value. However, getNewCookieValue returns nothing.
          >
          > Am I missing anything or using the wrong function? The website I'm
          > hitting does set a GUID cookie value in xx.com domain. What is the
          > right way to retrieve the cookie?
          >
          > Thanks so much in advance,
          > Jenny
        Your message has been successfully submitted and would be delivered to recipients shortly.