4

I check the property .readyState of BrowserTestObject using RFT (Rational Functional Tester).

Sometimes before the next step in my test script I need to be sure that the page is 'ready' and all objects are loaded.

Does the .readyState == 4 mean that all objects within the browser are loaded and ready? Could any ajax call in background be still "working" or it must finish before the browser returns .readyState=4? What about a flex application?

Is that behavior browser independent or not really? I am after IE 8 (and firefox 3.6.x)

theUtherSide
  • 3,338
  • 4
  • 36
  • 35
Radek
  • 13,813
  • 52
  • 161
  • 255

2 Answers2

3

quick answer is YES if browser implementation is correct.

See here: http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#current-document-readiness

Ray Cheng
  • 12,230
  • 14
  • 74
  • 137
  • 2
    @Radek, according to http://msdn.microsoft.com/en-us/library/ms535874(v=vs.85).aspx, IE8 has a buggy implementation. FF 3.6 supports it because the bug is fixed at https://bugzilla.mozilla.org/show_bug.cgi?id=347174. – Ray Cheng Feb 29 '12 at 00:27
  • Even in IE9, the bug is not totally gone away: http://msdn.microsoft.com/en-us/library/ms536957(v=vs.85).aspx. I suggest to tackle your requirements in a different way. Maybe you don't have to know "all are objects loaded"? Maybe a different design on the Ajax calls will help. – Ray Cheng Feb 29 '12 at 00:33
2

I would say no. If I understood discussion here, readyState used thus only refers to the test javascript, nothing else. To wait that the document itself is loaded, you need to hook to document.readyState and wait for it to become "complete". In that case, once the HTML parsing is complete, the document.readyState would be "complete" once and for all, and will not be affected by any XMLHttpRequest whatsoever. Flash plugins could or could not have started; most certainly there would be lots of javascript running; for example $(function() {}) construct in jquery often means that javascript code could start executing only after the browser hits the "complete" state.

To test if any asynchronous requests are going on, I suggest hooking the readyState event of all XMLHttpRequests somehow and make it update a global variable.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109