在 Capybara/Selenium 测试中触发悬停意图

发布于 2024-12-22 20:50:01 字数 794 浏览 2 评论 0原文

有谁知道如何通过水豚触发hoverIntent事件?

在我的 Rails 应用程序的主视图中,当用户将鼠标悬停在表格单元格上时,编辑按钮会出现在该单元格中。

我最近添加了 jQuery hoverIntent 插件来延迟这些按钮的出现,这样,当用户在页面上快速移动鼠标时,UI 就不会看起来像一个繁忙的总机。

不幸的是,hoverIntent 的添加破坏了几个 Cucumber-Capybara-Selenium 测试。测试一直在使按钮出现,步骤如下(简化):

And /^I hover on the table cell with ID "(.*)"$/ do |cell_id|
  selector = "td#" + cell_id
  js = %Q{ (function() { jQuery("#{ selector }").mouseover(); })() }
  page.evaluate_script js
end

这对于常规鼠标悬停事件效果很好,但它不会触发悬停意图。

一种(有点hackish)的解决方案是创建命名函数来传递给hoverIntent以实现鼠标悬停和鼠标悬停行为(而不是像我现在所做的那样的匿名内联函数)。然后,Capybara 步骤可以通过名称调用 mouseover 函数,并获得相同的结果。

不过,这会回避对hoverIntent功能的测试,因此它不是最佳的。

预先感谢您的任何建议。

Has anyone figured out how to trigger a hoverIntent event via Capybara?

In my Rails app's main view, edit buttons appear in a table cell when the user hovers the mouse over that cell.

I recently added the jQuery hoverIntent plug-in to delay the appearance of these buttons, so that the UI doesn't look like a busy switchboard when the user moves the mouse quickly across the page.

The addition of hoverIntent broke several Cucumber-Capybara-Selenium tests, unfortunately. The tests had been making the buttons appear with a step like this (simplified):

And /^I hover on the table cell with ID "(.*)"$/ do |cell_id|
  selector = "td#" + cell_id
  js = %Q{ (function() { jQuery("#{ selector }").mouseover(); })() }
  page.evaluate_script js
end

This worked well for the regular mouseover event, but it doesn't trigger hoverIntent.

One (kind-of-hackish) solution would be to create named functions to pass to hoverIntent for the mouseover and mouseout behaviors (instead of anonymous, inline functions as I'm doing now). The Capybara step could then invoke the mouseover function by name, and get the same result.

This would side-step the testing of the hoverIntent functionality, though, so it isn't optimal.

Thanks in advance for any suggestions.

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

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

发布评论

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

评论(1

青衫负雪 2024-12-29 20:50:01

对于要注册的hoverIntent,我相信浏览器需要在hoverIntent延迟期间处于睡眠状态。

For the hoverIntent to register I believe the browser needs to sleep for the duration of your hoverIntent delay.

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