2016-08-19 32 views
2

我使用的是Protractor,我無法找到一種方法來拉ng-repeat值來驗證數據是否填充。在量角器中拉ng-repeat數組

HTML

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

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

控制檯顯示元件陣列搜索器而不是數據。

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

回答

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

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')) 
    expect(products.count()).toBeGreaterThan(0); 
    }); 
}); 
}); 
+0

這實際上應該是這裏接受的答案。沒有必要明確地解決這個承諾。 – alecxe