Ruby on rails 水豚罐头';如果存在JS,则找不到元素

Ruby on rails 水豚罐头';如果存在JS,则找不到元素,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,我想测试用户在注册后是否可以跳过shipping_地址表单 因此,我在表单中有一个按钮,带有一些Javasrcipt,可以重定向到用户之前所在的页面 如果在场景中删除:js,则Capybara能够找到#subscription,但测试因路径(无js无重定向)而失败。 如果我把:js放进去,它就找不到#订阅 你能给我一些提示吗 配送地址/new.html.erb <%= link_to 'Remplir plus tard', 'javascript:history.go(-1);', cl

我想测试用户在注册后是否可以跳过shipping_地址表单

因此,我在表单中有一个按钮,带有一些Javasrcipt,可以重定向到用户之前所在的页面

如果在场景中删除
:js
,则Capybara能够找到
#subscription
,但测试因路径(无js无重定向)而失败。 如果我把
:js
放进去,它就找不到
#订阅
你能给我一些提示吗

配送地址/new.html.erb

<%= link_to 'Remplir plus tard', 'javascript:history.go(-1);', class: "btn btn-secondary btn-block" %>
这是我导航栏中的下拉列表

<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>   

编辑更多我的导航栏

  • #只需删除链接即可清除代码

我直接跳到注册页面,因为下拉菜单中的按钮对于水豚是不可见的:

scenario "skipping the address form for now", :js do 
    visit   new_user_registration_path
    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指定一个ID(我认为…有点取决于CSS框架)


我直接跳到注册页面,因为下拉菜单中的按钮对于水豚是不可见的:

scenario "skipping the address form for now", :js do 
    visit   new_user_registration_path
    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指定一个ID(我认为…有点取决于CSS框架)


ID=“subscription”的项目在哪里?它在链接到
的链接中哦,我看到了。。。您使用的是下拉菜单,因此第一个操作应该是单击下拉菜单按钮。但是在这种情况下,我会直接转到
new\u user\u registration\u path
,这是因为在JS中,按钮是隐藏的,所以水豚找不到具有该ID的可见项目。ID=“subscription”的项目在哪里?它在指向
的链接中哦,我看到了。。。您使用的是下拉菜单,因此第一个操作应该是单击下拉菜单按钮。但是在这种情况下,我会直接转到
new\u user\u registration\u path
,因为在JS中,按钮是隐藏的,所以水豚找不到具有该ID的可见项。是的,这是我首先要做的,我想测试“长途跋涉”。顺便说一句,这使工作,不是预期的,但我会这样做,你说的“工作不是预期的”是什么意思?你也可以给父母一个ID,如果你想查看的话,可以先点击它。让我重新解释一下答案。谢谢,但像这样,它找不到通常触发下拉列表的
#下拉列表
?从你的密码我看不出来。。。。是悬停、单击还是。。。?无论如何,你应该告诉水豚采取与用户在启用JS时完全相同的操作,因为它会尽可能地表现出与实际用户一样的行为。@johan你没有回答这个问题-悬停或单击是否会触发下拉菜单?是的,这是我首先做的,我想测试“漫长的道路”。顺便说一句,这使工作,不是预期的,但我会这样做,你说的“工作不是预期的”是什么意思?你也可以给父母一个ID,如果你想查看的话,可以先点击它。让我重新解释一下答案。谢谢,但像这样,它找不到通常触发下拉列表的
#下拉列表
?从你的密码我看不出来。。。。是悬停、单击还是。。。?无论如何,您应该告诉水豚采取与启用JS时用户所采取的完全相同的操作,因为它会尽可能多地表现为实际用户的行为。@johan您没有回答问题-悬停或单击是否会触发下拉?
scenario "skipping the address form for now", :js do 
    visit   new_user_registration_path
    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 id="dropdown" 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>  
scenario "skipping the address form for now", :js do 
    visit  root_path 
    find('#dropdown').click
    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