在量角器中拉出ng-repeat阵列

时间:2016-08-19 16:11:45

标签: angularjs protractor

我正在使用Protractor,我无法找到一种方法来提取ng-repeat值来验证数据是否正在填充。

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

控制台显示Element Array Finder而非数据。

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

2 个答案:

答案 0 :(得分:2)

您需要让element.all首先返回解析的承诺。

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

在这里的量角器文档中找到:http://www.protractortest.org/#/api?view=ElementArrayFinder

答案 1 :(得分:2)

你也可以使用element.all()。count()来获取给定选择器的元素数量,看下面的代码

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