SweetAlert Javascript 插件阻止水豚在测试期间继续到下一页

SweetAlert Javascript plugin preventing Capybara from continuing to next page during tests

我正在将 sweetalert 添加到页面,这样如果客户忘记上传文件,当他们在继续到下一页之前单击继续按钮时,它会用 sweetalert 提醒他们。

按钮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 和水豚进行测试时遇到问题。当我尝试继续进入下一页时,测试失败并且当我检查我是否在下一页时出现 capybara/poltergeist 错误。

rspec/capybara 测试代码:

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 时,Capybara 似乎注册了点击,因为它不会错误地指出该按钮不存在,但它永远不会继续到下一页。被注释掉的强制 jquery 代码也不起作用。如果我从我的代码中删除 sweetalert(以及我的测试中的点击),那么无论测试通过什么,用户都会继续。

如果使用 poltergeist,请使用 .trigger("click") 而不是单击或 click_button。 poltergeist 中有一个错误,点击和 click_button 没有给出一致的结果(似乎是在元素进行动画时)。 Poltergeist issue on github