2015-01-19 19 views
7

Tôi gặp vấn đề với các kiểm tra end2end của mình. Đôi khi họ vượt qua mà không có bất kỳ vấn đề, nhưng hai phần ba thời gian họ thất bại. Tôi sử dụng thước đo góc với đoạn mã sau:Thước đo chờ đợi cho isElementPresent và nhấp vào yếu tố chờ đợi không thành công

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 (lưu ý rằng yếu tố này có thể nhìn thấy và không giấu bởi ng-nếu hay 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> 

Lỗi Tôi nhận:

E2E: Admin dashboard delete Exports create export Message: NoSuchElementError: No element found using locator: By.id("export")

+0

nếu tôi nhận xét ra các hành động nhấp chuột nó chạy mỗi khi tốt –

+0

gì nếu bạn thêm 'trình duyệt .waitForAngular(); 'sau cuộc gọi' get() '? – alecxe

+0

doens't dường như không hoạt động đôi khi –

Trả lời

20

Tôi phát hiện thấy sự cố có sự khác biệt giữa: elementisPresent()isDisplayed()

vì vậy nếu bạn chỉ đợi isPresent(), bạn có thể tìm thấy nó trong html nhưng chưa được hiển thị.

khó khăn nếu bạn chỉ muốn sử dụng elm.isDisplayed() chỉ, nó sẽ sụp đổ nếu phần tử chưa tồn tại. Vì vậy, bạn phải kiểm tra đầu tiên là isPresent() trước isDisplayed()

tôi đã thực hiện một chức năng mà chờ đợi chặn cho 2 thuộc tính:

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(); 
     }); 
Các vấn đề liên quan