gpt4 book ai didi

ruby-on-rails - 如何告诉 capybara-webkit 不要忽略确认框(或者只是测试它们的内容)

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

所以我有一个场景:

Given I signed in to my business account
And there is one customer named "Samantha Seeley"
When I go to the customers management page
Then "Delete" should show a confirmation dialog saying "Are you sure?"

链接很简单:

<%= link_to 'Delete' customer_path(customer), method: :delete, confirm: 'Are you sure?' do %>

所以当我在 Chrome 中点击链接时,这段代码确实会出现一个确认对话框,但是使用这样的页面渲染:

Then /^"(.*?)" should show a confirmation dialog saying "(.*?)"$/ do |arg1, arg2|
click_on arg1
page.driver.render "tmp/screenshot.jpg"
end

我相信我可以从屏幕截图中确认 javascript 似乎没有被评估(没有显示确认对话框)。不过这个假设可能是错误的,我不确定。

感谢您的帮助。

最佳答案

GitHub 上也提出了类似的问题:https://github.com/thoughtbot/capybara-webkit/issues/84

结论是使用类似这样的东西,这是由Jesse Cooke建议的和 Ken Collins :

def handle_js_confirm(accept=true)
page.evaluate_script "window.original_confirm_function = window.confirm"
page.evaluate_script "window.confirm = function(msg) { return #{!!accept}; }"
yield
ensure
page.evaluate_script "window.confirm = window.original_confirm_function"
end

这不会帮助您测试确认对话框的内容(尽管它可以很容易地扩展到这样做),但它可以让您测试当用户单击“确定”或“取消”时会发生什么。

在这种特定情况下,您需要一个确认对话框,因为您使用的是生成确认对话框的 Rails 助手。值得考虑这是否需要在您自己的应用程序中进行测试;已经有 tests in Rails to cover it .

关于ruby-on-rails - 如何告诉 capybara-webkit 不要忽略确认框(或者只是测试它们的内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10765045/

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