Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用RSpec/XPath/CSS选择body:before_Css_Xpath_Rspec_Cucumber_Css Selectors - Fatal编程技术网

使用RSpec/XPath/CSS选择body:before

使用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_

我正在尝试编写一个Cumber测试,以确保Compass CSS没有错误

使用以下CSS将错误消息插入到页面中,例如:

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在页面中插入了错误,则为真

如果您想使用上述功能,请注意以下几点:

  • 根据您的驱动程序,您可能需要在场景中添加@javascript标记(否则您可能会遇到NotSupportedByDriverError异常)
  • 样式表的数组索引可能会有所不同(取决于导入样式表的顺序)
  • 如果您使用Internet Explorer作为测试浏览器,则需要更改JS-请参见此处:
  • 我遇到了Safari和Firefox之间的一个区别——Safari选择了OrText作为“body::before”,而Firefox选择了“body:before”(注意:vs:),其他浏览器可能也有类似的问题

  • 如果有人知道一个更好的方法来做这件事,我会非常感兴趣-但现在,上述将阻止任何罗盘错误偷偷通过

    我认为这与它是一个伪元素有关,而不是一个真正的HTML元素。是的,我得出了相同的结论——尽管我知道为什么have_xpath会因为我期望have_css能够工作而感到不安!