Reputation: 1272
I have a div on my page that is hidden by ng-if sometimes. I want to devise a test that checks whether the element is present ONLY when it should be present. ng-if completely removes the element from the DOM if the test fails.
I tried to write an if statement in protractor that evaluated the same thing that my ng-if is evaluating and then expect a value only if that evaluated to true but it looks like protractor isn't aware of non-dom elements, which makes sense but leaves me a little stumped as to what to do. Any ideas?
Upvotes: 0
Views: 2256
Reputation: 3240
For this solution, we need to check first, element is present or not
<div id="status" ng-if="data.isDeleted">
<span id="delete_status"> Deleted </span>
</div>
If data.isDeleted is true than we do expect further
var statusId= element(by.id('status'));
statusId.isPresent().then(function (present){
if(present){
expect(statusId.evaluate("data.isDeleted")).toBeTruthy();
expect(statusId.element(by.id("delete_status")).getText()).toContain("Deleted");
}
});
Upvotes: 0
Reputation: 473873
There is .isPresent()
method that checks for presence of an element in the DOM:
expect(elm.isPresent()).toBe(false);
You can also use .evaluate()
to evaluate the ng-if
value:
expect(elm.evaluate("ng_if_value")).toBe(false);
Upvotes: 0