Forum Discussion

rancohen's avatar
rancohen
Occasional Contributor
6 years ago

compare two variables between values

Hi,

 

I have textbox that show time with seconds.

I need to verify number of seconds pass from last reading, since the test take also time I have mistaken of +/-1 second in the test and that's OK.

How can I run test that will take account the accuracy of the test with +/-1 second?

 

I used one variable to store the previous time, and I variable that store the new time. how can I add checkpoint for time difference with +/- 1 second?

meaning, only if time difference is more or equal to 2 second, error should be record.

 

Thanks,

Ran

 

  • depending on your language 

    you can use something like... (this is sudo code)

    first if values are in string format convert to time..

     

    now_time = String_todatetime("String_now_Time");
    old_time = String_toDatetime("String_old_Time")

    if your languge is VBScript may look like this

    then compare .............


    if ((now_time - old_time)=>2) {     Log.Error("got more than 2 secs"); }

     

4 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    depending on your language 

    you can use something like... (this is sudo code)

    first if values are in string format convert to time..

     

    now_time = String_todatetime("String_now_Time");
    old_time = String_toDatetime("String_old_Time")

    if your languge is VBScript may look like this

    then compare .............


    if ((now_time - old_time)=>2) {     Log.Error("got more than 2 secs"); }

     

    • rancohen's avatar
      rancohen
      Occasional Contributor
      Hi NisHera,

      Thank you for your response.

      What is the difference between Log.Error and checkpoint compare?
      When the test pass I can't see the green mark like in checkpoint.
      There is only Log.Message no Log.Success option.
      I'm new to TestComplete and I would be glad if you could elaborate on that.
      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        If you would prefer, you could change the if-then logic code to this:

        if ((now_time - old_time)=>2) {
        
            Log.Error("got more than 2 secs");
        
        }
        else Log.Checkpoint("Got 2 seconds"):

        However, I would recommend what NisHera wrote... why write to the log file information you don't need?  If you don't see an error, it passed.  The more you write to the log, the bigger the log size gets, and the more data you need to sort through to find whether or not something passed or failed.  So, NisHera says, simply "If it failed, log it... if not... do nothing and assume it passeD".