使用RSpec/XPath/CSS选择body:before
我正在尝试编写一个Cumber测试,以确保Compass CSS没有错误 使用以下CSS将错误消息插入到页面中,例如:使用RSpec/XPath/CSS选择body:before,css,xpath,rspec,cucumber,css-selectors,Css,Xpath,Rspec,Cucumber,Css Selectors,我正在尝试编写一个Cumber测试,以确保Compass CSS没有错误 使用以下CSS将错误消息插入到页面中,例如: body:before { white-space: pre; font-family: monospace; content: "Syntax error: Undefined mixin 'horizontal-list'"; } 所以我想写一个确保正文的步骤:before的内容是空的,我一直在尝试以下方面的变化: page.should_not have_
body:before {
white-space: pre;
font-family: monospace;
content: "Syntax error: Undefined mixin 'horizontal-list'";
}
所以我想写一个确保正文的步骤:before的内容是空的,我一直在尝试以下方面的变化:
page.should_not have_css("body:before")
但这就产生了错误:
xmlXPathCompOpEval: function before not found
有人知道如何获取:before吗?经过多次搜索,我认为没有办法以优雅的方式获取:before中的内容。但是,我有一些东西可以很好地满足我的需要,所以我想与大家分享:
Then /^I should not see any compass errors$/ do
page.evaluate_script("document.styleSheets[1].cssRules[0].selectorText == \"body:before\";").should be_false;
end
以上测试第一个cssRule是否具有body:before的selectorText-如果Compass在页面中插入了错误,则为真
如果您想使用上述功能,请注意以下几点:
如果有人知道一个更好的方法来做这件事,我会非常感兴趣-但现在,上述将阻止任何罗盘错误偷偷通过 我认为这与它是一个伪元素有关,而不是一个真正的HTML元素。是的,我得出了相同的结论——尽管我知道为什么have_xpath会因为我期望have_css能够工作而感到不安!