Forum Discussion

AKarandjeff's avatar
AKarandjeff
Contributor
12 years ago

Log object variables

Is there a way to display the value of an object variable in the log?  I have to determine what kind of object I'm trying to test against based input from a properties table.  I have a situation where it appears that TC is not finding the object, but I'd like to display what object type it thinks it's looking for.  When I do a Log.Message(textField), I get nothing but a blank message line in the log.  Below is a snippet of my code.  I want to see what's been put in the textField variable once the switch command has executed.  Thanks.



                

           switch (vfpFPObjType)

               {

                 case "PropCombo":

                 textField = panelC.PropTypeComboBox.TextField;

                 break;

                 case "TableCombo":

                 textField = panelC.TableComboBox.TextField;

                 break;

                case "PropText":

                 textField = panelC.PropTypeTextField;

                  break;

                case "SimpleString":

                 textField = panelC.TextField;

                  break;

                 case "Password":

                   textField = panelC.SwingObject("JPasswordField", "", 0)

                   break;

                 default:

                   Log.Message("Type Not Found");

                }

               Log.Message(textField);

3 Replies

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Andrew,


    >> Is there a way to display the value of an object variable in the log?

    What do you mean by "the value"? Objects contain various properties, so you can log some of the property values, for instance:




    textField = null; // Initialize the variable


    // ...

    // Do your test actions, assign obj references to the variable

    // ...


    // Check results

    if (textField != null)

      Log.Message ("The object was not found")

    else

      Log.Message (textField.USE_SOME_TEXT_PROPERTY_HERE);

  • What I'm trying to figure out is what object type has wound up in the textField variable.  My application creates a dynamic java table and each value field can be a different object (text field, combo box, password, etc).  The object type can be derived from the application database, but there's a bit of convoluted logic to make the determination, and I don't always get it right.  I have the switch case statement to set the textField object variable based on the output of the database.  In the instance my query is incorrect, I'd like to know which object type was placed into the textField variable (e.g. panelC.TextField, panelC.ComboBox.TextField, etc.).  However, if I just log the textField variable, it shows up as nothing more than a blank in the log.
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Andrew,


    Different edit controls should have different class names. You can post these names to the log.

    I'm not a big Java specialist, but perhaps you can use some code like this:


    ...

    if (textField != null)

      class = textField.getClass().getName();

    ...


    You can ask your developers for assistance. They should know how to obtain the class name.