我正在尝试测试以下代码:
<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>
使用低于E2E测试用例:
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 :(得分:0)
使用ExpectedConditions
和browser.wait()
使您的脚本等待某些条件:
var EC = protractor.ExpectedConditions;
var elm = element(by.id('delete-user-0'));
browser.wait(EC.presenceOf(elm), 5000);
答案 1 :(得分:0)
如果要识别第一个delete_user元素,可以使用以下xpath。
let deleteUserElem = element.all(by.xpath(".//a[contains(@id, 'delete-user-')]")).first();
然后你可以将它与量角器预期条件联合起来,等到所需的web元素出现。
EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(deleteUserElem),20000, 'element is not visible within the time specified');
答案 2 :(得分:0)
您使用的是socket.io吗?如果您在应用中使用socket.io,似乎存在量角器不起作用的错误:https://github.com/angular/angular/issues/11853。