我基本上尝试获取“has_content?”的功能。或“should have_content”匹配器选项:count为has_css提供?匹配器。
答案 0 :(得分:2)
你可以尝试类似所有('a')。长度
以下是几个例子:
describe 'my awesome page' do
before :each do
visit root_path
end
# css just for querying DOM
it 'number of titles should be huge' do
page.all(:css,'h2.awesome_header').length.should have_at_least(3).items
end
it 'has exactly 4 div elements' do
page.all(:css,'div.awesome_class').length.should == 4
end
# For querying content you can try :xpath instead :css.
it 'has paragraps with text' do
page.all(:xpath, '//div[contains(., "t")]').length.should == 9
end
end
<强>更新强>
我找到更优雅的方式来做到这一点。 在此处查看文档:{{3}} 这是工作示例
page.all(:css, 'p', :text => /.*wellcome.*/).length.should == 2