我有一个场景,我想在页面上为表格中的第二个项目选择“删除”链接。我一直在关注click_link_within或使用内部但它无法正常工作。
Scenario: User deletes a staff member from the listing
Given a staff exists with name: "Michael"
And a staff exists with name: "Joe"
And I am on the listing staff index page
When I follow "Delete" for row containing "Joe"
Then I should be on the listing staff index page
And I should not see "Joe"
And I should see "Michael"
以下是我尝试使用的步骤:
When /^I follow "([^"]*)" for row containing "([^"]*)"$/ do |button, text|
click_link_within "//*[.//td[contains(.,#{text})]]", button
end
以下是haml中的列表代码:
%h1 Staff Listing
%table
%th Username
%th Surname
%th First Name
- @staff.each do |staff|
%tr
%td= staff.username
%td= staff.surname
%td= staff.firstname
%td= link_to "Edit", edit_staff_path(staff)
%td= link_to "Delete", staff, :method => :delete
答案 0 :(得分:1)
为了生成正确的删除链接,rails使用javascript。所以你得到一个DELETE请求而不是正常链接会产生的GET。由于webrat不能处理javascript,因此无法使用。查看Capybara作为webrat或webrat with selenium的替代品。