conditional if images then and waits on a launch

I have a testing script that launches an app on a client.

If certain conditions are met in the database on the server different warning dialogs popup during the launch of the app, for example a warning dialog that that user is already logged on the database.

So it is like this:

WaitFor 100.0, "stopforchooser"
TypeText return
wait 15.0
if ImageFound("useralreadyonsystem")
then Click "useralreadyonsystem"
wait 25.0
if ImageFound ("tfnwarningclick")
then Click "tfnwarningclick"
wait 120.0
if ImageFound ("notasksscheduled")
then Click "notasksscheduled"
WaitFor 40.0, "blankphonecallerfields"

my question is:

Is the code above really the best way of doing this - I don’t think it is because the time of the waits will vary according to the speed of the client they are on. Right now the SUT is a clunker Pentium III and I don’t want to adjust all the waits of my scripts if I want to run it later with a faster SUT.

Please let me know,

Brad

First, I hadn’t realized the pent up demand for avatar support on the forums. :lol:

There are other ways of writing the routines that you posted. There’s no “right” way, but I’ll try to suggest a more efficient alternative. I almost never use Wait commands if I can avoid them; WaitFors provide a lot more flexibility and don’t slow script execution unnecessarily. What I’m going to suggest may look a little clunky, and it is, but it lets you use WaitFors, so if the image does appear, your script can continue more quickly.

WaitFor 100.0, "stopforchooser" 
TypeText return 

Try
waitFor 15.0,  "useralreadyonsystem"
click foundImageLocation()
Catch
-- do nothing here
End Try

Try
waitFor 25.0,  "tfnwarningclick"
click foundImageLocation()
Catch
-- do nothing here
End Try

Try
waitFor 120.0,  "notasksscheduled"
click foundImageLocation()
Catch
-- do nothing here
End Try

WaitFor 40.0, "blankphonecallerfields"

So what I’m doing here is using WaitFor as though I’m expecting each of these warnings to appear. But since the script will fail if a WaitFor fails, I’m wrapping them inside try…catch blocks. If the WaitFor fails, the “catch” intercepts the exception. Often you’ll want to do something in the catch block to log or handle the failure, but in this case we know the images might not appear and we just want the script to keep going. The “foundImageLocation()” function returns the coordinates at which the last image was found. If the WaitFors fail, then the execution will drop into the catch block and bypass the clicks.

That’s how you’d do it in Eggplant 1.42, but this is going to get a lot cleaner in the upcoming Eggplant 1.5 release. In Eggplant 1.5, we’ve added a time parameter to the imageFound() function, so the above can be rewritten as follows:

WaitFor 100.0, "stopforchooser" 
TypeText return 

if imageFound( 15, "useralreadyonsystem" ) then
click foundImageLocation()
end if

if imageFound( 25.0, "tfnwarningclick" ) then
click foundImageLocation()
end if

if imageFound( 120.0, "notasksscheduled" ) then
click foundImageLocation()
end if

WaitFor 40.0, "blankphonecallerfields"

Hope this makes sense to you. Let us know if you have any other questions.