【发布时间】:2023-03-09 04:24:01
【问题描述】:
我想测试用户在注册后是否可以跳过 shipping_address 表单。
所以我在表单中有这个按钮,一些 Javasrcipt 重定向到用户之前的页面。
如果我在 Capybara 能够找到 #subscription 的场景中删除 :js 但由于路径(没有 js 没有重定向)而测试失败。
如果我把:js它找不到#subscription
你能给我一些提示吗?
shipping_addresses/new.html.erb
<%= link_to 'Remplir plus tard', 'javascript:history.go(-1);', class: "btn btn-secondary btn-block" %>
这是测试
scenario "skipping the address form for now", :js do
visit root_path
find('#subscription').click
choose "Monsieur"
fill_in "user[first_name]", with: "Benoit"
fill_in "user[last_name]", with: "Durant"
fill_in "user[birth_date]", with: "08/05/1981"
fill_in "user[email]", with: "benoit@example.com"
fill_in "user[email_confirmation]", with: "benoit@example.com"
fill_in "user[password]", with: "password"
fill_in "user[password_confirmation]", with: "password"
click_on "Valider mon inscription"
expect(page).to have_content("REMPLISSEZ VOTRE ADRESSE DE LIVRAISON")
click_on "Remplir plus tard"
expect(current_path).to eq root_path
end
这是我导航栏中的下拉菜单
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<%= link_to "Connection", new_user_session_path, class: "dropdown-item" %>
<%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %>
</div>
编辑更多我的导航栏
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<% if current_user %>
<%= current_user.first_name %>
<% else %>
Mon Compte
<% end %>
</a>
<% if current_user %>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
#Just removed the links to clear the code
</div>
<% else %>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<%= link_to "Connection", new_user_session_path, class: "dropdown-item" %>
<%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %>
</div>
<% end %>
</li>
</ul>
</div>
【问题讨论】:
-
ID="subscription" 的项目在哪里?
-
在这个link_to
<%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %> -
哦,我明白了...您正在使用下拉菜单,因此第一个操作应该是单击下拉菜单按钮。但在这种情况下,我直接去
new_user_registration_path -
因为用JS,按钮是隐藏的,所以Capybara找不到那个ID的可见项。
标签: ruby-on-rails rspec capybara