HTTPUNIT and ajax

JianJunShen
JianJunShen used Ask the Experts™
on
I have a HTTP unit problem.

I have some pages with ext ajax staff. I am using HTTP unit to test memory consumption after page is totally loaded.

As usual, I open WebConversation, then instantiate with webRequest. So I will get response. The snippet codes are as follows:

WebConversation wc = new WebConversation();
WebRequest wr = new PostMethodWebRequest(url);
WebResponse response = wc.getResponse(wr);

Since the pag has ajax staff, I will ask ajax to set a particular text to "load complete". And in response object, I want to do
response.getElementWithID("ID").getText(). If I check out this particular text is changed, so it means ajax is fully loaded.

The problem is how could I let response wait and to get latest updated output from wc.getResponse(wr).

I have done following studpid method, but it fails:

long timeExpired = 30000; //30 seconds
long endTime = timeExpired +System.currentTimeMillis();

WebConversation wc = new WebConversation();
WebRequest wr = new PostMethodWebRequest(url);
WebResponse response = null;

while(System.currentTimeMillis() < endTime){
    response = wc.getResponse(wr);
    ....
    checkTextFromResponse;
    if(textupdated)   {    //ajax loaded
         break;
    }
}

I am afraid that clause "response = wc.getResponse(wr);" will always initiate new request and get Response from server.

Do experts in this forum have any recommendation?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Java Developer
Top Expert 2010
Commented:
determine the requests sent by ajax and have your load app generate them instead of having them generated using ajax

Author

Commented:
Yes, Indeed I only need to directly test ajax. Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial