Forum Discussion

nisgupta's avatar
nisgupta
Valued Contributor
7 years ago

TestComplete - check whether the property value is empty

I would Like to know how we can we check whether the property value of the object is empty or not by script in TestComplete ?

 

For e.g. We have a Object called Log Out Button, Want to check whether the contentText property of the object is empty or not by script ? If it is empty then I can check for another property like idStr.

 

Let me know if you need additional questions 

 

Thanks

Nishchal

 

 

  • I'm confused: Why do you need to log the property used for mapping when you click the button?  What purpose does that serve in your testing?  The mapping does the identification... all you need to do is pass the Alias into your ClickButton function and call the appropriate click method.  What is used for mapping makes no difference in the execution of the click.

  • nisgupta's avatar
    nisgupta
    7 years ago

    Thank you for the updates . I figured out the solution by passing the alias.

     

    NG

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Script or keyword test?

     

    In script, if you want to check the property value and return a true or false, then I'd do something like this (JavaScript)

     

    var myObject = Aliases.MyApp.buttonLogout;
    if (aqObject.CompareProperty(myObject.contentText, 0, '', false, 0){
        Log.Message('content text is blank, checking idStr');
        aqObject.CompareProperty(myObject.idStr, 0, '', false, 2)
    }

    The CompareProperty method of aqObject will check the property of an object based upon the condition and value passed.  If the condition passes, the method returns true, if not, it returns false.  You can have the method log a message or not and that message could be a warning or an error as desired.  See https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/compareproperty.html

     

    Now, you can simplify it by just using simple if/then logic...

     

    var myObject = Aliases.MyApp.buttonLogout;
    if (myObject.contentText === ''){
        Log.Message('no content text, checking idStr');
        if (myObject.idStr === '' {
             Log.Warning('idStr is blank');
        }
    }

    Either way will work.

    • nisgupta's avatar
      nisgupta
      Valued Contributor

      Thank you for the updates

       

      It is script. I am trying to implement Button click function. So after the button is clicked then in the Log Message I want to log the message with the button property name which is mapped in the Name Mapping.. Currently in my case there are some Buttons which have the following properties like

       

      Some Buttons have  contentText Property only. In the Name Mapping I map contentText

       

      Some Buttons have idStr Property only. In the Name mapping I map idStr

       

      Some Button have both contentText and idStr Property . In the name Mapping I map idStr

       

      Thank You

      NG

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I'm confused: Why do you need to log the property used for mapping when you click the button?  What purpose does that serve in your testing?  The mapping does the identification... all you need to do is pass the Alias into your ClickButton function and call the appropriate click method.  What is used for mapping makes no difference in the execution of the click.