Kendall
Kendall

Reputation: 5245

Waiting for element by.css() in protractor

I have some code in which $scope.$broadcast triggers an event which executes an element.addClass()

code in my controller

ctrlr.rollDice = function(){
 .... do some stuff 
 $scope.$broadcast('eventType', args);
}

code in my directive

scope.$on('eventType', function(){ element.addClass('class'); });

I am trying to wait until the event has fired and the element.addClass is executed in my protractor test using

browser.wait(element(by.css('.activate')).isPresent,15000).then(function(isPresent){
      expect(isPresent).toBe(true);
    });

However, I get the following error

TypeError: Cannot read property 'getWebElements' of undefined

How do I wait for the element with the class .activate to show up ??

Note that element can be any random visible element ...it is just to set the class. Also if I were to run the project in my actual web browser....everything runs successfully.

Upvotes: 1

Views: 1719

Answers (1)

Andres D
Andres D

Reputation: 8900

Try this:

browser.wait(() => $('.activate')).isPresent() ,15000);
expect($('.activate').isPresent()).toBe(true);

Or the ES5 version

browser.wait(function() {
  return $('.activate').isPresent();
}, 15000);
expect($('.activate').isPresent()).toBe(true);

Note: element(by.css('.abc')) === $('.abc')

Upvotes: 2

Related Questions