Reputation: 2024
I'm testing an internal website built on the Magento storefront. During the checkout process, certain parts of the form are hidden (style: none) until the previous section is filled out. These parts would normally break the script, but using when_present for the first element of the hidden form resolved this issue.
The Submit Order button, however, is not working well with these same methods. I worked with our lead developer today to verify that the only difference between this button and the previous form buttons is that a new page is loaded (new URL, new "done" status in the browser).
To be crystal clear:
Here is the somewhat-pseudo code for the form, and the Submit click:
def complete_form(data = {})
data = DEFAULT_DATA.merge (data)
select_guest
continue_button.click #proceed to billing panel
enter_billing_and_shipping_info(data)
enter_additional_information(data)
place_order_button.when_present.click #submit form
#sleep 2 #this succeeds, but is undesirable
thank_you_message.wait_until_present #I do not actually appear to wait until anything is present
end #
def enter_billing_and_shipping_info(data)
billing_first_name.when_present.value = data['First Name'] #I work!
billing_last_name.value = data['Last Name']
#more fields
end #
From Steps:
thank_you_message.should include("Yippee")
The script fails in two different ways depending on how quickly the site is responding:
Other methods such as Watir::Wait.until, or until {} do, resulted in the same behavior.
Update 8-15 Attempted solution #1:
place_order_button.when_present.click #complete form
ajax_submit_image.wait_while_present
Same end result - script terminates with no success message found, screenshot shows the Ajax loading image mid-spin. Both this and the previous method SHOULD work, but seem to have no effect. I did verify that I can access the image using the locators in the script (img src match).
Upvotes: 1
Views: 2626
Reputation: 410
one option worth considering is requesting a testability feature of a flag in the application itself that lets you know if an asynchronous process is running. In one AJAX-heavy web app I tested, whenever an XRH or timer kicked off, we set an attribute on the body tag like AjaxStarted and the final thing any XHR or timer would do was set that attribute to AjaxStopped. That way, in any context (even where there might be multiple asynchronous processes underway, I had one easy method to call to see if I should move on or not.
You can read details of what we did and some other solutions we tried here: http://testingjeff.wordpress.com/2009/10/21/relief-for-the-pain-of-waiting-for-ajax-elements-on-the-page/
Upvotes: 1
Reputation: 6660
Have you considered using the presence of the 'loading animation' (which might just be an animated gif or similar) as a way to know you should keep waiting?
I've used that means in some of my scripts where the animation was just a simple graphic file that was being made visible or not by client side javascript. So my wait loop consisted of a brief sleep, and checking to see if the animation was still present, exiting once it had gone away.
Upvotes: 2