Modify image searching time globally

Hi

I’ve few scripts. Each of these scripts have commands like WaitFor, AnyImageFound etc, whereby these commands have a max timing value tied to them. For example,

WaitFor 8.0, Image1 -- try to look for Image1 within 8s
if AnyImageFound (5.0, Image2) then...end if -- try to look for Image2 within 5s

I’m thinking of a way to control the maximum image searching time globally. Meaning, I am hoping to have a way to edit max time specified in commands like WaitFor, ImageFound etc, without the need to hand-edit every occurence of this value.

I can think of a way to do this, which is to write the scripts like this:

WaitFor MaxTime, Image1 
if AnyImageFound (MaxTime, Image2) then...end if 

And, I will have another master script to control the value of MaxTime. This master script will first set MaxTime, then call the rest of the sub-scripts. This will ensure that the same MaxTime value can be propagated to all the occurences of MaxTime, used in WaitFor and ImageFound commands.

-- In master script,
set MaxTime = "8.0"
-- Run sub-scripts here

I know this approach will be working fine. I just need to replace the timing value in WaitFor and ImageFound in all of my scripts…I am just thinking whether there is a way to reset this max image search time in Eggplant?

I understand that there is an Eggplant option: ImageSearchTime that we can set to control the least amount of time Eggplant spends seasching for an image. I’d like to know how is this ImageSearchTime affects the max time value set in WaitFor command. Consider example below:

put getOption (ImageSearchTime) into IST
set the ImageSearchTime to 10.0
WaitFor 8.0, Image1
setOption ImageSearchTime, IST

In the above example, I scripted the WaitFor command to spend at most 8.0s to look for Image1. But, at the same time, the global property ImageSearchTime is set to 10. How is the WaitFor command going to behave? Should WaitFor at least spends 10s to search for Image1? Or, WaitFor will return an error status if it failed to find Image1 within 8.0s?

I’m wondering whether this ImageSearchTime is used to specifically cater for commands without timing value attached to them. For example, Click, DoubleClick etc.

Please advice on the best approach to modify the maximum image search time globally, with the minimum changes to existing test scripts. Thanks.

regards
Ai Choo

Hello Ai Choo,

There isn’t a setting that will adjust the maximum time globally. You can certainly do what you want with a MaxTime variable as you suggested, but you’ll need to declare it as a global variable for the value to be accessible across multiple scripts.

So, in your master script:

global MaxTime
set MaxTime = 8.0

Then wherever you want to use the global maximum:

WaitFor global MaxTime, Image1
if ImageFound (global MaxTime, Image2) then ... end if

By specifying “global” before each use of MaxTime like this, you avoid having to declare MaxTime as global at the beginning of each script, which will make it easier to update your existing scripts. You’ll need to do a search and replace of specific values in your scripts to replace something like “WaitFor 8.0” with “WaitFor global MaxTime”.

You can use our example script to Find and Replace Text in Multiple Scripts to make these changes across an entire suite (or several suites) at once. But you’ll have to do this for every command and function variation that you have which you want to change.

I hope that helps answer your question on the practical side.

As far as how the different timing parameters interact, it works basically like this:

When Eggplant looks for an image, it searches the entire screen (or the area defined by The SearchRectangle) for the image. If the image is NOT FOUND, Eggplant waits the length of time specified by The ImageSearchDelay, then tries again. It does this until it has searched The ImageSearchCount times. The ImageSearchTime is made up of these two values (click the disclosure triangle next to Image Search Time in Preferences -> Run Options -> Screen to see the relationship between these 3 values – changing any one of these values will change at least one of the others).

In operations that include a maximum search time (like the WaitFor command and the ImageFound function), the entire search process as outlined above is repeated until the the image is found or the maximum time is reached. Once the maximum time is reached, the process described above will be aborted early (between searches) before the ImageSearchCount has been reached.

It’s a bit complex internally (and also involves a full screen update before the last search of each group), but most of the time you can just use it and don’t need to worry about exactly how it all works. In certain situations it’s helpful to understand the internal workings, though, so I hope this description makes it clear. :slight_smile:

I tried to follow the link given to download the Find/Replace scripts, but it said that:

The selected Attachment does not exist anymore
404 File Not Found: The File files/findinscripts.suite.zip does not exist.

Can you suggest me another place to get the Find/Replace scripts?

Thanks
Ai Choo

The link has been repaired, sorry for the inconvenience.