根据 capybara 的自述文件:
以下两个语句在功能上是等效的:
page.should_not have_xpath('a') page.should have_no_xpath('a')
但是,当尝试这样做时,这似乎并不正确。使用 capybara-webkit 时,这似乎工作正常:
visit dashboard_accounting_reports_path
click_link 'Delete'
page.should_not have_css('#reports .report')
但是当使用 poltergeist 时,它经常会失败,这似乎是在说它在幕后使用#has_css?
,实际上并不会等待给定的元素消失:
Failure/Error: page.should_not have_css('#reports .report')
expected #has_css?("#reports .report") to return false, got true
如果我将断言改为这样读取,它似乎每次都成功:
page.should have_no_css('#reports .report')
我疯了,还是这是 poltergeist 中的错误?我正在使用 PhantomJS 1.8.2、poltergeist 1.1.0 和 capybara 2.0.2。
should_not have_css
这是示例的调试输出:http: //pastebin.com/4ZtPEN5B
这是should have_no_css
示例中的一个:http: //pastebin.com/TrtURWcZ