1

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:

  1. User enters name, address, email and clicks 'Continue' => JS "loading" animation spins while the General panel slides closed and the Shipping Method panel expands, all on the same page.
  2. User clicks 'Submit Order' => JS "loading" animation spins, when complete, the browser proceeds to /success/ (new page) with verifiable elements.
  3. If given enough time to complete (sleep statement), the test does pass.

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:

  1. fail with a message that the expected Thank You message was not found - a screenshot taken during the error shows the Checkout page, NOT the thank you page, with the "loading" animation displayed. (expected "Checkout" to include "Your order has been received")
  2. fail with the "Element not found in the cache" error - the screenshot in this case does display the Thank You page, containing the text we are looking for

Other methods such as Watir::Wait.until, or until {} do, resulted in the same behavior.

  • Windows 7 64-bit & Windows XP 32-bit
  • ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
  • cucumber (1.0.2)
  • rspec (1.3.2)
  • watir-webdriver (0.3.0)

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).

4

2 回答 2

2

您是否考虑过使用“加载动画”(可能只是动画 gif 或类似的动画)的存在来了解您应该继续等待?

我在我的一些脚本中使用了这种方法,其中动画只是一个简单的图形文件,客户端 JavaScript 是否可见或不可见。所以我的等待循环包括一个短暂的睡眠,并检查动画是否仍然存在,一旦它消失就退出。

于 2011-08-12T06:14:41.297 回答
1

一个值得考虑的选择是在应用程序本身中请求一个标志的可测试性功能,让您知道异步进程是否正在运行。在我测试的一个重 AJAX 的 Web 应用程序中,每当 XRH 或计时器启动时,我们都会在 body 标记上设置一个属性,例如 AjaxStarted,任何 XHR 或计时器要做的最后一件事就是将该属性设置为 AjaxStopped。这样,在任何情况下(即使可能有多个异步进程正在进行中,我都有一个简单的方法可以调用,看看我是否应该继续前进。

您可以阅读我们所做的详细信息以及我们在此处尝试的其他一些解决方案:http: //testingjeff.wordpress.com/2009/10/21/relief-for-the-pain-of-waiting-for-ajax-elements-页面上/

于 2011-08-12T17:28:21.243 回答