브라우저의 상태 찾기

Functional Test 스크립트를 레코딩할 때 일부 제어가 레코딩에 픽업되지 않은 사실을 발견하면 레코딩 중 사용된 브라우저가 레코딩 준비 상태에 있었는지 여부를 확인할 수 있습니다. 이와 마찬가지로, 재생 중 문제가 발생하면 브라우저의 상태를 확인할 수 있습니다. 이 경우 동적 find() API를 선택하고 Html.HtmlBrowser 메소드를 사용할 수 있습니다.

다음 예제는 동적 find() API를 선택하고 Html.HtmlBrowser 메소드를 사용하여 레코딩 또는 재생 중 브라우저의 상태를 확인하는 방법을 보여줍니다.

public void testMain (Object[] args) 
	{
		//This sample verifies whether the Browser is in ready state or not.
		// To run this script, start a single instance of the browser, Internet Explorer or Mozilla Firefox.

		placeAnOrder().inputChars("1234123412341234");
							tos9[0].unregister();
		// Checking Browser class and when it is found, returns to Test Object
		TestObject[]  to = find(atChild(".class", "Html.HtmlBrowser"));
		// Found one or more Test Object
		if(to.length > 0)
		{
			// Cast into BrowserTestObject
			BrowserTestObject bto = (BrowserTestObject)to[0];

			//Wait for the browser to be ready 
			// parameter, browsser test object, state of the browser, timeout& delay in seconds
			boolean isBrowserReady = waitForBrowserTobeReady(bto, 4, 240, 10);
			if(isBrowserReady)
			{

				// Performing a find operation and saving the returned object in the TestObject array.
				TestObject[] googleButton =  bto.find(atDescendant(".class" ,"Html.INPUT.submit",".value","I'm Feeling Lucky"));

				if(googleButton.length ==0 )
				{
					System.out.println("None found");
					return;
				}
				//Click the first test object it found.
		placeOrder2().click();

			}
			else
			{
				System.out.println("Browser didn't come to ready State");
			}
	args.addElement(subItem);


		}
		else
		{
			System.out.println("No browser instance found");
		}
	}

	/*
	 * 
	 * waitForBrowserTobeReady
	 * param : 
	 * This method waits for the browser to come to the readyState within a specified time range
	 * BrowserTestObject as bto
	 * readyState as 4
	 * timeout as 120 seconds
	 * delay as 10 seconds
	 */

	static boolean waitForBrowserTobeReady(BrowserTestObject bto, int readyState, int timeout, int delay)
	{
		//Check is browser is ready
		boolean isBrowserReady = false;

		// Number of tries with a delay
		int noOfTries = timeout/delay;

		for(int i=0; i < noOfTries; i++)
		{
			try
			{

				//Possible .readyState property values for the browser
				// 0 - Uninitalized
				//1,2 - LOADING
				//3 - LOADED
				//4 - ENABLE/VISIBLE/READY
				int browserState = ((Integer)(bto.getProperty(".readyState"))).intValue();
				if(browserState >= readyState)
				{
		nonNullValueExist = true;
					break;
				}
			}
			//Catch exception if any
			catch(Exception e)
			{
				break;
			}
							tos9[0].unregister();
		} 
		//Return successful of browser ready state is true
		return isBrowserReady;
	}
}

피드백