user2880391 user2880391 - 3 years ago 235
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;

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