Search code examples
ruby-on-railsunit-testingtddseleniumwebrat

How do I get webrat / selenium to "wait for" the CSS of the page to load?


When I use webrat in selenium mode, visit returns quickly, as expected. No prob.

I am trying to assert that my styles get applied correctly (by looking at background images on different elements). I am able to get this information via JS, but it seems like the stylesheets have not loaded and/or gotten applied during my test.

I see that you can "wait" for elements to appear, but I don't see how I can wait for all the styles to get applied. I can put in a general delay, but that seems like built-in flakiness or slowness, which I am trying to avoid.

Obviously since I know what styles I'm looking for I can wait for them to appear. I'll write such a helper, but I was thinking there might be a more general mechanism already in place that I haven't seen.

Is there an easy way detect that the page is really really "ready"?


Solution

  • That's strange. I know that wait_for_page_to_load waits for the whole page, stylesheets included.

    If you still think it's not waiting as it should, you can use wait_for_condition which will execute a javascript and wait until is returns true. Here's an example:

        @selenium.wait_for_condition "selenium.browserbot.getCurrentWindow().document.body.style.backgroundColor == 'white'", "60000"