Menu

Multiple requests.

Eddie
2004-10-05
2013-04-26
  • Eddie

    Eddie - 2004-10-05

    Hi,

    I have been working with HttpUnit to test my web application for the past few weeks. The first page of my application has a javascript function that runs on "onLoad" of the form, which opens up another window. Meaning its a new request. Unless I am making some kind of silly mistake it seems to me like, the second request (for the pop-up) overwrites the first one. The problem is, I am looking for something in the response and its not what I expected because of the pop-up.

    Is this the expected behaviour? Let me know if I need to clarify further.

    BTW, I like the new 1.6! I used to get a lot of Javascript "undefined value" errors which is fixed now!

    Thanks!

     
    • David Demmer

      David Demmer - 2004-10-05

      You can use getOpenWindows from the WebConversation object. This will return an array of WebWindows where you will be able to send requests to both windows.

      David

       
    • Eddie

      Eddie - 2004-10-05

      Actually I am not trying to send a request to two windows. I am trying to get the response from the first window. Here is what happens:
      1. response = conversation.getResponse("http://localhost:8080/ab.jsp");

      2. As part of the response, the page ab.jsp requests another page using "openWindow("http://localhost/dc.jsp")";

      3. The response that I get is the response for dc.jsp. Whereas what I want to get to is the response for ab.jsp (the very first page I requested).

      Going by your solution, I tried to do a conversation.getOpenWindows()....not sure if I used this correctly. Then using the resulting WebWindows array I tried to get the opener using the getOpener() method. But that didn't work coz I ended up getting just one Window in the WebWindow array!

      Could be something wrong with my implementation. I'll work on this some more.

      Eddie.

       
    • David Demmer

      David Demmer - 2004-10-05

      Seeme like you should see both windows but try from a request call:

      WebConversation wc = new WebConversation();
      WebRequest wr = new GetMethodWebRequest(http://localhost:8080/ab.jsp);
      wc.getResponse(wr);
      WebWindow[] windows = wc.getOpenWindows();
      // should have an array length of 2
      WebResponse resp = WebWindow[0].getCurrentPage();

      Hope this helps...

       
    • Eddie

      Eddie - 2004-10-06

      That didn't work either. Still array lenght of 1. I need to start fresh with a new simple page. Take all my code out of the equation and see what if I can get getOpenWindows() to return an array length of more than one! Also I read my previous post again, doing that getOpener() thing is not required! Esp if you have two windows and direct access to the respnse of either one of them. So I wasnt thinking then! :-)

      BTW I get my code to work by disabling Javascript (so that the onLoad script does not run) before I get to the page and then enabling it after getting the response. Not the best way to do it but it works.

      Thanks so much for your response! And I'll  update my post after my test.

      Thanks,
      Eddie.

       
    • Sir Runcible Spoon

      Have you tried registering a WebWindowListener or WebClientListener  with your WebConversation?  You should be able to use this to record all responses and windows.

       
    • Eddie

      Eddie - 2004-10-06

      So here's the latest.

      I created a simple HTML page that just opened a window and I got two elements in the getOpenWindows() array. So something in my original JSP I was testing is causing the getOpenWindows() to return just one window. I'll try using the WebWindowListener with the conversation.

      Thanks.

       
    • Eddie

      Eddie - 2004-10-08

      Ok...if anybody is interested. I have figured out what happens.

      This is what happens.:

      1. Create a page http://localhost:8080/do.jsp that does a redirect to hello.jsp.
      <%response.sendRedirect("http://localhost:8080/hello.jsp");%>

      2. Create hello.jsp, which in turn calls do.jsp using a javascript:window.open('/do.jsp')

      Seems like in this case the conversation.getOpenWindows() returns only one window. The one that is spawned by hello.jsp (in the second step).

      I stepped through the HttpUnit source code but I wan't able to see why this is happening. Could be because of the redirect involved? Not sure if my theory is totally correct but that's the behaviour I see in the WebWindows.getResponse() method.

      Let me know what you guys think.
      Eddie.

       
    • Max Wilson

      Max Wilson - 2004-10-08

      > Seems like in this case the conversation.getOpenWindows()
      > returns only one window. The one that is spawned by
      > hello.jsp (in the second step).

      I've seen similar behavior when there's a button in a frame that opens a separate window to display its results.
      WebConversation.getOpenWindows() should return two windows, but only returns one, the original one. (However, it strips out all the other frames from the window IIRC.) I've been following your problem but haven't responded because I don't have anything to say yet; but it's on my agenda at work of things to look into and solve.

      Max Wilson
      OIT - Brigham Young University

       

Log in to post a comment.

Monday.com Logo