22

I'm trying to count the elements in repeater and to print it to console.

This is the markup:

<div class="col-md-3 ng-scope" ng-repeat="app in userApps" >...< /div> 

currently I'm counting and comparing:

expect(element.all(by.repeater('app in userApps')).count()).toEqual(4);

it works, but I want to be able to print it also.

I've tried this:

var rows = element.all(by.repeater("app in userApps"));
var sum = rows.count(); 
console.log(sum.getText());

but I'm getting:

TypeError: Object [object Object] has no method 'getText'

there are two question actually- 1. am I doing it the correct way? 2. how do I print it to console?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
user2880391
  • 2,683
  • 7
  • 38
  • 77

2 Answers2

46

If I understand your problem correctly, you actually want to print the count and not the entire content, right?

element.all(by.repeater('app in userApps')).count().then(function(count) {
  console.log(count);
});
e-shfiyut
  • 3,538
  • 2
  • 30
  • 31
hankduan
  • 5,994
  • 1
  • 29
  • 43
  • you are right. it is what i meant. but now, with your code I'm getting this error immediately: SyntaxError: Unexpected identifier Stacktrace: SyntaxError: Unexpected identifier at require (module.js:380:17) at Function.promise (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:650:9) – user2880391 Jan 21 '15 at 20:25
  • 1
    it Works! just needed to add ';' and ');' : element.all(by.repeater('app in userApps')).count().then(function(count) { console.log(count); }); thanks a lot! – user2880391 Jan 21 '15 at 20:45
  • Thanks guys! amazing :) – borracciaBlu Jun 19 '15 at 08:40
0

the more 'modern' way of doing this is using async/await

it('test case', async () => {
  let count = await element.all(by.repeater('app in userApps')).count();
  console.log(count);
});
Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40