2014-02-10 56 views
0

我是網絡應用程序自動化測試的新手。我正在使用watir-webdriver通過應用程序自動執行我們的功能測試。 我將我的javascript下拉菜單與Watir一起測試,就像我知道的一樣。我無法過去,每一次嘗試都會導致錯誤。Watir點擊下拉列表

關於一個提示,我將非常感激

<section class="price-calculation" data-view="Forms.Pricecalculation,Forms.HelpInfo"> 
      <form action="/index.php" method="post" class=""> 
        <input type="hidden" name="tx_bodpricecalculation_pi1[controller]" value="priceCalc"> 

          <input type="hidden" name="tx_bodpricecalculation_pi1[action]" value="calculate"> 
          <input type="hidden" name="type" value="54321">       


        <input type="hidden" name="tx_bodpricecalculation_pi1[isEditor]" value="0"> 

        <input type="hidden" name="tx_bodpricecalculation_pi1[binding]" id="binding" value=""> 

        <section class="input-group-container select-casade clearfix"> 
         <div class="input-group product first"> 
          <div class="input-fields"> 
           <select name="tx_bodpricecalculation_pi1[product]" data-required="" id="selFNF" class="chzn-done" style="display: none;"> 
            <option value="" selected="selected" disabled="">ProduktNEU</option> 
            <option value="FunNEU">FunNEU</option> 
            <option value="ClassicNEU">ClassicNEU</option> 
            <option value="ComfortNEU">ComfortNEU</option> 
           </select><div id="selFNF_chzn" class="chzn-container chzn-container-single chzn-container-single-nosearch" style="width: 76px;" title=""><a href="javascript:void(0)" class="chzn-single"><span>Comfort</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" readonly=""></div><ul class="chzn-results" tabindex="-1"><li id="selFNF_chzn_o_0" class="disabled-result" style="">Produkt</li><li id="selFNF_chzn_o_1" class="active-result" style="">Fun</li><li id="selFNF_chzn_o_2" class="active-result" style="">Classic</li><li id="selFNF_chzn_o_3" class="active-result result-selected" style="">Comfort</li></ul></div></div> 
          </div> 

            <a class="btn-help" href="#" tabindex="-1" data-helpid="731"></a> 

          <div class="error-message"> 
           <span class="desktop">Bitte</span> Ergänzen Sie die Angaben 
          </div> 
         </div> 

第一個測試碼

browser.select_list(:class => 'chzn-done').select('Fun') 

第一個測試,輸出

Test Suite 
    New Test Case (FAILED - 1) 
    Failures: 
    1) Test Suite New Test Case 
    Failure/Error: browser.select_list(:class => 'chzn-done').select('FunNEU') 
    Selenium::WebDriver::Error::ElementNotVisibleError: 
    Element is not currently visible and so may not be interacted with 
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-     profile20140212-5829-7ai1pp/extensions/[email protected]/components/command_processor 

第二個測試碼

browser.select_list(:name => 'tx_bodpricecalculation_pi1[product]').select('Fun') 

第二個測試,OutputTest套房

Test Suite 
    New Test Case (FAILED - 1) 
    Failures: 
    1) Test Suite New Test Case 
    Failure/Error: browser.select_list(:name =>   'tx_bodpricecalculation_pi1[product]').select('FunNEU') 
    Selenium::WebDriver::Error::ElementNotVisibleError: 
    Element is not currently visible and so may not be interacted with 
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-  profile20140212-5829-  ry619a/extensions/[email protected]/components/command_processor.js:8179:in   `fxdriver.preconditions.visible' 
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-  profile20140212-5829-ry619a/extensions/[email protected]/components/command_processor.js:10814:in `DelayedCommand.prototype.checkPreconditions_' 

我得到了下面的測試根本就沒有去。 =>點擊PRODUKTNEU =>選擇FUNNEU

最後是發生,計算產品FUNNEU。只是部分和PRODUKTNEU和FUNNEU造成問題。

關於你的幫助,我將非常感激

+2

你能分享你嘗試什麼,你得到了錯誤? (這樣做可以節省給出/獲得答案的努力,而您已經知道這些答案是行不通的。) –

+0

我的Watir代碼和我的測試輸出在1答案 – mattrock

回答

1

這是在樣本HTML給出的選擇列表沒有的顯示風格。因此,它不被視爲可見。

您實際上想要與選擇列表之後的內容進行交互。 「下拉」實際上是一個鏈接,「選項」是實際的元素。

與實際頁面下面的工作:

require 'watir-webdriver' 

b = Watir::Browser.new 
b.goto 'http://www.bod.de/autoren/buch-veroeffentlichen/preiskalkulation.html' 

# This is the div containing the "dropdown" you want to work with. 
input_field = b.div(:class => 'product') 

# Click the link to expand the dropdown 
input_field.link(:class => 'chzn-single').click 

# Click the related li element 
input_field.li(:text => 'Fun').click 
+0

我再次更改了我的測試代碼。新錯誤仍然存​​在 – mattrock

+0

異常說明該元素當前不可見。在用戶看到選擇列表之前,用戶需要執行哪些操作? –

+0

用戶只需要點擊ProduktNEU以便選擇列表可見。鏈接=> [鏈接示例](http://www.bod.de/autoren/buch-veroeffentlichen/preiskalkulation.html) – mattrock