我正在使用capybara写我的rails应用程序的请求规范。在我的代码中,我有类似的东西:
%table
%tbody
%tr{"on_click" => "location.href='some_link'"}
%td="Some attribute"
%td="Some attribute"
%td="Some attribute"
%td="Some attribute"
这样我就可以整行整行。我想用capybara为这个功能写一个请求规范,但我不知道怎么做。谁可以帮我这个事 ?
谢谢
答案 0 :(得分:6)
可能你应该首先了解rails中的测试。看一下这个! http://railscasts.com/episodes/275-how-i-test这真的很有帮助。您可以为tr
一个班级(比方说).tr
提供
page.find(:css, ".tr").click()
我希望这有效,在我的情况下工作!
答案 1 :(得分:5)
我发现这可以不需要课程:
page.find(:xpath, "//table/tbody/tr").click
我相信您的行点击需要JavaScript,因此您需要将:js => true
添加到测试的标题中。使用JavaScript设置测试是一项挑战。我发现这些资源很有帮助:
这是一个更完整的测试示例:
# Note that opening page by clicking on row requires JavaScript
describe "when user clicks on first row", :js => true do
let(:first_account_listed) { Account.order(:name).first }
before { page.find(:xpath, "//table/tbody/tr").click }
it { should have_selector('title', text: 'Account Details') }
end