When we ask the browser to visit a URL, it calls us back when it's finished, but as web developers know, it's tricky to know exactly when a page load can be considered fully finished
A browser object has its own event loop that handles asynchronous events, such as loading resources, events, timeouts, and intervals. After a page is loaded and parsed, all the dependencies are loaded and parsed asynchronously—just like in real browsers—using this event loop.
Some of these dependencies may contain JavaScript files that will be loaded, parsed, and evaluated. Furthermore, the HTML document may contain some additional inline scripts that will be executed. If any of these scripts have a callback waiting for the document to be ready, these callbacks will be executed before your browser.visit()
callback fires your test callback. This means that if, for instance, you have jQuery code that gets fired when the document is ready, it will run before your callback. The same can...