Unknown developer
Unknown developer

Reputation: 5930

Protractor does not perceive a quick change

This is my protractor test:

it("should check email validity", function(){
      var resetButton = element(by.id('reset-button'));
      element(by.model('Contact.email')).sendKeys('nick');
      element.all(by.css('.form-control-error')).each(function (elem, index) {
        if (index===1) {
           expect(elem.isPresent()).toBe(true);
           element(by.model('Contact.email')).sendKeys('@gmail.com').then(
             function(){
              expect(elem.isPresent()).toBe(false);
             }
           )
        }
      });  
    }); 

Behind that code there is a form with some input texts. The second one includes the email.form-control-erroris an error message which appears whenever the email format is not correct. The first time expect(elem.isPresent()).toBe(true);passes the test, the second time it does not, even if the error message disappears from the UI. It seems that Protractor does not perceive the fast change; however, it should because it is inside a promise. Do you have any explanation for that?

Upvotes: 1

Views: 38

Answers (1)

alecxe
alecxe

Reputation: 473833

You should make things more reliable by adding a wait for the element to become not present ("stale") after sending the keys:

element(by.model('Contact.email')).sendKeys('@gmail.com');

var EC = protractor.ExpectedConditions;
browser.wait(EC.stalenessOf(elem), 5000);
expect(elem.isPresent()).toBe(false);

Upvotes: 1

Related Questions