2015-04-16 11 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