gpt4 book ai didi

jquery - 如何使用 Capybara 模拟点击 jQuery-UI 模式对话框按钮?

转载 作者:行者123 更新时间:2023-12-01 04:18:15 24 4
gpt4 key购买 nike

在 Web 应用程序中,我使用 jQueryUI 模式对话框来确认操作:

function erase() {
$("#dialog").text("Are you sure want to delete this record?")
.attr("title", "Delete...")
.dialog({
modal: true,
buttons: {
Delete: function() {
$.ajax({
...snip...
success: function() {
self.location = "."; // returns to the welcome page
}
});
},
...snip...
}
});
}

该代码运行得很好,但我无法使用 Capybara 成功测试它:

...snip...
Capybara.default_driver = :webkit
...snip...

def in_dialog()
f = find('.ui-dialog')
end

feature 'Delete a record' do
...snip...
scenario 'for any record' do
click_on 'Delete...'
page.should have_content 'Are you sure want to delete this record?'
in_dialog.click_button 'Delete'
page.should have_content 'Welcome'
...snip...
end
end

Capybara 找到了按钮,但一切都像回调从未被触发过一样。

我尝试了不同的解决方法(其中一些是我在 stackoverflow 上找到的):

  • sleep ,
  • “等待ajax”,
  • page.native.send_keys(:return) 而不是 click_button“删除”,
  • find('button', :text => 'Delete').click 而不是 click_button 'Delete',
  • Selenium 驱动程序而不是 webkit 驱动程序。

没有一个有效。还有其他想法吗?

最佳答案

您发布了code that you use to interact with the server在评论中。

我在浏览器中手动执行了这些步骤,但单击“Supprimer”按钮返回 409 错误,并且没有任何其他 react 。这就是为什么当您单击此按钮时测试中没有任何反应。

关于jquery - 如何使用 Capybara 模拟点击 jQuery-UI 模式对话框按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12998075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com