Search code examples
javascriptangularjsprotractorsubtractionend-to-end

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?


Solution

  • 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);
        })
    });