title: Angular e2e test to check a list of elements
body: <p>My case is as follows - I have a simple page which lists available products:</p>
  
  <pre><code>&lt;ul class="products ng-scope" id="products"&gt;
    &lt;!-- ngRepeat: tag in products --&gt;
    &lt;li ng-repeat="product in products" class="ng-scope"&gt;
      &lt;a ng-href="/#/viewProduct/1" class="ng-binding" href="/#/viewProduct/1"&gt;Product A&lt;/a&gt;
    &lt;/li&gt;&lt;li ng-repeat="product in products" class="ng-scope"&gt;
      &lt;a ng-href="/#/viewProduct/2" class="ng-binding" href="/#/viewProduct/2"&gt;Product B&lt;/a&gt;
    &lt;/li&gt;&lt;li ng-repeat="product in products" class="ng-scope"&gt;
      &lt;a ng-href="/#/viewProduct/3" class="ng-binding" href="/#/viewProduct/3"&gt;Product C&lt;/a&gt;
    &lt;/li&gt;&lt;li ng-repeat="product in products" class="ng-scope"&gt;
      &lt;a ng-href="/#/viewProduct/4" class="ng-binding" href="/#/viewProduct/4"&gt;Product D&lt;/a&gt;
    &lt;/li&gt;&lt;li ng-repeat="product in products" class="ng-scope"&gt;
      &lt;a ng-href="/#/viewProduct/5" class="ng-binding" href="/#/viewProduct/5"&gt;Product E&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>In my angular scenario I want to test if the list of products is equal to expected. I know it can/should be a unit test, but suppose I want an e2e test.</p>
  
  <p>After reading the official docs (<a href="http://docs.angularjs.org/guide/dev_guide.e2e-testing" rel="nofollow">http://docs.angularjs.org/guide/dev_guide.e2e-testing</a> - which as usual cover 10% of the subject) and debugging angular code I managed to write the following test:</p>
  
  <pre><code>'use strict';
  
  describe('my app', function() {
    var productsList = [
      'Product A',
      'Product B',
      'Product C',
      'Product D',
      'Product E'
    ];
  
    it('should list all products', function() {
      browser().navigateTo('/#/products');
      var foundProducts = element('#products li').query(function(elements, done) {
        var productsArray = [];
        elements.each(function(index) {
          productsArray.push(elements[index].innerText);
        });
  
        done(null, productsArray);
      });
  
      expect(foundProducts).toEqual(productsList);
    });
  });
  </code></pre>
  
  <p>Can anyone please tell me how this can be done easier?</p>
  
  <p>And the second question, why elements[index].text() is undefined - which in fact is a question how to jet a jQuery object out of elements[index].</p>