2015-04-16 10 views
1

我正在將sweetalert添加到頁面的過程中,以便如果客戶忘記上傳文件,則在點擊繼續按鈕之前用sweetalert加熱它們繼續到下一頁。SweetAlert Javascript插件可阻止水豚在測試過程中繼續到下一頁

按鈕的html:

<a href="/checkout/address" class="checkout-now continue-to-checkout">Checkout Now &gt;</a> 

單擊處理的javascript:

$(HtmlIds.cart.checkoutBtn).click(function(e) { 
      if ($(HtmlIds.cart.missingUploadsTag).length !== 0) { 
       e.preventDefault(); 
       var linkURL = $(this).attr("href"); 
       SweetAlert({ 
       title: "Missing Uploads", 
       text: "Your print job(s) are missing file uploads, which will cause a delay in the production of your order. " + 
        "To upload a file to a print job, please click on the 'Update Files' links in your shopping cart.", 
       type: 'warning', 
       showCancelButton: true, 
       confirmButtonColor: "#DD6B55", 
       confirmButtonText: "I understand, proceed anyway" 
       }, function(isConfirm) { 
        if (isConfirm) 
        window.location.href = linkURL; 
       }); 
      } 
      }); 

的代碼工作正常。但是,我遇到了通過rspec和水豚測試的問題。當我嘗試進入下一頁時,測試失敗,並且當我檢查下一頁上的im時是否出現水豚/ poltergeist錯誤。

RSpec的/水豚測試代碼:

click_link "Checkout Now" 
find(".sweet-alert").should have_content("Missing Uploads") #wait until sweet alert pops up 
click_button "I understand, proceed anyway" 
#page.execute_script('$(".confirm").click()') 
page.should have_content("Checkout: Delivery") 

錯誤消息:

2) checkout should be able to go through checkout via shipping 
    Failure/Error: page.should have_content("Checkout: Delivery") 
     expected #has_content?("Checkout: Delivery") to return true, got false 

水豚似乎當我使用click_button註冊點擊,因爲它不報錯了說的按鈕不存在,但它永遠不會繼續到下一頁。註釋掉的強制jquery代碼也不起作用。如果我從我的代碼中刪除sweetalert(並在我的測試中單擊),這樣無論測試通過了什麼,用戶都可以繼續。

+0

如果在have_content期望之前添加「睡眠10」,會發生什麼情況。它通過了嗎? – Phil

+0

@Phil我只是試過。仍然失敗'page.should have_content(「Checkout:Delivery」)' – Zyren

+0

只是一個猜測:也許'$(HtmlIds.cart.missingUploadsTag).length'爲零?這會阻止SweetAlert代碼執行。 –

回答

1

如果使用poltergeist,請使用.trigger(「click」)而不是click或click_button。 poltergeist中存在一個bug,click和click_button不會給出一致的結果(似乎是元素正在進行動畫處理時)。 Poltergeist issue on github