追蹤 AJAX 要求

您可以用兩種不同的方式來測試 AJAX 型應用程式:在對應的文件物件上,將「自動追蹤」選項設為 true,或將「自動追蹤」選項設為 false。 您可以將「自動追蹤」選項設為 true 來追蹤 AJAX 要求。
下列範例顯示如何使用 getAjaxPendingRequests 和 waitForAjaxCompletedRequests。 getAjaxPendingRequeststo 方法用來傳回在第一次 AjaxTraceOn 之後,在任何給定時間點的 AJAX 擱置要求數目。 waitForAjaxCompletedRequestsTo 方法用來等待完成指定的 AJAX 要求數目。 如果未指定引數,它會等待擱置要求數變成零。
註: 當擱置要求數變成零時,請務必關閉「自動追蹤」選項。
public class AjaxRequestExample extends AjaxRequestExampleHelper
{
	/**
	 * Script Name   : AjaxRequestExample
	 * Generated     : Apr 24, 2012 2:52:37 PM
	 * Description   : Functional Test Script
	 * Original Host : WinNT Version 5.1  Build 2600 (S)
	 * 
	 * @since  2012/04/24
	 * @author IBM
	 */
	public void testMain(Object[] args)
	{
		ajaxTraceTest();
	}
	
	public void ajaxTraceTest() {
		 startBrowser("Internet Explorer",
		"<AJAX related Web Application URL>");

		// When is set to true, turn the AJAX Request tracing facility to 'On' at the HTML document level.
		document_convertBuyTransferAnd().setAjaxTrace(true);

		// perform AJAX-related actions.
		text_xvalue().click(atPoint(72, 10));
		list_xfrom().click();
		list_xfrom().click(atText("EUR - Euro"));

		/*
		 * ++++++++++Use one of the following three functions:
     a) waitForAjaxPendingRequests() - Wait for all the pending request to be served.
     b) waitForAjaxPendingRequests(5) - Wait for the 5 pending request to come
     c) waitForAjaxCompletedRequests(3) - Wait for 3 completed AJAX requests
		 * 
		 * Just to illustrate we have used a,b and c - in the real use case we expect you to use any one of the function.
		 */

		// Wait until all pending requests are completed.
		document_convertBuyTransferAnd().waitForAjaxPendingRequests();

		// Number of allowed pending requests, otherwise throw AjaxTimeOutException on timeout
		document_convertBuyTransferAnd().waitForAjaxPendingRequests(5);

		// Wait until the specified count of AJAX requests are completed. Otherwise throw AjaxWaitTimeOutException on timeout.
		document_convertBuyTransferAnd().waitForAjaxCompletedRequests(1);

		// When is set to false, turn the AJAX Request tracing facility to off
		document_convertBuyTransferAnd().setAjaxTrace(false);

	}
}

意見