Michael Warner
Michael Warner

Reputation: 4217

Pulling ng-repeat array in protractor

I'm using Protractor and I can't find a way to pull the ng-repeat value to verify the data is populating.

HTML

<div ng-repeat="product in products></div>

PROTRACTOR TEST

it( 'should load product data.', function() {
  auth(); //log in as user
  browser.get(server.dev + '/path').then(function(){
    var products = element.all(by.repeater('product in products'));
    console.log('products',products);
    expect( products.length >= 1 )
      .toBeTruthy();
    });
} );

The console shows an Element Array Finder not the data.

ElementArrayFinder {
  browser_: 
   ProtractorBrowser {
     actions: [Function],
     wait: [Function],
     sleep: [Function],
...
...

Upvotes: 2

Views: 437

Answers (2)

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

You can also use element.all().count() to get the number of elements found for the given selector, look at the below code

it( 'should load product data.', function() {
  auth(); //log in as user
  browser.get(server.dev + '/path').then(function(){
     var products = element.all(by.repeater('product in products'))
     expect(products.count()).toBeGreaterThan(0);
    });
 });
});

Upvotes: 2

MBielski
MBielski

Reputation: 6620

You need to let the promise that element.all returns resolve first.

it( 'should load product data.', function() {
  auth(); //log in as user
  browser.get(server.dev + '/path').then(function(){
    var products = element.all(by.repeater('product in products')).then(function(products){
        console.log('products',products);
        expect( products.length >= 1 ).toBeTruthy();
        });
    });
});

Found in the Protractor docs HERE: http://www.protractortest.org/#/api?view=ElementArrayFinder

Upvotes: 2

Related Questions