Find out more about eggPlant

Forum IndexForum Index
Forums FAQForums FAQ
Search ForumsSearch Forums
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
Your ProfileYour Profile
Log inLog in
Useful SenseTalk Functions
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic   Printer-Friendly View    Forum Index -> Eggplant Examples
View previous topic :: View next topic  
Author Message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Fri Apr 11, 2008 10:22 am
Post subject: RE: Resting and Relaxing on a Friday
Reply with quote

A little fun here today, its Friday after all.

10.5.x Leopard has a much improved and understandable Text-To-Speech system and a new voice called Alex. Alex can and will say stupid (and useful) things to you and others if you just command it. If you dare, man page the 'say' command in the Terminal/iTerm.app vt100 environment.

Here we have a not so big challenge, announcing the time and suggesting doing something else for a bit is a good thing for those of us that sit at the computer far far far too long at spells. With the healthy problems computer professionals have, RSS, pooling of blood in the extremities (particularly the legs), shoulder problems and even eye strain issues this little ditty does the job well to remind me to shower Smile. I laugh, and think about how it is a good thing its just a computer telling me to take a rest and not some nagging impotent boss from "The Office" or "The Drew Carey Show".

Code:
get the time

if the hour is zero then  -- announce for first hour of day what day it is.
 shell "say Today is " & the long date
 put "00" into chars 1 to 2 of it  -- correct a bug with say command
end if

shell "say The" && \
  any item in ( "bleeping", "freaking", "", "darn", "lovely" ) && \
  "time is" && it && \
  any item in ( ", so", ", " ) && \
  any item in ( "wake up", "make a change" ) && \
  any item in ( "and", "or", "exclusively or", "in a boolean fashion and" ) && \
  any item in ("possibly", "maybe", "definitely") && \
  " you" && \
  any item in ("should", "would", "could") && \
  any item in ( "think about", "contemplate, to consider, to evaluate, to decide on", "deciding on" ) && \
  any item in ( "taking", "doing", "exiting and doing" ) && \
  any item in ( "a cup of" & \
  any item in ( "java", "coffee", "tea", "soda", "water" ), "a walk", "some sleep", "a bit of rest", "a" && \
  any item in ( "hot", "cold", "warm", "boiling", "freezing", "" ) && \
  "shower", "dinner", "lunch", "breakfast", "a meal" )


You could include this in an .st or .script file, and direct either your embedded ST application to run it, or even talk to Thoughtful Software (http://www.thougthful.com) about other means of executing SenseTalk (http://www.sensetalk.com) scripts from the CLI. I run it as an .st script, and let Cronnix (http://www.abstracture.de/projects-en/cronnix) do the scheduling.

Either way this is a good and fun way to remind us that we need to take a few mins every 30 to 60 mins and stretch and exercise something other than our brains.

Try this on for size:
Code:
shell "say super calla fragia listic expee alla docious"


And finally you can leverage all this for announcements that change due to failures or success in your scripts and environment.

Code:
try to do Something
sayRunStatus the exception

try to do "Something(goAheadAndFail)"
sayRunStatus the exception

to sayRunStatus  e
 if e.name is empty then
  shell "say" && "SUCCESS, your scripts works fine!"
 else
  Log  e.name && "-" && e.reason
  shell "say" && "Uh oh, you have encountered a problem."
  shell "say The Exception information follows"
  wait 1 second
  shell "say" && e.name && e.reason
 end if
end sayRunStatus

to something  trigger  -- do nothing but throw an exception
 if trigger is not empty then
  Throw "Some Type of Exception", \
    "Please place exception information here, which should be detailed."
 end if
 return "goodness"
end something


Enjoy, and have a great time with your SenseTalk'ing (literally)
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Fri Apr 11, 2008 3:11 pm
Post subject: RE: Random Thoughts on Filenames and Directories
Reply with quote

I do all kinds of stuff generating temp files instead of using dynamic variable creation. These serve purposes like storing intermediate variable or conditions/results that I want to track. This can be done with Log, LogWarning or even LogError and exception handling... However, often my needs are for template files that will be merged later (being generated programmatically rather than statically). This leads to the need of temporary file names and generating those names.

Once again, a simple but powerful solution is presented. You'll notice also a clean and simple comment header that should be employed whenever you are moving scripts and handlers into your libraries. These headers are not only a best practice in software engineering, but also in automation and functional programming/scripting. You can use the Doug Simons radioactive EggDoc to run against this which will generate a nice clean html file for your documentation efforts, you are doing documentation of your 'agile' efforts I hope.

Code:
(**
  Returns a unique file name that is almost uarenteed not exist.
  Will try up to 10000 times to create a filename that is unique
  with a large spread of 90 million possibilities.  Chances of this
  routine not creating a unique file name are very remote

@param  dir     optional directory, defaults to "/tmp/"
@param  prefix  the front, defaults to "TempFile"
@param  suffix  end which is often left empty.
@param  ext     the file name extension, defaults to empty.
@returns        a unique full path name
**)

params  dir, prefix, suffix, ext

set numOfAttempts to 10000
set defaultDir to "/tmp/"

if there is not a folder dir then
 LogWarning  "Passed parameter 'dir' invalid, passed as '" & \
   dir & "'... doesn't exist."
 set dir to defaultDir
 LogWarning "The parameter is now defaulted to '" & dir & "'"
else if dir is empty then
 set dir to "/tmp/"
end if

if last char of dir is not "/" then put "/" after dir
if prefix is empty then set prefix to "TempFile"
if ext is not empty and first char of ext is not "." then \
  set ext to "." & ext

repeat numOfAttempts times
 set path to dir & prefix & \
   random(10000000, 99999999) & suffix & ext
 if there is not a file path then return path -- exit when unique
end repeat

-- as a last resort, we'll toss an exception if we are unable
-- to generate a unique filename numOfAttempts times
Throw  "Unique File Name Creation Exception", \
  "Was not able to create a file name that was unique trying" && \
  numOfAttempts && "times."


Some example calls to this and returned values follow...

Code:
put UniqueFileName("/tmp")
/tmp/TempFile78212738
put UniqueFileName("/tmp")
/tmp/TempFile61775655
put UniqueFileName("/tmp", Todd)
/tmp/Todd26460678
put UniqueFileName("/tmp", Todd, Nathan)
/tmp/Todd18014018Nathan
put UniqueFileName("/tmp", Todd, Nathan, abc123)
/tmp/Todd24873800Nathan.abc123
put UniqueFileName("/tmp", , , rtf)
/tmp/TempFile52695153.rtf


And of course for those folks that want to use the underpinnings of the hosting operating system, in my case currently OS X, you can use the 'secure' means of mkdir and mktmp using the bash shell $RANDOM generator. To read more on this, you can turn to http://wooledge.org:8000/BashFAQ/062 which has a terse but good example set.

You could easily make the above SenseTalk handler deal with a unique folder name generated by changing the

Code:
if there is not a file path then


to the equivalent for a folder

Code:
if there is not a folder path then


and that effort to make it work is left up to the astute SenseTalker. Good luck, and happy scripting.

And of course a final note. If you want to avoid looping for uniqueness you could also use milliseconds, or a date-time combination to stamp each file as unique. This technique works close to 100% of the time since time is a continuum which if using small enough time stamp increments (as in milliseconds) you will not likely have a single command execute in less than that time to execute in SenseTalk (at least not until we get to 20-30Ghz mega count core computers, and we'll worry about that later.)
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Thu May 08, 2008 7:58 pm
Post subject: Testing ways to best write scripts... Leveraging Yur Assets
Reply with quote

Just for fun exercise today. I was reading along on metrics in C++ and C for hysterically historic meloncholic reasons today. And what did I find in the SQE PowerPass access (www.sqe.com) area a little article on the right way to handle checking for items in a iterator before iterating over the iterator (what a mouthful). I found this almost self folding, solving itself as stated which is often a hint of unnecessary complexity.

For our example, lets start with some variable setting for the simple elapsed time testing...

Code:
set aList to ()
set iterations to 10 ^ 5


Then we'll execute a simple repeat loop with some time wrapper script around it for reporting purposes.

Code:
set sTime to now  -- the really wrong way to do things.
repeat iterations times
   if the number of items in aList is not zero then
      repeat with each item in aList
         do somethingWonderful
      end repeat
   end if
end repeat
put "Elapsed Time: " & now - sTime


and then execute a simple repeat loop with some time wrapper code around it for reporting. What we find when we alter the object checking (either for existance, or contents of items, or emptiness) is significantly different timings. Some cases are useful to note...

Code:
set sTime to now  -- the possibly right way to do things.
repeat iterations times
   if aList is not an empty list then
      -- [[ ... loop removed for brevity ... ]]
   end if
end repeat
put "Elapsed Time: " & now - sTime && seconds


set sTime to now  -- the maybe right way to do things
repeat iterations times
   if aList is not () then
      -- [[ ... loop removed for brevity ... ]]
   end if
end repeat
put "Elapsed Time: " & now - sTime && seconds


set sTime to now  -- the right way to do things
repeat iterations times
   -- [[ ... loop removed for brevity ... ]]
end repeat
put "Elapsed Time: " & now - sTime && seconds


The point of this exercise is not to point out the flaws, weakeness or particular right or wrong way to do things... But more of a method of understanding your needs. In this case, we don't need to check for the object being empty or void of items at all, due to the nature of the repeat loop inherintly doing that for us by default. A loop over any chuck in a container which has non of those chunk types in it will result in the fastest execution with no checking for that chuck type at all.

Here are the numbers I got on an iMac with 4 gigs of RAM, 2.0 ghz system running SenseTalk in a hosted application called Eggplant. The numbers are clear on the winning approach.

Code:
Thu, 5/8/08 9:56:21 PM   START      Running BenchmarkContainerChecking.script
Elapsed Time: 6.357546 seconds
Elapsed Time: 5.063503 seconds
Elapsed Time: 2.60024 seconds
Elapsed Time: 0.5716 seconds
Thu, 5/8/08 9:56:35 PM   SUCCESS      Execution Time 0:00:14 BenchmarkContainerChecking.script


Experiment, write your own metric and timing scripts. Just like a master mechanic learns the tools and language of the trade, it is in your best interest to do the same. Read at least once a month the entire SenseTalk Reference Manual, there are so many tidbits of goodness tucked away in it that I still find fun to discover weekly.
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Wed May 14, 2008 7:44 pm
Post subject: Recursion Window Closure
Reply with quote

The need arose last week to click on all instances of a image element, as they become visible as a result of elements moving out of the way. The power of recursion (a technique where a function calls itself with possibly terminal values for call depth control) is what first came to mind. Many problems can be solved recursively.

Code:
params  image

if image is empty then set image to "close_window"
repeat with each loc in EveryImageLocation(image)
   Click  loc
end repeat

if ImageFound(1, image) then CloseAll

return


You also have to be careful that this can loop forever if the elements eventually don't go away from the screen. For intance, if you were to supply an image element of the zoom button on a window title bar, this loop would go forever until either the system ran out of memory and Eggplant or SenseTalk would exceed the default recursion count limit.

You can take a look at how to tweek the call depth limit in Eggplant.

http://www.redstonesoftware.com/phpBB2/viewtopic.php?p=1931
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Wed May 21, 2008 7:07 am
Post subject:
Reply with quote

Developing vocabulary in scripting system for automation is often part of what we all do, eventually establishing some standards in our organization to facilitate effective communications of ideas, quality and easy of maintainance of scripts. Externalizing script creation and management, decoupling if you will, is often part of the keyword driven approach in test automation.

Eggplant has build in functions and vocabs, which form the foundation to a much richer custom solution for any organization. In the search to describe a limiting search region, I have come up with a fairly flexible "LimitSearchTo regionName, additionalRegions" handler, with its own help/usage system (for you unix heads)...

Code:
properties
 help: "Usage: LimitSearchTo  [ Menus | Dashboard | Content | Help ], optionalProperties"
end properties

params  regionByName, optionalProperties

if regionByName is "help" then
 put my help
 return
end if

set regionProperties to ( "All": the remoteScreenRectangle, "Menus": Menus, "Dashboard": Dashboard, "Content": Content )
if optionalProperties is a property list then \
  add properties optionalProperties to regionProperties

if regionByName is in the keys of regionProperties then
 get regionProperties.(regionByName)
 if it is not a rectangle then get everyImageLocation(it)
 set the searchRectangle to it  -- should be two image locations
end if


Without belaboring the details, fundamentally this handler embraces a LOT of SenseTalk and objects. You have initial properties of which is a static help string property by name 'help'. This allows you to quickly ask the object/script for some help in using itself. This string is internalized, so if you change the script's behaviour you also will need to be in the habit of changing/updating both the help property and the EggDoc comments. I encourage as a standard in house to use EggDoc comments for automatic documentation creation along with test runs being part of your organizations build cycles (daily or more often).

You'll also notice this handler does some fun stuff with a mix of data types. We dynamically get the screen rectangle and use it for the "All" directive. We also make an assumption that the name of the region is a collection of 2 images likely with offsetting corners of a rectangle of interest. The optionalProperties also gives you the flexibility to add dynamically a list of regions with names or rectangles on the fly. This gives you the added power to expand your vocabulary dynamically as projects and practices demand. Nothing is static, so developing your scripts to be open ended with well defined behavior is a good idea in all your efforts.

Here is some demonstration script to drive validation of the LimitSearchTo handler:

Code:
-- Demonstrate vocabulary development...  Each 'region' is a two or more collection
-- of images, or a reference to a rectangle (within the LimitSearchTo handler itself)
set additionalRegions to ( region1: (1,2,3,4), region2: (4,5,6,7) )
repeat with each aRegionName in (( "Menus", "Dashboard", "Content", "All", "Help" ) \
  &&& the keys of additionalRegions )
 LimitSearchTo  aRegionName, additionalRegions
 if region is not in ( "All", "Help" ) then LimitSearchTo  All
end repeat


Please take this as a base for your own vocabulary development efforts, and comment about what you have found to be useful. Below is a run result output for the following exercise script for LimitSearchTo...

Code:
Wed, 5/21/08 8:51:34 AM   START      Running Selection from Sandbox.script
Wed, 5/21/08 8:51:34 AM   everyimagelocation   Menus   found 2 images
Wed, 5/21/08 8:51:34 AM   set      SEARCHRECTANGLE = ((5,245),(199,714))
Wed, 5/21/08 8:51:34 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:35 AM   everyimagelocation   Dashboard   found 2 images
Wed, 5/21/08 8:51:35 AM   set      SEARCHRECTANGLE = ((2,113),(1024,204))
Wed, 5/21/08 8:51:35 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:35 AM   everyimagelocation   Content   found 2 images
Wed, 5/21/08 8:51:35 AM   set      SEARCHRECTANGLE = ((201,206),(1020,713))
Wed, 5/21/08 8:51:35 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:35 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Usage: LimitSearchTo  [ Menus | Dashboard | Content | Help ], optionalProperties
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (1,2,3,4)
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (4,5,6,7)
Wed, 5/21/08 8:51:36 AM   set      SEARCHRECTANGLE = (0,0,1024,768)
Selection Executed in 0:00:02


I hope you have found this useful, please feel free to share in your own threads findings and ideas about your particular situation, needs, wants, practices and visions.



Vocabulary Building - LimitSearchTo.zip
 Description:
Download, unarchive, and read to learn more...

Download
 Filename:  Vocabulary Building - LimitSearchTo.zip
 Filesize:  129.79 KB
 Downloaded:  602 Time(s)

Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Tue May 27, 2008 4:33 pm
Post subject: Debugging strings, long descriptions help...
Reply with quote

While debugging some text streams I have been working on, I decided to make my life a bit easier in knowing what a particular character string contained. Remember what 09 is, or 10, or even 13 means... linefeed, newline, return (or did I get this wrong too) is a bit much to recall let along get correct. Instead you can use the handy charToDesc() handler to spit out the details of a string's character constituents.

Code:
put charsToDesc("Todd" & space & "was" & tab & "here!!!" & return)

Offset    Char  Oct     Dec     Hex     Cntrl   Description
       1: T   124   84   54   Uppercase T
       2: o   157   111   6f   Lowercase o
       3: d   144   100   64   Lowercase d
       4: d   144   100   64   Lowercase d
       5: SP   40   32   20   Space
       6: w   167   119   77   Lowercase w
       7: a   141   97   61   Lowercase a
       8: s   163   115   73   Lowercase s
       9: HT   11   9   9   ^I   Horizontal tab, move to next tab stop
      10: h   150   104   68   Lowercase h
      11: e   145   101   65   Lowercase e
      12: r   162   114   72   Lowercase r
      13: e   145   101   65   Lowercase e
      14: !   41   33   21   Exclamation mark
      15: !   41   33   21   Exclamation mark
      16: !   41   33   21   Exclamation mark
      17: LF   12   10   a   ^J   Line Feed


A bit of a warning is in order. If you feed this handler long strings, it will produce long results.

Code:
(** a long version of the numToChar() function.
Gives details of the characters (mostly designed for hidden chars,
but does deal with most of the ASCII table)
Most table data ripped/borrowed/lifted directly from
http://www.robelle.com/smugbook/ascii.html
Blame them for any errors or omissions.
**)

params  aString

get asciiTableDetails()

put "Offset    Char  Oct     Dec     Hex     Cntrl   Description"
repeat with each char aChar in aString
   set s to each line of ( lines 2 to -1 of it ) where word 3 of each is charToNum(aChar)
   write format("%8d: ", repeatIndex())
   if number of items in s is not 1 then put aChar
   else put item 1 of s
end repeat


(** assumed unique entries for each char in the list.
ASCII based, does not deal with UNICODE currently,
however you are welcome to expand and do this work yourself :) **)

to asciiTableDetails

   return <<Char>>)


Which would return to your script the bare essential text of the page in question. This can be very powerful for simple text search in a page result instead of wading thru a bunch of possibly troublesome tags in the result.

As a side note, yet marginally interesting to a technical historian, is the history of the ASCII character set with some tidbits of how it may be related to Morse Code (digital, or descrete signals). A good read while you are processing possibly large file sets with hidden characters and their meanings [NOTE: you may want to perform all this within SenseTalk containers instead of output to a Eggplant run window].

http://www.wps.com/projects/codes/index.html

And finally you may want to use the tried and true tool 'cat -vt' to help detect hidden unprintable characters. First 'put' the contents into a file path, and then issue 'cat -vt filepath', you can 'man cat' for more information on the CLI options to cat. The latter two steps would normally be done from a VT100 terminal window, of which Terminal.app comes with OSX. Another CLI tool that just rocks blocks, is iTerm.app (available online at

http://www.versiontracker.com/dyn/moreinfo/macosx/17484

Good luck and happy SenseTalkin' with ya!
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Tue Jun 03, 2008 10:49 am
Post subject: Search and Save; Result File Contents Summary
Reply with quote

Here you go, a quick and easy front end for searching a file for a string and placing the search results into a file, pasteboard, or into the run results window. Along with GUI and speed, this script remembers old used values between script runs, as well as being a tutorial on how to make life easy on yourself and others by scripting gently.

Code:
params  resultsPath, aStringToFind, saveToPath

universal  lastSearchStringEntered, lastSearchPath, lastSavePath

set tempFilePath to "/tmp/TempFile-" & the long seconds split by "." joined by ""

if resultsPath is empty or resultsPath is not a file then
 -- Get the file path to search
 if lastSearchPath is empty then set lastSearchPath to UserInfo().HomeDirectory
 answer file "Enter or select the results file path:" in folder lastSearchPath
 if it is in ( "Cancel", empty ) then exit all
 set resultsPath to it
 set lastSearchPath to the folder of resultsPath
end if

if aStringToFind is empty then
 -- Ask for the string to search for
 if lastSearchStringEntered is empty then set lastSearchStringEntered to "LogError"
 ask "Enter a string:" title "Find a substring" with lastSearchStringEntered
 if it is in ( "Cancel", empty ) then exit all
 set aStringToFind to it
 set lastSearchStringEntered to aStringToFind
end if

-- Request if user wants to save to file or pasteboard
answer "Save to Pasteboard or a File" with \
  "Pasteboard" or "File" or "Standard Out" title "A place for salvation..."
if it is in ( "Cancel", empty ) then exit all

set foundStuff to each line of file resultsPath where each contains aStringToFind
if saveToPath is empty or saveToPath is not a file then
 -- Either act on the File, or stuff it all into a pasteboard.
 if it is "File" then
  if lastSavePath is empty then set lastSavePath to UserInfo().HomeDirectory
  ask file "Where to save results" title "Save data to file" in folder lastSavePath
  if it is in ( "Cancel", empty ) then exit all
  put foundStuff into file it
  set lastSavePath to the folder of it
  open it with TextEdit  -- could put a open or not here???
 else if it is "Pasteboard" then
  put foundStuff into file tempFilePath
  shell "cat " & quote & tempFilePath & quote & " | pbcopy"
  delete file tempFilePath
 else
  put foundStuff
 end if
else
 put foundStuff into file saveToPath
end if


Most of this script is a wrapper around various parts of a simple need to get data from a file. In eccense there is one line that matters, where each contains aStringToFind Smile



SearchAndSave.script.zip
 Description:
Download, unzip, and drag and drop into your suite or EggplantCommons.suite.

Download
 Filename:  SearchAndSave.script.zip
 Filesize:  1.26 KB
 Downloaded:  589 Time(s)

Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Tue Jun 03, 2008 1:37 pm
Post subject: Connection Info, getting at the real ServerID (IP) value
Reply with quote

To help get the IP numbers of connections from Eggplant, here is a filter handler allowing quick and easy access to the same data with actual IP values for ServerID instead of the Name override property set to ServerID.

Code:
params  aFilter

set aList to an empty list
repeat with each connection in AllConnectionInfo()
 if ( each item in the values of connection where each contains aFilter ) is not () then
  set aNewConnection to an empty property list
  repeat with each key in the keys of connection
   set aNewConnection.(key) to QuoteString(connection.(key))
  end repeat
  insert aNewConnection into aList
 end if
end repeat

return  aList

to QuoteString  aString
 if char 1 of aString is not quote then put quote before aString
 if char -1 of aString is not quote then put quote after aString
 return  aString
end QuoteString
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Tue Jun 03, 2008 11:26 pm
Post subject: Valid IPv4 or IPv6 addresses
Reply with quote

Code:
-- See: http://www.trap17.com/index.php/ipv4-vs-ipv6_t24034.html
-- returns the IP if it is valid, or the items of a list of IPs that are valid.
-- A resonable filter/verification tool.

params   IPs...

repeat with each anIP in IPs by reference
   set validNumbers to each item delimited by "." of anIP where each is between 0 and 255
   get number of items in validNumbers
   if it is not in ( 4, 16 ) or it <> number of items delimited by "." in anIP then delete anIP
end repeat

return  IPs
Back to top
View user's profile Send private message
Todd
AuberGenie


Joined: 20 Jan 2007
Posts: 265

Posted: Mon Jun 09, 2008 7:37 pm
Post subject: The "ultimate" WaitForClick handler, or is it???
Reply with quote

Here is a revised WaitForClick handler that does what it implies by name. We first parse out the parameters which are delay, images... and an optional 'hidden' value which specifies the instance if provided by a positive number. As a convenience handler, this is a staple in my bag of SenseTalk tricks. Hope you find it as useful in your testing practices.

Code:
params  delay, images...

set instance to 1
get a reference to the last item of images
if it is a positive number then
 set instance to it
 delete it
end if

if delay is not a positive number then
 insert delay before images
 set delay to 30 seconds
end if

-- if an image, it will become a location...
repeat with each image in images
 if image is not a point then
  MoveTo  RemoteScreenSize()
  WaitFor  delay, image
  set imageLocations to EveryImageLocation(image)
  get number of items in imageLocations
  if instance > it then
   LogWarning "Setting image instance to be selected to the maximum number of images found (" & it & \
     "), you specified a larger number of images to be selected " & instance & "."
   set instance to it
  end if
  set image to item instance of imageLocations
 end if
 Click  Image
end repeat


I have so many version of WaitForClick, I'm not sure which is best or least likely to cause issues, however this one seems to be my favorite right now.



WaitForClick.script.zip
 Description:
Download, unzip, drag and drop into your EggplantCommon.suite or into a project suite

Download
 Filename:  WaitForClick.script.zip
 Filesize:  1.26 KB
 Downloaded:  586 Time(s)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   Printer-Friendly View    Forum Index -> Eggplant Examples All times are GMT - 8 Hours
Goto page Previous  1, 2, 3, 4, 5  Next
Page 4 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
 
TestPlant
©TestPlant Ltd 2009. All rights reserved.