I know this option doesn’t exist in eggplant and I’ve looked around the help file and this forum - but is there any alternative to doing something where if a specific image is not found, then run a command?
Any help would be great. Thanks!
I know this option doesn’t exist in eggplant and I’ve looked around the help file and this forum - but is there any alternative to doing something where if a specific image is not found, then run a command?
Any help would be great. Thanks!
It’s a pretty common operation to write something like this
if not imageFound("MyImage") then
"do some stuff"
end if
I’m not sure what you mean by “run a command”. But the stuff can certainly include calling shell() to invoke a process on the local system OR a series of operations on the SUT. Let us know if you are looking for more than that.
Yup. Don’t forget the “not” keyword. (or the other operators–equals, is equal to, is not equal to, contains, begins with, ends with)
I was able to condense this into a handler (at least the reverse, anyway…), to save the trouple of writing a bunch of duplicate code:
to safely action, image
if imageFound(image)
put action&&foundImageLocation() into command
do command
exit handler
end if
throw "No Image Found"
end safely
To call it:
safely "click", "myImage"
This works most of the time. It wouldn’t be all that hard to extend this to check that an image is not there…
I think that answers it. Will be messing around with that - sorry for the n00biness.
Thank you!
Oh, noob - I think this does exist. Don’t assume too much and stay with the question
A couple more options:
try
if imageFound(image)
doSomething
end if
catch
– look for application menu, and control (PC) command (Mac) + Tab
– apply image filter
– put shell(“some unix command on my machine that’ll help SUT machine”) into SUThelpResults
– other clever things…
end try
You have lots of options.
v
There are a lot of good suggestions here for different ways of approaching the problem!
To make sure everyone has a clear understanding I want to point out that commands like Click will throw an exception if the image isn’t found on the SUT, but the ImageFound() function normally just returns true or false to indicate whether the image was found or not, and doesn’t throw an exception. It only throws an exception if you pass it an invalid image name (for an image that doesn’t exist in your Images folder) or that sort of thing.
So most of the time it probably makes sense to use either a try/catch block around a command like Click, or else to use the ImageFound() function, but you may not need to use both together.
Just thought I’d follow up. You guys’ suggestions worked. Thank you