在我的应用程序中,我有一个 Controller ,它的范围有一个模型,用于确定我 View 中的条件。非常标准。
Controller
$scope.shouldShow = false;
$scope.seeCoal = true;
查看
<div ng-controller="SomeController" ng-if="shouldShow">
<span id="coal" ng-show="seeCoal"></span>
</div>
很公平。当我将此 shouldShow
更改为真实的内容时,此 div 将呈现。
Protractor 将如何解释它及其包含的标记?如果我的测试没有将shouldShow
模型设置为true,那么#coal
元素是否会被 元素视为存在。 isPresent()
?
此外,如果(在我的测试中)我不将shouldShow
设置为truthy(保持为false),并将seeCoal
设置为false - 我是否能够遍历到 #coal
以确认 ng-hide
类存在,即使它的父类有一个 ng-if
评估为假的条件?
在我尝试这个的项目中,我有太多的不确定性,我不能确定 Protractor 在这些情况下应该如何工作。
最佳答案
Angular 的 ng-if
将从 DOM 中移除受影响的元素。因此,它们及其子元素将不会以任何形式对 Protractor 可见。如果 shouldShow
为假, Protractor 将根本看不到“煤炭”跨度。
ng-show
将元素留在 DOM 中,但使其不可见。参见 what is the difference between ng-if and ng-show/ng-hide .
Protractor 定位器应该能够找到 ng-show
隐藏元素。 isDisplayed()
方法的 promise 应 promise 返回 false。参见 How to use protractor to check if an element is visible?
关于angularjs - Protractor isPresent() 结果在/与 ng-if 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29038009/