2016-04-14 40 views
1

我即將測試與nightwatch/selenium一點下拉選擇框。 雖然測試我經歷了選擇框的選項似乎是可見的(對於測試運行者),即使它沒有被點擊。 我在HTML中很少有技能,因此我不確定這是默認行爲還是我的測試有點壞。選擇框選項是可見還是隱藏?

Testcode:

var urlToOptionsPage ='chrome-extension://dafanlbggefkfnbekjceijjhgcancpik/html/options.html'; 

module.exports = { 

    '[Options Page UI] - project list': function(browser) { 
    browser 
     .url(urlToOptionsPage) 
     .pause(500) 
     .waitForElementVisible('#projects', 5000) 
     .assert.value('#projects', 'BWK') 
     //.click('#projects') 
     .waitForElementVisible('#projects > option:nth-child(1)', 5000) 
     .end() 
    } 
}; 

HTML:

<select name="projects" id="projects"> 
    <option value="BWK">BWK</option> 
    <option value="DMG">DMG</option> 
    <option value="ABC">ABC</option> 
</select> 

試驗結果:

✔ Element <#projects> was visible after 52 milliseconds. 
✔ Testing if value of <#projects> equals: "BWK". 
✔ Element <#projects > option:nth-child(1)> was visible after 35 milliseconds. 

回答

1

在Chrome實在不行,但在Firefox中至少是這樣。所以我的答案是;它的瀏覽器依賴。您可以運行測試:

// jQuery required 
var optionsVisible = $('option').eq(0).is(':visible'); 
alert(optionsVisible); //alert if options are visible or not 

或看看here

+0

感謝您的快速回答 – xetra11

+0

@ xetra11非常歡迎您! –