user2880391 user2880391 - 8 months ago 58
AngularJS Question

Protractor - compare numbers

In my program I'm calculating two numbers, and I want to make sure that subtraction of them equals 1.

this is the code:

var firstCount=element.all(by.repeater('app in userApps')).count();
var secondCount=element.all(by.repeater('app in userApps')).count();


so far it's good- I'm getting the numbers. the problem comes next:

var sub=secondCount-firstCount;
expect(sub).toEqual(1);


I'm getting this error:

Expected NaN to equal 1.


any idea?

Answer Source

Both firstCount and secondCount are promises that are needed to be resolved:

element.all(by.repeater('app in userApps')).count().then(function (first) {
    element.all(by.repeater('app in userApps')).count().then(function(second) {
        expect(first - second).toEqual(1);
    })
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download