dem*_*tal 2 bdd ruby-on-rails cucumber capybara
鉴于我有一个包含10个用户列表的页面,如何测试我有10个用户显示链接?
我试过这个:
Then /^I should see a list of (\d+) users$/ do |num|
page.should have_selector('a', {:href=>"users/*", :count => num})
end
Run Code Online (Sandbox Code Playgroud)
还有这个 :
Then /^I should see a list of (\d+) users$/ do |num|
page.should have_selector('a', {:href=>/users\/\d+/, :count => num})
end
Run Code Online (Sandbox Code Playgroud)
但两者都返回预期的css"a"返回一些东西(RSpec :: Expectations :: ExpectationNotMetError)
但是,如果省略:count参数,则测试总是传递:href参数中的任何内容(甚至是错误的模式).
我会使用带有此contains函数的xpath :
page.should have_xpath("//a[contains(@href,'users')]"), :count => num)
Run Code Online (Sandbox Code Playgroud)
应该匹配具有包含文本'users' 的属性num的任何a元素的出现href.
| 归档时间: |
|
| 查看次数: |
2260 次 |
| 最近记录: |