Forum Discussion

lucist's avatar
lucist
Occasional Contributor
13 years ago

Unable to highlight and log a picture at the same time

Hello!



I am a beginner with TC and trying to create a VB script for highlighting an object (a button for example) from a web-page and log a picture of it (that will display the button as highlighted) at the same time.



I am running the following script but I get an error and don't know what I have made wrong :



Sub Find



  Dim firefox, Result



  Set firefox = Aliases.firefox.Page("http://www.google.ro/").Panel("searchform").Form("tsf").Panel(0).Panel(1).SubmitButton("btnK")

 

  Set Result = Runner.CallObjectMethodAsync(firefox, "HighlightObject")

  Log.Picture(firefox)



  While Not Result.Completed

    aqUtils.Delay 300

  WEnd



End Sub

7 Replies

  • lucist's avatar
    lucist
    Occasional Contributor
    Hey Robert ! Thanks for the fast reply !



    I am getting a VBScript runtime error on line 7 column 3



    so the issue may be with this code line :



    Set Result = Runner.CallObjectMethodAsync(firefox, "HighlightObject")  











    Thank you!
  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hello,

    The HighlightObject method is a member of the Sys object and it accepts the onscreen object to be highlighted as a parameter. Therefore, the correct code should be as follows:



    Sub Find



      Dim firefox, Result



      Set firefox = Aliases.firefox.Page("http://www.google.ro/").Panel("searchform").Form("tsf").Panel(0).Panel(1).SubmitButton("btnK")

     

      Set Result = Runner.CallObjectMethodAsync(Sys, "HighlightObject", firefox)

      Log.Picture(firefox)



      While Not Result.Completed

        aqUtils.Delay 300

      WEnd



    End Sub

  • lucist's avatar
    lucist
    Occasional Contributor
    Thanks very much for your advise Artem, that solved the issue !
  • Hello,



    I am having problems with the solution to the issue of highlighting an object and taking a picture at the same time. The issue is that sometimes the picture doesn't have the red border around it. Is it because the red border flashes? Therefore if it happens to be flashed off when the picture happens, there's no border?



    If TC knows to have the red border in the log.picture even if it's flashed off, then why am I getting some pictures with no red border? Is it because it's not flashing for long enough for the picture event to complete? If that's the case, how do I have it so that it flashes only for long enough that the picture is complete vs having a hard coded delay in the HighlightObject call. I want to avoid a hard coded delay.



    Thanks,



    Robert.

  • lucist's avatar
    lucist
    Occasional Contributor
    Hi Robert,



    You can try the below function:




    Sub findobject(PropArray, ValuesArray, path)

      Dim val,w

      Set w = path.FindChild(PropArray, ValuesArray, 10)





      If w.Exists  then

        val = true

        else

        val = false

      End if

      

      If val = True Then 

      

        Set Result = Runner.CallObjectMethodAsync(Sys, "HighlightObject", w, 5)

        Log.Message "The object "&ValuesArray&" is displayed on page", Nothing, pmNormal, Nothing, path   

           

           While Not Result.Completed

              aqUtils.Delay 100

           WEnd

        

        Else

        

        Set Result = Runner.CallObjectMethodAsync(Sys, "HighlightObject", path, 5)

        Log.Warning "The object "&ValuesArray&" was not found.", Nothing, pmNormal, Nothing, path   

           

           While Not Result.Completed

              aqUtils.Delay 100

           WEnd

        

      End If



    I am having the same problem as you if I lower the number of flashing times(currently is set to 5) from the below line code :



    Set Result = Runner.CallObjectMethodAsync(Sys, "HighlightObject", w, 5)





    Please let me know if it helps,



    Lucian


  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)

    Hello gentlemen,

    >>The issue is that sometimes the picture doesn't have the red border around it. Is it because the red border flashes? Therefore if it happens to be flashed off when the picture happens, there's no border?

    Yes, since Sys.HighlightObject and Log.Picture are called asynchronously, TestComplete is not guaranteed to capture an image of the on-screen object exactly when it is surrounded with the red border. 

    Try to experiment with the HighlightCount parameter that determines the number of flashing times as Lucian suggested. This would be the fourth parameter in the Runner.CallObjectMethodAsync(Sys, "HighlightObject", w, 5) routine call. 



    Regards.