Working with the WaitFor command.

I have found some issues dealing with the WaitFor command that I would like to have addressed.

  1. Waitfor 30, “ImageFileHere”

If “ImageFileHere” is not found within 30 seconds, Eggplant ends the script. It would be helpful if there was a way to use WaitFor such that if the image is not found, the script can deal with it.

I am aware that the following would work"
Try
WaitFor 30, “ImageFileHere”
catch exception
Do this or that
end try

It seems reasonable to me, that there should be a way to use it more like"

If WaitFor 30, “ImageFileHere”
Do this
else
Do that
end if

However, the result of the WaitFor 30, “ImageFileHere” is the location of the found image, not a boolean that can be used for an if statement.

I think this could be written into a do statement, but that seems like a lot of work for something that should be as simple as writing the WaitFor command into a logic statement.

  1. There should be a way to Not a WaitFor command.

I have an image on the screen and I’m waiting for it to go away. To do this right now, I’m having to build a repeat loop until ImageFound(“ImageFileHere”) = false.

It seems like this could be functionalized by Eggplant in a logical command like the following:

WaitFor 30, not “ImageFileHere”

Yes, I have written a function that I can call to do just this, but I thought it would be neat if it were built into Eggplant for better readability of the code.

I have found the WaitFor command to be very useful in many areas, but it seems like these small changes could make the tool extensively more useful and shorten the code even further for more readability and function.

Thanks for all your comments, they have always been useful in the past.

The ImageFound command takes an optional time parameter as its first argument, so your first issue can be easily addressed with code like this:

if imageFound(30, "ImageFileHere") then
    -- do this
else
    -- do that
end if

The second one is really best addressed by the “repeat while imageFound()” construct:

repeat while imageFound()
    wait 1 -- this line is optional
end repeat

If you want to cover the case where the image doesn’t disappear after a given amount of time, you could do this:

repeat while imageFound()
    if repeatIndex() is 30 then
        logError "Image did not go away"
        -- take other actions as necessary
        exit repeat
    end if
    wait 1 -- this line is optional
end repeat

If you had a WaitForNot command (as I’m choosing to think of it) you’d have to do what you did with the WaitFor command in your first example in order to address the case where the image doesn’t go away, so you’re not gaining much. In addition, as you’ve noted, the WaitFor command has the useful feature of returning the location of the image – the WaitForNot would have nothing of value to return, so I think the function is better served by a handler that returns true or false as the ImageFound() function does.