如何让 webrat / selenium “等待”要加载的页面的CSS?

发布于 2024-08-02 18:43:34 字数 334 浏览 4 评论 0原文

当我在 selenium 模式下使用 webrat 时,visit 正如预期的那样快速返回。没问题。

我试图断言我的样式得到正确应用(通过查看不同元素上的背景图像)。我可以通过 JS 获取此信息,但在我的测试期间样式表似乎尚未加载和/或应用。

我看到您可以“等待”元素出现,但我不知道如何等待所有样式应用。我可以进行总体延迟,但这似乎是内在的不稳定或缓慢,我试图避免这种情况。

显然,因为我知道我正在寻找什么风格,所以我可以等待它们的出现。我会写一个这样的助手,但我想可能已经有一个我还没有见过的更通用的机制了。

有没有一种简单的方法来检测页面是否真的“准备好”?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老街孤人 2024-08-09 18:43:34

这很奇怪。我知道 wait_for_page_to_load 等待整个页面,包括样式表。

如果您仍然认为它没有按预期等待,您可以使用 wait_for_condition 它将执行 JavaScript 并等待直到返回 true。这是一个例子:

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

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"
野稚 2024-08-09 18:43:34

当页面报告加载时,我们遇到了这个问题,即使 Cold Fusion 部分仍在访问数据库以显示信息。后续处理将发生得太快。

查看 Selenium API 中的抽象 Wait 类。您可以编写自己的自定义until()子句,该子句可以测试某些文本是否出现、文本是否消失(在加载完成后浮动消息消失的情况下)或您可以测试的任何其他事件硒曲目。 API 页面甚至有一个很好的示例,可以帮助您进行设置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文