[eggPlant Functional] Recovering from the Unexpected

We've heard from some of our users that occasionally they have trouble with alert panels that may pop up at unexpected times during the execution of their script.

If a dialog can truly come up at any time and interfere with the test, that makes it awkward. The simplest solution is to turn off whatever is causing the dialog to pop up, before you start your test. But if that isn't possible, here's an approach that may help:

This solution involves overriding the Click command and other similar commands, as shown here:
on click
	-- check the version, since this won't work with earlier releases
	if eggplantVersion() < 1.41 then pass click 
	try
		-- the next line will pass the click message along to
		-- Eggplant, but allow us to catch any error
		pass click and continue
	catch
		-- The click failed. Check to see if an intermittent 
		-- popup is the problem, and deal with it.
		logWarning "Click failed -- attempting to recover"
		-- note: if an exception is thrown at this point, we won't catch it
		send dealWithInterruption to the target
		pass click -- having dealt with the popup, try our click again
	end try
end click

Put this click handler in a script along with similar handlers to override the DoubleClick, RightClick, WaitFor, etc. commands (whichever ones are being used that may throw an exception when they fail to find an image) and save this script in a helper suite. If, for example, you name the script "PopupOverrides.script", then in your main script, you would just need to include the following command:
start using "PopupOverrides"

Then, you will need to provide an 'on dealWithInterruption' handler (which could also be in the PopupOverrides script, if you like) that contains whatever code is needed to look and see if a popup is on screen and dismiss it in whatever manner is appropriate, so that the main script will be able to resume.

The beauty of this particular approach is that by using SenseTalk's "pass ... and continue" command inside a "try" block, it is able to catch the error that is raised when an image is not found. It then sends a dealWithInterruption message to whatever script called Click to begin with ("the target" is the object the Click message was first sent to). Assuming the interference has now been cleared out of the way, it then passes the original Click message once more to allow Eggplant to carry out the originally intended click operation. (NOTE: The script checks that it is running with at least the 1.41 release of Eggplant, which fixed a problem with the 'pass ... and continue' command.)

While this won't solve every situation, in many cases it should give your script a chance to deal with whatever interruptions your dealWithInterruption handler can respond to, and enable the overridden commands (such as Click) to resume and keep your main script running.

Doug

Comments

  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Note: Beginning in Eggplant version 2.21, a built-in script called Omega13 was included with Eggplant. Omega13 implements a slightly more sophisticated version of the approach shown in this example. This makes it easy to add overrides for all of the built-in image-based commands by simply including the command "start using Omega13" in your script. Then just implement an AttemptRecovery handler (rather than DealWithInterruption as shown in this example) to check for and dismiss any dialog or other interruption.

    For more information on Omega13, just type "Omega13" in the Do box at the bottom of the Run window.
Sign In or Register to comment.