Forum Discussion

nedbacan's avatar
nedbacan
Frequent Contributor
5 years ago

TestComplete function to capture system clock of computer

Hello, can someone tell or show me how can I capture the system clock time/date and use it to compare the time/date to an object property checkpoint value , and report the result to a log, pass if it matched.

 

Also if it can check the format if is correct as well but this can be a seperate check.

 

I am using Keyword scripting and if I can add it to a script routine it will be nice.  Thank you !!

  • Hi Ned

     

    "capture the system clock time/date"

    Use the aqDateTime.Today method to get the current date.

    To obtain both the current date and time, use the Now method

    To obtain only the current time, use the Time method.

     

    Doc link: https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/today.html

     

    "to compare the time/date to an object"

    The aqDateTime.Compare method compares two Date/Time values.

     

    "I am using Keyword scripting and if I can add it to a script routine it will be nice."

    Check my tutorial on this topic:

    https://community.smartbear.com/t5/TestComplete-Functional-Web/Add-a-check-on-the-file-extension-type-of-the-file-exported/m-p/197789

     

    "How to check results"

    Use -> aqDateTime.Compare

    Result Value

    An integer number that indicates the comparison result. The possible values are:

    -1 Date1 is earlier than Date2
    0 Date1 is equal to Date2
    1 Date1 is later than Date2

     

    Use these values inside if condition to obtain results.

     

    let result = aqDateTime.Compare(Date1, Date2);
    
    if(result === 1) {
      Log.Checkpoint("It's 1!");
    }
  • Wamboo's avatar
    Wamboo
    5 years ago

    Hi nedbacan,


    1) You can try to access this property from the first screenshot using the file object.innerText save it in the variable

    2) get the current time using the native TestComplete built in class. You have doc in my first entry

    3) parse1 and 2 to the appropriate date format

    4) use the native TestComplete solution to compare values.


    I hope this will help you!

     

  • Wamboo's avatar
    Wamboo
    Community Hero

    Hi Ned

     

    "capture the system clock time/date"

    Use the aqDateTime.Today method to get the current date.

    To obtain both the current date and time, use the Now method

    To obtain only the current time, use the Time method.

     

    Doc link: https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/today.html

     

    "to compare the time/date to an object"

    The aqDateTime.Compare method compares two Date/Time values.

     

    "I am using Keyword scripting and if I can add it to a script routine it will be nice."

    Check my tutorial on this topic:

    https://community.smartbear.com/t5/TestComplete-Functional-Web/Add-a-check-on-the-file-extension-type-of-the-file-exported/m-p/197789

     

    "How to check results"

    Use -> aqDateTime.Compare

    Result Value

    An integer number that indicates the comparison result. The possible values are:

    -1 Date1 is earlier than Date2
    0 Date1 is equal to Date2
    1 Date1 is later than Date2

     

    Use these values inside if condition to obtain results.

     

    let result = aqDateTime.Compare(Date1, Date2);
    
    if(result === 1) {
      Log.Checkpoint("It's 1!");
    }
    • nedbacan's avatar
      nedbacan
      Frequent Contributor

      Appreciate your help but I am new to scripting. 

       

      Please if you can elaborate how will I get the time displayed as a label on the screen (see attachment) and compare it to the system clock using the aqDateTime.Compare method.   I added a screen shot of the object property of the label, which name will work to compare with the system time?

       

      I need to add both times as variables? 

       

      Anyhow a small demonstration would be great as you did in the tutorial below ..!!  

       

      Thank you very very much. =)

      • Wamboo's avatar
        Wamboo
        Community Hero

        Hi nedbacan,


        1) You can try to access this property from the first screenshot using the file object.innerText save it in the variable

        2) get the current time using the native TestComplete built in class. You have doc in my first entry

        3) parse1 and 2 to the appropriate date format

        4) use the native TestComplete solution to compare values.


        I hope this will help you!