Question

I am trying to call done() for async tests but that is not working, i am getting 'undefined is not a function' error.

describe('Login screen tests', function () {
  var ptor = protractor.getInstance();
  beforeEach(function(){
    console.log('In before Each method');
    ptor.get('http://staging-machine/login/#/');
  });

  it('Blank Username & Password test', function(done) {
    ptor.findElement(protractor.By.id("submit")).click();
    var message = ptor.findElement(protractor.By.repeater('message in messages'));
    message.then(function(message){
      message.getText().then(function(text) {
        console.log("Message shown:"+text);
        expect(message.getText()).toContain('Username or Password can\'t be blank');
        done();
      });
    });
  });
});

I tried to google around, and found that there might be some issue with jasmine, but i am still unable to resolve this. Because the error seems to be really unexpected. Any help would be appreciated.

Was it helpful?

Solution

Are you sure you're getting undefined is not a function in line done() ?

I think your problem is here: ptor.findElement(protractor.By.repeater('message in messages')) because by then your clearly are on an Angular page so, regarding webdriver's findElement for a repeater: you should not be doing that.

Anyway, I would do 2 things:

  1. Upgrade Protractor to latest
  2. Rewrite the whole test like below since calling done() here is not required at all.

Rewrite:

describe('Login screen tests', function () {
  // Page Objects. TODO: Extract to separate module file.
  var submitBtnElm = $('#submit');
  var messagesRepElms = element.all(by.repeater('message in messages'));

  describe('Blank Username & Password test', function() {
    // Moved login get out of beforeEach since you need to get it once
    it('Opens an Angular login page', function() {
      browser.get('http://staging-machine/login/#/');
    });

    it('Clicks submit btn without entering required fields', function() {
      submitBtnElm.click();
    });

    it('Should trigger validation errors', function() {
      expect(messagesRepElms.first().isPresent()).toBeTruthy();
      expect(messagesRepElms.first().getText()).
        toContain('Username or Password can\'t be blank');
    });
  });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top