我正在尝试运行这些测试:
describe "Selecting Assets Tour" do
context "when logged in as client" do
it "should run through all steps" do
visit tours_path
click_link("Selecting Assets")
binding.pry
expect(page).to have_content 'Selecting an Asset'
end
end
end
但它失败了,但是当我插入 binding.pry 并手动输入时
click_link("选择 Assets ")
然后退出 binding.pry
然后测试通过,但除此之外..它不会自己点击链接..
我尝试了其他变体,例如:find('#start-assets-tour').click
和 click_on
但结果是一样的。在这一点上真的不确定为什么当我正常运行测试时它不会点击链接,任何帮助将不胜感激
使用 rails 4
如果我没有提供足够的信息,请告诉我。
编辑:我的观点是这样的:
<table class="table table-hover table-tour">
<thead>
<tr>
<th class="tour-header">Site Tours</th>
</tr>
</thead>
<tbody>
<% if current_user.client_limited? || current_user.client_full? %>
<tr>
<td>
<%= link_to "Changing Focus", "/", :id => "start-focus-tour" %>
</td>
</tr>
<% end %>
<tr>
<td>
<%= link_to "Selecting Assets", "/", :id => "start-assets-tour" %>
</td>
</tr>
<tr>
<td>
<%= link_to "Viewing Asset Details", "/", :id => "start-view-asset-tour" %>
</td>
</tr>
<tr>
<td>
<%= link_to "Lightbox", "/tours", :id => "start-lightbox-tour" %>
</td>
</tr>
<tr>
<td>
<%= link_to "Changing Your Viewing Options", "/", :id => "start-navigation-display-tour" %>
</td>
</tr>
</tbody>
id #start-assets-tour 会自动触发 Bootstrap 的开始,即没有发生的点击。
最佳答案
我以前遇到过你的这种问题。在我要求 Capybara 单击我想要的元素之前,我碰巧通过最大化浏览器窗口来修复我的问题。只需像这样添加 page.driver.browser.manage.window.maximize
describe "Selecting Assets Tour" do
context "when logged in as client" do
it "should run through all steps" do
visit tours_path
page.driver.browser.manage.window.maximize
click_link("Selecting Assets")
expect(page).to have_content 'Selecting an Asset'
end
end
end
关于ruby-on-rails - capybara 不点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22996511/