Ask a Question

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

todd2
Contributor

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 21
Marsha_R
Champion Level 3

Here's how to reformat the date and time

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/date-and-time-f...

 

If you want to use that in another instance of the test, then store it in a Project Variable or a Project Suite Variable. Otherwise it won't be stored for next time.

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.

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?

Or MarshaR would this be simpler somehow to deploy?

 

https://community.smartbear.com/t5/TestComplete-Questions/String-concatenation-using-Keyword-testing...

 

Sincerely,

 

Todd

So I went ahead and built three steps into my keyword test script  

The Unit2 script runs by itself just fine but when it executes within the entire keyword script it gives me an exception. Why?  My thought was I have the time format working well.  I can place the lastname in a variable project wide now and I initialized it with a starter value just fine by setting the default value.  All I want to do is run the code snippet Project.Variables.LastName + Unit2   Can't that be done?

todd2_0-1683133034930.png

 

Sincerely,

 

Todd2

 

 

todd2_1-1683133281286.pngtodd2_2-1683133371499.png

Works great!  Now I just need to add that last name that is in the Variable for the project at the moment the script runs to the front of this output as one big string and we are good to go.  What could I be missing?

 

Thanks,

Todd2

Team:  This code now works as a Unit script

 

from datetime import datetime

 

def ContatenationString():

    Lastname = "America"

    now = datetime.now()

    current_time = now.strftime("%H%M%S")

    UpdatedLastname =  Lastname+current_time

    Log.Message(UpdatedLastname)

ContatenationString()

 

But when the keyword test script executes and the lastname on the form approaches, the name America prints but not UpdatedLastname.  What do we got to do to make the lastname text box print the UpdatedLastname value?  The keyword test steps have been modified as well as indicated below.

 

todd2_0-1683142897178.png

 

Thank you,

 

Todd2

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.

rraghvani
Champion Level 3

Is this is your first time coding?

cancel
Showing results for 
Search instead for 
Did you mean: