Forum Discussion

Morgan's avatar
Morgan
Frequent Contributor
14 years ago

Event Handlers

Hello,



1)  I am working on a handler for OnLogError that stops script execution after a certain number of errors.  It doesn't appear to be working, though.  So far, I have this :



   Err.Clear

   

   On Error Resume Next

  

   If Err.Number > 3 Then

   Log.Message "Max number of errors reached - Test execution halted"

   Runner.Stop 

     End If



Any ideas?



2)  Secondly, I was wondering if it was possible to create a script that (on region checkpoint error) attains the actual region image used, assigns it a name of your choosing and puts it in a folder along with the diff file and expected image.  I'm not sure if this is possible with a handler...?  The actual images saved to the TC directory are hard to sort through and match up.  Basically for the project I am working on, we'd like to attain the expected, actual, and dif .pngs so we can manually look through the differences.



I was working on the following but it's not working and not correct (how do I add the dif file?) :



  Set Pict = Sys.Desktop.PictureUnderMouse(20, 20, False)      ' But I'd much rather attain the actual image file...

  Set StoredPict = Regions.GetPicture("StoredImageName")


  If Regions.Compare(StoredPict, Pict, False) then

  Call Pict.SaveToFile("C:\Folder\Results\Compares\"+StoredImageName+ACTUAL.png)

  Call StoredPict.SaveToFile("C:\Folder\Results\Compares\"+StoredImageName)

  Call Log.Message("Compare Files Saved to C:\Folder\Results\Compares")

  End If


Thanks!

Morgan
  • Hi Morgan,



    1)  I am working on a handler for OnLogError that stops script execution after a certain number of errors



    Here is the sample script:




    If Log.ErrCount > 3 Then


      Log.Message "Max number of errors reached - Test execution halted" 


      Runner.Stop


    End If









    2)  Secondly, I was wondering if it was possible to create a script that (on region checkpoint error) attains the actual region image used, assigns it a name of your choosing and puts it in a folder along with the diff file and expected image.  I'm not sure if this is possible with a handler...?  The actual images saved to the TC directory are hard to sort through and match up.  Basically for the project I am working on, we'd like to attain the expected, actual, and dif .pngs so we can manually look through the differences


    You can use the Picture.Difference method:




    Set Pict = Sys.Desktop.PictureUnderMouse(20, 20, False)


    Set StoredPict = Regions.GetPicture("StoredImageName")


    Set DiffPicture = StoredPict.Difference(Pict)


    If Not DiffPicture Is Nothing Then


      Call Pict.SaveToFile("C:\Folder\Results\Compares\StoredImageName_ACTUAL.png")


      Call StoredPict.SaveToFile("C:\Folder\Results\Compares\StoredImageName.png")


      Call DiffPicture.SaveToFile("C:\Folder\Results\Compares\Differences.png")


      Call Log.Message("Compare Files Saved to C:\Folder\Results\Compares")


    End If




    Note that C:\Folder\Results\Compares must exist to save files to it. For more information, refer to the Picture.SaveToFile help topic.
  • Morgan's avatar
    Morgan
    Frequent Contributor
    Thank you very much, it works perfectly! 



    Morgan