gpt4 book ai didi

angularjs - 删除 NG-repeat Protractor 中的一条记录

转载 作者:搜寻专家 更新时间:2023-10-31 23:09:17 26 4
gpt4 key购买 nike

所以我正在用 Protractor 和 Angular 进行端到端测试,
我的第一个测试是向列表中添加一个元素,
现在我正在尝试删除它,但我在这样做时遇到了麻烦

所以这就是我需要做的:

  1. 找到我要删除的记录的名称
  2. 单击同一行的垃圾桶图标并将其删除
  3. 在出现的弹出窗口中按确定
  4. 尽量避免使用 By.css 并更喜欢与 Angular 相关的所有内容(byBinding、model 等)。这是因为应用程序的这一部分最终可能会发生变化,因此我将不得不重做所有这些案例。

HTML:

...

<div class="list-group-item ng-scope" ng-repeat="item in teamList">
<span class="glyphicon glyphicon-user"></span>
<span ng-bind="item.name" class="memberName ng-binding">nuevo Team</span>
<a ng-click="editTeam(item._id)" class="hand-cursor">
<span class="glyphicon glyphicon-edit memberRemoveBotton"></span>
</a>
<a ng-confirm-click="Would you like to delete this item?" confirmed-click="deleteTeam(item._id)" class="hand-cursor">
<span class="glyphicon glyphicon-trash memberRemoveBotton"></span>
</a>
</div>

JS:

describe('Testing delete Item',function() {
it('Should delete the Item that just got Inserted',function() {
element(by.css('a[href="#!/item-create"]')).click(); //Opens up the Item dashBoard
element.all(by.repeater('item in itemList')).then(function(table) {
table.element(by.binding('item.name')).each(function(names) {
console.log('the names',names.getText());//I'm trying to find the name of the item that just got inserted
// is there like a nested chaining of elements in here ??
});
});
});
});

感谢任何有关如何解决此问题的提示

最佳答案

describe('Testing delete Item',function() {
it('Should delete the Item that just got Inserted',function() {
// Assume you know the name of the item you want to delete.
var nameToDelete = 'some name';

// Get the row that has the name by using filter.
element.all(by.repeater('item in itemList')).filter(function(row){
return row.element(by.css('.memberName')).getText().then(function(name){
return name === nameToDelete;
});
})
// Now you should have one row.
.get(0)
// Get the row and click find the remove button.
.element(by.css('.memberRemoveBotton'))
.click();

// Make sure it was deleted.
var names = $$('.list-group-item .memberName').getText();
expect(names).not.toContain(nameToDelete);
});
});

让我知道它是否有效。

关于angularjs - 删除 NG-repeat Protractor 中的一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28464730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com