Michael Warner Michael Warner - 3 months ago 31
AngularJS Question

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],
...
...

Answer

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

Comments