等元素,我想測試下面的代碼:超時雖然與定位
<div name="userElem" *ngFor="let user of users ; let i=index">
<div class="list-group-item" id="user-{{i}}" (click)='selectUser(user)' [style.backgroundColor]="user?._id==selectedUser?._id ? '#F0F0EE' : 'white'">
<div *ngIf="user?._id==selectedUser?._id">
<div class="pull-right">
<a id="delete-user-{{i}}" (click)="deleteUser(user._id)">
<i class="fa fa-trash fa-fw"></i>
</a>
<a (click)="editUser(user._id)">
<i class="fa fa-pencil fa-fw"></i>
</a>
<a [routerLink]="['/edit',user._id]" name="userLink-{{i}}">
<i class="fa fa-eye fa-fw"></i>
</a>
</div>
</div>
</div>
</div>
使用下面端到端測試案例:
it('should delete a user',() => {
page.navigateToUserComponent();
let selectUserElem = element(by.id('user-0')).click(); //this event is fired as I can see user getting selected.
let deleteUserElem = element(by.id('delete-user-0'));
browser.wait(function() {
return browser.isElementPresent(by.id('delete-user-0'));
}, 5000);
expect(deleteUserElem.isPresent()).toBeTruthy(); // if element is present I want to click that element .i.e. delete the first user in array
});
但至今沒有得到任何成功。
我想在這個環節討論多種方法:
,但不能使它工作。 有幫助嗎?
感謝
我認爲身份證'刪除用戶0'是不恆定的你可以檢查一次 –
@SureshSalloju當我的angular2應用程序運行時,檢查DOm顯示ID爲:id ='delete-user-0''..其中delete-user是一個字符串&0是一個索引 –
deleteUserElem = element.all(by.css('[name =「userElem」]> div> div> div> a))。first()試試 –