Forum Discussion

Nadav's avatar
Nadav
Contributor
7 years ago

Comparing 2 equal values failed in property checkpoint

Hi,I try to compare property in checkpoint, the property compare failed although it has same value

  • You can write a script routine using the script editor of TestComplete.  You should have chosen a script language when you created your project.

     

    Once your script code is written, you can use the "Run Script Routine" operation to execute the code within your keyword test.

  • Hi,

     

    > The value is float

    This is the key. Regular comparison logic does not work with floats due to their internal representation. Your approach with the threshold is valid and generally used one.

     

    Or, convert floats to strings as it was suggested by Robert and do strings comparison.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Non-printing characters, spaces, etc., all are compared.  If you're comparing string to string, it needs to be EXACT.

    Double check to make sure that the actual property does not have spaces at the end.  You could always change the test to "contains" instead of "equals".

    • Nadav's avatar
      Nadav
      Contributor

      Hi Trisyaanogre,

      The values are exactly the same, no spaces or something like that, even when I updated the property to the actual value and ran the test again it fails.

      Furthermore the value is recognized as a number and not as a string (I don't have the "contains" condition) .

      My end game is to compare the value with  a threshold - is there any way to do this? 

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I'm wondering if it may be a rounding problem... that the property value actually contains more significant digits than what is visible... or if it's a data type problem (double vs long).

        What would happen if you had your "Expected Value" stored as a string?  To see if it compares string to string?

  • Nadav's avatar
    Nadav
    Contributor

    The value is float, the main goal of this test is to compare array of floats.

    I can not change the type of the property because it is an external component.

     

    Is there a way to compare array of values and not only one?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      I would write script code for that rather than using a property checkpoint.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      > The value is float

      This is the key. Regular comparison logic does not work with floats due to their internal representation. Your approach with the threshold is valid and generally used one.

       

      Or, convert floats to strings as it was suggested by Robert and do strings comparison.

  • Nadav's avatar
    Nadav
    Contributor

    How do I replace checkpoint with script code?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      You can write a script routine using the script editor of TestComplete.  You should have chosen a script language when you created your project.

       

      Once your script code is written, you can use the "Run Script Routine" operation to execute the code within your keyword test.