Forum Discussion

todd2's avatar
todd2
Contributor
12 months ago

Concat Now Time in YYYYMMDDHH with LastName keyword test field as one string value

I have this piece of code

# Obtain the current time
 TimeValue=aqDateTime.Time() # Obtain the current date and time
 NowValue=aqDateTime.Now() # Convert the returned date/time values to string values
 StringTimeValue = aqConvert.DateTimeToStr(TimeValue)
 StringNowValue = aqConvert.DateTimeToStr(NowValue) # Post the converted values to the log
 Log.Message(“The time obtained from the Time routine is ” + StringTimeValue)
 Log.Message(“The time obtained from the Now routine is ” + StringNowValue) # Convert the floating-point values to string values
 VariantTimeValue = aqConvert.FloatToStr(TimeValue)
 VariantNowValue = aqConvert.FloatToStr(NowValue) # Post the converted values to the log
 Log.Message(“The variant representation of TimeValue is “+ VariantTimeValue)
 Log.Message(“The variant representation of NowValue is “+ VariantNowValue)

 

I want to concat the The time obtained from the Now routine as YYYYMMDD and 24 hr format which the above does not look like.  I dont need the PM.  The name of the field to concat the time and date now function to is Aliases.browser.pageApplyNow6.formWouldYouLikeToIncludeA.textboxLastName

 

How can I achieve that in a unit script and when test executes the unit script fills out the LastName field with the entire string?  I want to store that result also in a temporary variable that will be called again later in the test and reset when the start of the test begins the next time.

 

Thank You,

 

Todd

21 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you refer and understand how aqDateTime Object works, and look at the examples provided & the methods. If you want to format the date, then refer to Marsha_R response.

     

    It's worth understanding what Epoch is.

    • todd2's avatar
      todd2
      Contributor

      Thank you both for your responses.  I did the research into the aqDateTime object and its formatting options.  I created this sample of python unit script code but I must be missing something because the interpreter will not let me execute.  What could I be missing?  Yes, I checked the examples. 

       

      def ConcatLastNameWithTime():

        Str1 = "Aliases.browser.pageApplyNow6.formWouldYouLikeToIncludeA.textboxLastName"

        Str2 = "aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%Y%m%d%H%M%S"))

        Log.Message(aqString.Concat(Str1, "Str2"))

      # Log.Message(Aliases.browser.pageApplyNow6.formWouldYouLikeToIncludeA.textboxLastName + aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%Y%m%d%H%M%S"))

       

      then yes I need it in a variable project wide.  How would I get the above to run in the interpreter correctly and then how do I make it into a variable?  Could I make my variable point to Unit1?

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    I would log current_time right after you create it just to make sure that it has the content you wanted. You may also need to force it to be a string before you concatenate it.

    • todd2's avatar
      todd2
      Contributor

      Marsha,

       

      This is what my log says after I run the unit3 script to show you that it is indeed echoing to the log output what I want

       

      But when the keyword test script executes it only types America there not the result of the unit3 script output.

       

      Sincerely,

       

      todd2

      • todd2's avatar
        todd2
        Contributor

        Marsha,

         

        See I want the contents of Unit3 to appear right at the text control in the picture provided. 

         

         

        Thank You,

         

        todd2

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    I get it!  🙂

     

    Even though your unit3 script output looks good, I am concerned that the variable value is not what we expect it to be.

     

    Please output UpdatedLastName to the log in the keyword test (not in the script) at the point right before you try to put it in the text box and let's see what the variable has in it at that moment.

    • todd2's avatar
      todd2
      Contributor

      Marsha,

       

      Yes, I bet the variable is reporting the default value of America (because I thought you cant leave that blank you have to initialize the variable with something) not changing to what is in the contents of Unit3 script.  How do I, when creating a Project Variable, tell it to go get the contents of Unit3? 

       

      Thank You,

       

      todd2

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Let's test that.  Make the default in the variable be something like "abcdefg" instead of "America", so we can really tell the difference when the updated string is added. 

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    Make sure that UpdatedLastName is a Project or ProjectSuite level variable so that it is available at all times in your test.

    See if that helps and let me know!
      • todd2's avatar
        todd2
        Contributor

        Marsha,

         

        So we can get Unit3 to output to the log America and the Date and Time in the format we seek.  What we cant get accomplished is the Project variable is not receiving that value even though I told it to do so in the Unit script.  I even initialized the variable by placing a default value in it and it will not change to what I want at keyword test script execution time.  How come?

         

        todd2