Question

Tosca DateTime variable calculation function

  • 6 March 2024
  • 4 replies
  • 52 views

Badge

 for testing I need to create  time records

so I created Variables to store DateTime 

my expectation is that between Start and Stop is 3 seconds 

but sometimes when variable initialised  real difference is 2 seconds 

So it looks like Variable initialisation happens on last milliseconds - the problem is that further calculation and Responce time checks failing du to expected result 3 sec and Actual result is 2 sec

And unfortunately it happens quiet often

 

Can someone suggest if I can initialise 1 variable like 'StartTime'

and then in next variable use formula expresion 'EndTime' = 'StartTime'+3sec

 

is there way of doing this in Tosca ?

i couldn find this type of DateTime calculation on Help page 

https://documentation.tricentis.com/tosca/2320/en/content/tbox/date_and_time_expressions.htm


4 replies

Userlevel 3
Badge +1

From your description it sounds like the Tosca buffers (expected result) are indeed 3 seconds apart, but the actual system (expected result) is returning them 2s apart? It’s hard to tell without seeing the other test steps you’re using to compare the values, the actual buffer values and full error message you get when running the steps, etc.
I wouldn’t expect the Tosca buffer values to differ by 2s very often since it only takes Tosca a few ms to generate each one.

So I don’t think changing your buffering steps will do a lot, but if you want to guarantee they are always based on the same initial timestamp, I would try something like this:

  1. Create an initial buffer called e.g. Timestamp with the value {DATETIME}
  2. Use {B[Timestamp]} as the first parameter, i.e. the Basedate for your other buffer values. Then you can be assured they are all using the exact same timestamp as their baseline.
Badge

Explanation to why the difference in one second appears 
Example

Start time - 23:55:01 (it was initiated on 23:55:01:999ms)

End time - 23:55:04 - expected 

End time - 23:55:05 - actual (it was initiated on 23:55:02:001ms)

Since I use a loot of time parameters this happens often and my calculation fails.

So my question is - can I use ‘StartTime’ variable as starting point and calculate ‘EndTime’ variable as SUM of ‘StartTime’ and preProgrammed difference ‘+3sec’ ?

like ‘EndTime’ = ‘StartTime’ +3sec


in this case difference is always be the same 3sec.

I tried next expression on Tosca but it didnt work

 

Userlevel 3
Badge +1

Explanation to why the difference in one second appears 
Example

Start time - 23:55:01 (it was initiated on 23:55:01:999ms)

End time - 23:55:04 - expected 

End time - 23:55:05 - actual (it was initiated on 23:55:02:001ms)

Since I use a loot of time parameters this happens often and my calculation fails.

So my question is - can I use ‘StartTime’ variable as starting point and calculate ‘EndTime’ variable as SUM of ‘StartTime’ and preProgrammed difference ‘+3sec’ ?

like ‘EndTime’ = ‘StartTime’ +3sec


in this case difference is always be the same 3sec.

I tried next expression on Tosca but it didnt work

 

In your baseline buffer (TimeStartAt), don’t include any formatting. You only need to capture the timestamp itself there.

You didn’t say exactly how it didn’t work, but my guess is that the second buffer failed because it couldn’t parse the TimeStartAt as a date due to the formatting.

Badge

Thank you Brendon.
Yes the problem was in DateTime formatting in the firs variable wich I was using for further calculation.
when i removed my formatting [yyyy-MM-dd'T'HH:mm:ss'Z'] from the first (TimeInitial) variable - all further time calculations work just fine
Example:

 

If there is someone from Tricentis on this forum - I think it will be great to add this or similar example to help page ))

Reply