1
在我的Angular应用程序中,我有一个表格(ng-grid是精确的),并且我有一个向它添加新元素的过程。我省去了细节,但是这个过程是多步骤的,涉及与服务器交谈并在ng-grid表中生成一个新项目。我知道新项目的名称,我想检查量角器测试是否确实添加了这个项目。这是我试图做到这一点:检查新元素是否已添加到量角器中的表中
var nameTestItem="mySuperItem";
//... some actions to add the element, and going back to the page with the table
browser.get('#/resTable');
//checking if there is new item with this title
var element_added=false;
//picking the cell of the table with css selector and searching for the text
element.all(by.css('div.ui-grid-cell-contents')).then(function(elements) {
_.forEach(elements, function(el) {
el.getText().then(function(text){
console.log(text);
element_added= element_added || (nameTestItem==text);
});
});
});
browser.sleep(1000);
browser.pause();
expect(element_added).toBeTruthy();
显然我的问题是,我正在处理很多承诺。你将如何解决这个问题?我真的不想依靠count()
,因为我不想在几个人执行测试时发生碰撞。