Forum Discussion

jyothi_priya's avatar
jyothi_priya
Contributor
13 years ago

How to post object name in log messages

Hi,



I have written a script as follows:



Function clickcontrol(Object)



    If Object.exists then

        Object.Click

    Else

        Log.Message( Object & " is not found")          'This is actually not working when object does not exist

    End If

End function



Sub abc()



    XXX = NameMapping.Sys.Process("XXX")    

    Call  clickcontrol(XXX)



End Sub



My Req is:

If object XXX does not exist, then I should get a log message 'XXX is not found'. Using Log.Message( Object & " is not found") throws error as object itself doesnot exist. Is there any way to display object custom name when it doesn't exist?



   

1 Reply

  • Hi,


    To post the custom object name to the log, you can modify your script in the following way:




    Function clickcontrol(Object)

        If Object.exists then

            Object.Click

        Else

            Log.Message( "The object is not found")   'the modified line

        End If

    End function



    Sub abc()

        XXX = NameMapping.Sys.Process("XXX")   

        Call  clickcontrol(XXX)

        Log.Message ("The object custom name is XXX") 'the added line

    End Sub





    Now if the object has not been found, TestComplete will post two messages to the log. The first message informs you that the object has not been found, the second one contains the object's custom name.