如何测试一个元素不';不存在RSpec吗?
如何测试元素是否不存在? 我尝试了以下操作,但得到的错误是如何测试一个元素不';不存在RSpec吗?,rspec,capybara,Rspec,Capybara,如何测试元素是否不存在? 我尝试了以下操作,但得到的错误是textarea#Question1Text不存在,而不是通过测试 it "should not have question 1" do find('textarea#Question1Text').should_not be end it { should_not find('textarea#Question1Text') } 您可以使用一个水豚匹配器(特别是have_css)来测试元素是否存在 it 'should not
textarea#Question1Text不存在
,而不是通过测试
it "should not have question 1" do
find('textarea#Question1Text').should_not be
end
it { should_not find('textarea#Question1Text') }
您可以使用一个水豚匹配器(特别是
have_css
)来测试元素是否存在
it 'should not have question1' do
page.should_not have_css('textarea#Question1Text')
end
容易的豌豆
expect{page.find_by_id("update-#{term1.id}").should}.not_to raise_error
expect{page.find_by_id("update-#{term4.id}")}.to raise_error
如果您没有唯一的ID,那么spullen建议的Css将起作用建议的方法的问题是,如果在单击按钮后隐藏字段,它们将具有竞争条件。在这种情况下,它会在点击按钮之后,但在javascript有机会找到它之前抓取页面,因此测试可能会失败。它往往是断断续续的,主要发生在像phantomjs这样的快速无头浏览器上 相反,我建议您使用以下方法:
expect(page).to have_selector("#id_of_element")
这将等待条件为真,但如果失败,仍将快速超时