views:

901

answers:

2

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"?

+2  A: 

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"
Santi
Thanks. That will probably do it. We had all sorts of problems actually extracting the current background-image of an element. We actually couldn't simulate a "hover" so that the CSS :hover selector would work, and ended up using JS to change styles-- in order to detect the change reliably within selenium.
ndp
A: 

We ran into this when a page was reporting loaded even though a Cold Fusion portion was still accessing a database for info to display. Subsequent processing would then occur too soon.

Look at the abstract Wait class in the Selenium API. You can write your own custom until() clause that could test for certain text to appear, text to go away (in the case of a floating message that goes away when the loading is done) or any other event that you can test for in the Selenium repertoire. The API page even has a nice example that helps a lot getting it set up.