• Support
  • Articles
  • Resources
  • Products

Test Framework

Moderator: boris

2 postsPage 1 of 1

IshmaelCallMe
Guru

Posts:
670
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Mon Feb 11, 2008 5:11 pm
This was in another category, but I think it belongs here more.

Here are some simple macros that allow a script to continue or stop if a failure occurs.

In swait.ttl:

Code: Select all

wait waitstr
if result=0 include 'errout.ttl'
exit


In errout.ttl:

Code: Select all

strcompare param3 ''
if result=0 then      ;param3 is used to give a general error message
   param3='Did not find expected string = '
   strconcat param3 waitstr
endif
logwrite #13#10'<error_message>'
logwrite param3
logwrite '</error_message>'#13#10
logwrite #13#10'<result>FAIL</result>'#13#10
boardfail=1
msg=param3
param3=''
msg1=msg
strconcat msg1 #13#10'Continue Anyway?'
yesnobox msg1 'ERROR'
if result=1 exit
end


To use in your main script:

Code: Select all

boardfail=0
timeout=2
sendln 'something or other'
waitstr='something_else'
include 'swait.ttl'
sendln 'something2'
waitstr='something_else2'
include 'swait.ttl'
sendln 'something3'
wait '1' '2' '3'
if result=0 then
  param3='Didnt get 1 2 or 3'
  include 'errout.ttl'
endif
if boardfail=0 msg='PASSED'
if boardfail=1 msg='FAILED'
messagebox msg 'Click OK'
closett
end


Note that pressing 'yes' to 'continue anyway?' at any time will mean the script will continue, but the end result will be a 'FAILED'. Pressing no will stop the script. Failure is logged in either case. This gives a good framework for tests.
IshmaelCallMe
Guru

Posts:
670
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Fri Jul 25, 2014 5:58 pm
Here is a somewhat more polished version that includes auto logging. This version you just append this text to your existing script and use call instead of include:

Code: Select all

  1.  
  2.  
  3.  
  4. ;********************* Common test utilities V2 by Brian Rose ****************************
  5. :swait
  6. wait waitstr
  7. if result=0 call errout
  8. return
  9.  
  10. :errout
  11. ifdefined param9
  12. if result=0 param9=''
  13. strcompare param9 ''
  14. if result=0 then      ;param9 is used to give a general error message
  15.    param9='Did not find expected string = '
  16.    strconcat param9 waitstr
  17. endif
  18. logwrite #13#10'<error_message>'
  19. logwrite param9
  20. logwrite '</error_message>'#13#10
  21. logwrite #13#10'<result>FAIL</result>'#13#10
  22. boardfail=boardfail+1
  23. msg=param9
  24. param9=''
  25. msg1=msg
  26. strconcat msg1 #13#10'Continue Anyway?'
  27. gethostname hostname
  28. sprintf2 tmp '%s ERROR' hostname
  29. yesnobox msg1 tmp
  30. if result=0 exit
  31. ;flushrecv  ;put this in, and expected output after what was not found will also not be found
  32. return
  33.  
  34. :prelude
  35. exec 'C:\Program Files\TT_Scripts\tt_window_pos.exe'    ;positions macro windows inside appropriate tterm window
  36. boardfail=0     ;This is the global variable that gets set to the number of errors encountered
  37. timeout=20      ;Determines how long commands that wait for host responses will wait
  38. testlink
  39. if result=0 connect '/C=999'        ;open a temp connection so logging can start
  40. logclose ;loginfo logfile   
  41. ;if result=-1 then   ;put some stuff in here to start new log if not a primary login log file and not currently logging
  42.     getenv 'USERNAME' username
  43.     gettime timestr "%Y%m%d-%H%M%S"
  44.     gethostname hostname
  45.     gettitle title
  46.     sprintf2 filenamedir 'C:\Documents and Settings\%s\desktop\TT_logs' username
  47.     filesearch filenamedir
  48.     if result=1 then
  49.        foldersearch filenamedir
  50.        if result=0 then
  51.           sprintf2 msg '%s is a file, not a folder.  Delete or rename it.  Exiting.' filenamedir
  52.           sprintf2 tmp '%s ERROR' hostname
  53.           messagebox msg tmp
  54.           exit
  55.         endif
  56.     else
  57.         foldercreate filenamedir
  58.     endif
  59.     sprintf2 filename '%s\%s-%s-%s-%s.log' filenamedir param1 title hostname timestr
  60.     logopen filename 0 0
  61.     showtt 6    ;Hide the log window
  62. ;endif
  63. return
  64.  
  65. :postlude
  66. if boardfail=0 msg='    PASSED      '
  67. if boardfail<>0 sprintf2 msg 'FAILED with %d Errors' boardfail
  68. sprintf2 tmp '%s Click OK' hostname
  69. messagebox msg tmp
  70. end
  71.  
  72.  
Display posts from previous:
Sort by:

2 postsPage 1 of 1

Users browsing this forum: No registered users
cron