Overriding the wait method

Here’s what I want to do.

I have wait and waitforall and waitforany calls all over my scripts. God only knows how many I have scattered all over my scripts.

Anyways I just realized that even though the times I have specified are quite conservative for a successful event to be recorded on most machines, there are still going to be some SUT’s that are going to be painfully slower or even a lot faster.

So based on the processor speed, I would like to weight the wait time into units rather than seconds. E.g. wait 10 would be less than 10 secs on a faster computer and more than 10 secs on a slower computer.

Instead of my having to specify a weight manually or create custom scripts which would mean having to change each and every instance of wait every time, is there a way for me to change the wait command itself?

If not that’s fine, I’ll just create some custom wait scripts that will add the weightage, but I’d rather just override the wait commands.

Hi, that’s a great question! Yes, you can do this. Here’s a sample script that shows how:

put "A"
set global waitAdjustment to 0.8
wait 1
put "b"
set global waitAdjustment to 3
wait 1
put "c"

to wait howLong
	send wait global waitAdjustment * howLong to SenseTalk
end wait

The “send” command is needed to prevent the wait handler from calling itself. Sending the wait message to SenseTalk targets it directly to the built-in implementation of wait.

The custom “to wait” handler can either go in the local script (as shown here) or in a library script that is added to the backScripts, such as by calling “start using”:

start using "myLibraryScript"

Then just set global waitAdjustment to 1 for normal timings, or higher or lower than 1 for slower or faster operation.

One reminder for everyone, though: we generally always recommend using WaitFor rather than Wait, since that allows the script to continue running as soon as an image is found rather than “dead waiting” for the full time. You can override WaitFor in a similar way to adjust its timing if you need to, although you shouldn’t ever need to make it faster since it already proceeds as soon as it sees what it’s waiting for.

I hope that helps!


Thanks… that sounds simple enough.

Does imagefound() work the same way?

If not how would I weight this?

I do realize that I can change this using the eggplant preferences option, but I need to decide on my wait time on a case by case basis, thanks to one very slow machine that I have to run my tests on.

Sorry I forgot to mention this earlier, but how does the override method look for waitfor, waitforany, and, waitforall, as they have extra parameters?

Does it look the same as it does for wait, or should I override it differently?

[quote=“bharathh”]Sorry I forgot to mention this earlier, but how does the override method look for waitfor, waitforany, and, waitforall, as they have extra parameters?

Does it look the same as it does for wait, or should I override it differently?[/quote]

Well that doesn’t work, as all these methods can take in more than one variable.

How would I write an override method for this? I can do it for the waitfor as it only expects one param in addition, but am at a loss to write a generic override function for the any and all methods.

Some help pls!

I really need this info to complete a time critical project.

Commands that take multiple parameters are similar to the single-parameter case, but because the number of parameters can vary, you’ll need to use the parameterList function and the “as parameters” option on the call. So your override will look something like this:

on waitFor
    put the parameterList into myParams
    multiply item 1 of myParams by global waitAdjustment
    send waitFor myParams as parameters to SenseTalk
end waitFor
    send waitFor myParams as parameters to SenseTalk 

Sensetalk is not able to understand this line.

Here is the error I get with it

Syntax Error at line 4: can’t understand “as” at or near character 133

You must not be running the latest version of Eggplant. The send command was enhanced to allow the use of “as parameters” in version 2.21. You’ll need that version or later in order to do this.

How do I get v2.21? Should I ask my manager if he has received an email about this?

Just click Download at the top of this page, then click the “download the latest Eggplant release” link.

Oh ok. Great!

Thanks for all the help. Much appreciated.