[英]Angular E2E testing getting hidden elements to show only during E2E
Currently I am using browser.executeScript
to change hidden elements to show up during E2E. 当前,我正在使用
browser.executeScript
更改隐藏元素以在E2E期间显示。
In my app.po.ts, I have a function to set display
to inline
. 在我的app.po.ts中,我具有一个将
display
设置为inline
的功能。
browser.executeScript('arguments[0].style.display = "inline"',getHiddenElements());
By default, the hidden elements have css display = none
so it won't show up during prod/dev. 默认情况下,隐藏元素的css
display = none
因此它不会在prod / dev中显示。
My hidden component template: 我隐藏的组件模板:
.hidden{
display: none;
}
<div class="hidden">
...... my hidden elements .......
</div>
Problem: The code in hidden component runs when the elements are hidden too. 问题:元素也被隐藏时,隐藏组件中的代码也会运行。 I prefer not to run it.
我宁愿不运行它。 Currently I am trying to have a conditional check in the component code to check for the hidden element css
display
style but I am unable to achieve it with Renderer2
or ElementRef
to get the css class.hidden
. 目前,我正在尝试在组件代码中进行条件检查,以检查隐藏元素css的
display
样式,但是我无法通过Renderer2
或ElementRef
来实现,以获取css class.hidden
。
How can I ensure that codes in hidden elements only runs during E2E testing, but not during dev/prod mode? 如何确保隐藏元素中的代码仅在E2E测试期间运行,而不在开发/生产模式下运行? Is there anyway to check if
.hidden.display
is none or in-line in hidden.component.ts
? 无论如何,是否要检查
.hidden.display
是none还是hidden.component.ts
?
Try it 试试吧
browser.executeScript('arguments[0].style.display = "inline-block"',getHiddenElements());
or 要么
browser.executeScript('arguments[0].style.display = "block"',getHiddenElements());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.