黄瓜webrat点击第二个删除链接
问题描述:
我有一个方案,我想选择页面上的'删除'链接表中的第二个项目。我一直在看click_link_within或使用内,但它不能正常工作。黄瓜webrat点击第二个删除链接
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
答
为了生成正确的删除链接轨使用JavaScript。所以你得到一个DELETE请求,而不是一个正常链接产生的GET。由于webrat不处理JavaScript,所以这是行不通的。检查水豚作为Webrat或Webrat与硒的替代品。
我已经安装了水豚,我可以点击删除链接,但不是第二个链接。 – map7 2011-04-17 02:49:42
水豚安装很好,但你必须确保你使用它而不是在黄瓜webrat(请参阅:https://github.com/aslakhellesoy/cucumber-rails后安装一些像红宝石脚本/生成黄瓜 - capybara) 。你是什么意思,你可以点击删除链接,但不是第二个链接?我不明白。 – wrtsprt 2011-04-18 08:26:10
我的意思是,我有一个工作人员名单,并且我有一个列表中每个工作人员的删除链接。如果可能,我想让黄瓜点击第二个删除链接。 – map7 2011-04-18 09:11:29