【发布时间】:2017-07-22 06:59:56
【问题描述】:
使用 RSpec 和 Capybara,我正在尝试在网页上测试删除功能。
视图中按钮的代码为:
<%= link_to "×".html_safe, material, method: :delete, data: { confirm: 'Are you sure?' }
我想为它编写一个 RSpec 测试,以便能够单击确认框中的 OK 按钮。到目前为止,我得到了以下内容
feature 'Delete materials' do
before do
@user = FactoryGirl.create(:user)
@group = FactoryGirl.create(:group)
@user.groups << @group
@material_1 = FactoryGirl.create(:material, user: @user, group: @group)
login_as(@user, scope: :user)
end
scenario "in the index should give a confirmation box", js: true do
visit materials_path
expect(Material.count).to eq(1)
accept_confirm do
find('a[data-method="delete"]').click
click_link "OK"
end
expect(Material.count).to eq(0)
end
end
我不断收到的错误是:
Selenium::WebDriver::Error::UnhandledAlertError:
unexpected alert open: {Alert text : Are you sure?}
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.27.440175(9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.8.0-39-generic x86_64)
我用谷歌搜索并四处搜索,一个解决方案是 chromedriver 可能不是最新的。据我所知,我正在使用最新的驱动程序。 另一种解决方案是使用 accept_confirm 块,但这还没有帮助。
为了记录,我正在使用 Selenium-webdriver + chromedriver-helper gem 来测试 Google Chrome。
【问题讨论】:
标签: ruby-on-rails ruby selenium rspec