2016-04-22 44 views
1

單擊手風琴元素後,手風琴面板將打開,但即使所需面板已展開,以下代碼中的expect()仍會通過(aria-expanded =「true 「)。我正在嘗試驗證是否已打開正確的面板。我是量角器新手 - 任何幫助將不勝感激。量角器預計不適用於非角度手風琴小部件

var el = element(by.css('#brainstormingLink')); 
el.click().then(function(){ 
    browser.sleep(1000).then(function(){ 
     expect(element(by.css('#BrainstormingAccordion[aria-expanded="false"])).isPresent()); 
    }); 
}); 

的HTML如下:

<h3 id="brainstormingLink" class="menuSectionLink ui-accordion-header ui-helper-reset ui-state-default ui-accordion-header-active ui-state-active ui-corner-top" sectionnum="1" role="tab" aria-controls="BrainstormingAccordion" aria-selected="true" tabindex="0">Brainstorm</h3> 
<div id="BrainstormingAccordion" class="accordion-inner scrollable ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" aria-labelledby="brainstormingLink" role="tabpanel" aria-expanded="true" aria-hidden="false" style="display: block; height: 282px; overflow: auto;"> 
    Follow these steps to brainstorm ideas:<br><br> 
     <ol> 
      <li>Use the add idea button <div class="toolbarButtonIcon inlineIcon"><div id="icon-plus">&nbsp;</div></div> to enter one idea, fact, or opinion about your topic that you think might be useful.</li> 
      <li>Continue using the add idea button <div class="toolbarButtonIcon inlineIcon"><div id="icon-plus">&nbsp;</div></div> to add as many ideas as you can.<br><br> 
       <div class="buttoncenter"><button class="btn btn-custom" type="button" name="brainstorming" title="brainstorming"> about brainstorming</button></div> 
      </li> 
     </ol> 
    </div> 
+0

請參閱http://stackoverflow.com/help/someone-answers。 – alecxe

回答

1

您的測試總是通過,因爲你沒有完成在expect聲明斷言。 .isPresent()所以你需要,不管你期待的結果是即完成它返回一個布爾.toBe(false).toBeTruthy()

只需注意isPresent真的問該元素出現在頁面上,如果你想知道如果目前對用戶可見,則使用.isDisplayed()。此外,由於該元素具有ID,因此我認爲您最好像使用第一個元素那樣定位它,除非無法定位它,否則HTML屬性不是必需的。我一直在使用ID,因爲它們是獨一無二的。

這裏可以斷言的列表:http://jasmine.github.io/2.0/introduction.html