问题描述
|
我有一种情况,我想在页面上为表中的第二项选择\'Delete \'链接。我一直在查看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
解决方法
为了生成正确的删除链接,rails使用javascript。因此,您会收到一个DELETE请求,而不是普通链接将产生的GET请求。由于webrat无法处理javascript,因此无法正常工作。查看Capybara,以替代webrat或带硒的webrat。