如何用量角器或硒测试@media print?

How to test @media print with protractor or selenium?(如何用量角器或硒测试@media print?)
本文介绍了如何用量角器或硒测试@media print?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经在我的网站上实现了打印功能,我想通过量角器/硒对其进行测试.

I've implemented an print functionallity at my site, and I would like to test it via protractor / selenium.

在测试期间有什么方法可以应用" @media print 下的样式?

There is any method to "apply" the styles that are under @media print during the test?

我只看到了一个相关的问题,但它没有任何好的答案.

I saw only one relevant question, but it without any good answer.

例如在那个示例中,我希望 #hidden div 将在测试期间显示.

For example at that sample I would like to the #hidden div will be shown during the test.

.print-only {
  display: none;
}

@media print {
  .print-only {
    display: block;
  }
}

<div id="hidden" class="print-only">Will be shown when printing</div>

推荐答案

我发现的一个选项是将所有打印" css 拆分为一个单独的文件,并通过 link 加载它带有 media="print" 的标签.

One option that I've found is to split all the "print" css into a separate file, and load it via link tag with media="print".

<link rel="stylesheet" type="text/css" href="print.css" media="print">

意思是根本不在大型css文件中使用媒体查询.

Meaning not to use media query inside large css file at all.

这样我可以在测试期间通过 executeScriptmedia="print" 属性更改为 all.

That way will allow me to change the media="print" attribute during test to all via executeScript.

希望对某人有所帮助.

这篇关于如何用量角器或硒测试@media print?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

AttributeError: #39;list#39; object has no attribute #39;click#39; using Selenium and Python(AttributeError: list 对象没有使用 Selenium 和 Python 的属性 click)
How to execute JavaScript in Ruby written Webdriver test?(如何在 Ruby 编写的 Webdriver 测试中执行 JavaScript?)
Selenium WebDriver get text from CSS property quot;contentquot; on a ::before pseudo element(Selenium WebDriver 从 CSS 属性“内容获取文本在 ::before 伪元素上)
ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python(ElementClickInterceptedException:消息:元素单击被拦截元素不可点击错误单击使用 Selenium 和 P
An error has occured in #39;site url#39;: Uncaught TypeError: Cannot read property #39;getColomnSet#39; of undefined with Selenium and Python(“站点 url中发生错误:未捕获的类型错误:无法使用 Selenium 和 Python 读取未定义的属性“getColomnSet)
GIve css3 rotate to a DIV in Chrome then the background-attachment:fixed creating bug(将 css3 旋转到 Chrome 中的 DIV 然后背景附件:修复创建错误)