JianJunShen
asked on
HTTPUNIT and ajax
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").getT ext(). 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.currentTimeMi llis() < 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?
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(
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.currentTimeMi
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER