2

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

This should actually be an accepted answer here. No need to resolve the promise here explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.