我的end2end测试有问题。有时它们通过没有任何问题,但失败的时间占三分之二。我使用带有以下代码的量角器:
describe('Admin dashboard delete Exports', function () {
it('create export', function () {
browser.get(e2GUrl + '/admin/studies');
ptor.wait(function() {
return ptor.isElementPresent(by.id('export'));
}, 5000, 'wait for study list page to be loaded.');
element(by.id('export')).click();
});
HTML(请注意,此元素是可见的,不会被ng-if或ng-show隐藏):
<ul>
<li data-ng-repeat="study in studies">
<div data-ng-controller="ExportController" class="btn-group">
<a id="export" class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fw-icon fw-icon-cloud-download"></i>Export
<span class="caret"></span>
</a>
<ul class="dropdown-menu export-list">
<li class="excel"><a data-ng-click="excel(study.Code)">Export to Excel</a>
</li>
</ul>
</div>
</li>
</ul>
我收到的错误:
E2E:管理仪表板删除导出创建导出消息:NoSuchElementError:使用定位符未找到元素:By.id(“ export”)
我发现问题出在:element
isPresent()
和isDisplayed()
因此,如果您只等待isPresent()
它,则可以在html中找到它,但尚未显示。
如果只想使用elm.isDisplayed()
,则比较棘手,如果该元素尚不存在,它将崩溃。所以你必须先检查isPresent()
之前isDisplayed()
我做了一个等待2个属性阻塞的函数:
this.waitUntilReady = function (elm) {
browser.wait(function () {
return elm.isPresent();
},10000);
browser.wait(function () {
return elm.isDisplayed();
},10000);
};
describe('Admin dashboard delete Exports', function () {
it('create export', function () {
browser.get(e2GUrl + '/admin/studies');
waitUntilReady(element(by.id('export')));
element(by.id('export')).click();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句