Reputation: 663
I am in the process of adding sweetalert to a page so that if a customer forgot to upload files, it would warm them with sweetalert when they clicked on the continue button before continuing to the next page.
button html:
<a href="/checkout/address" class="checkout-now continue-to-checkout">Checkout Now ></a>
click handler 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;
});
}
});
The code works fine. However, i am having a problem with testing via rspec and capybara. When i try to proceed to get to the next page, the test fails and capybara/poltergeist errors out when i check to see if im on the next page.
rspec/capybara test code:
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")
error message:
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
Capybara seems to register the click when i use click_button because it doesn't error out saying the button doesn't exist, but it never continues to the next page. The forced jquery code thats commented out doesnt work either. If i remove the sweetalert from my code (and the click in my test) so the user continues no matter what the test passes.
Upvotes: 1
Views: 562
Reputation: 663
If using poltergeist, use .trigger("click") instead of click or click_button. There is a bug in poltergeist where click and click_button does not give consistent results (seems to be when elements are undergoing animations). Poltergeist issue on github
Upvotes: 1