我的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: Admin dashboard delete Exports create export Message:
NoSuchElementError: No element found using locator: By.id(“export”)
我发现问题在于:
元素isPresent()和isDisplayed()
原文链接:https://www.f2er.com/angularjs/141365.html元素isPresent()和isDisplayed()
因此,如果您只等待isPresent(),它可以在html中找到但尚未显示.
如果你只是想使用elm.isDisplayed(),那么它将会崩溃,如果该元素尚不存在,它将会崩溃.所以你必须先检查isDisplayed()之前是isPresent()
this.waitUntilReady = function (elm) { browser.wait(function () { return elm.isPresent(); },10000); browser.wait(function () { return elm.isDisplayed(); },10000); }; describe('Admin dashboard delete Exports',function () { browser.get(e2GUrl + '/admin/studies'); waitUntilReady(element(by.id('export'))); element(by.id('export')).click(); });