1

我正在向页面添加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 进行测试时遇到问题。当我尝试继续进入下一页时,测试失败并且当我检查我是否在下一页时出现 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(以及我的测试中的点击),那么无论测试通过什么用户都会继续。

4

1 回答 1

1

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

于 2015-10-25T00:44:03.813 回答