Umair Jameel
Umair Jameel

Reputation: 1673

if condition in protractor not working correctly (AngularJS)

I am first getting total number of li elements within ul like this.

var dropElementLength = dropdown_ul.all(by.tagName('li')).count();

Now dropElementLength is having 4. if test this variable with if condition like so.

 if(dropElementLength == 4) {
    expect(dropElementLength).toEqual(34);
 } else {
    expect(dropElementLength).toEqual(634);
 }

The error is 'Expected 4 to equal 634', where as error should 'Expected 4 to equal 34'. But if condition should gets true as dropElementLength is equal to 4.

Why if condition is not getting true?

Upvotes: 0

Views: 64

Answers (2)

Umair Jameel
Umair Jameel

Reputation: 1673

After @Kacper comment, I resolved my problem by writing this code.

dropElementLength.then(function (value) {
     if (value === 4) {
          expect(value).toEqual(34);
     } else {
          expect(value).toEqual(634);
     }
})

Upvotes: 0

Kacper
Kacper

Reputation: 1199

dropElementLength returns a promise not a bool.

Use chai-as-promised: expect(dropdown_ul.all(by.tagName('li')).count()).to.eventually.equals(34);

Upvotes: 1

Related Questions