Recording test start time proving difficult

I’m trying to record the start time for a test so that in the handleSummary() section I can append it to the output JSON I’m building. However, this is proving more difficult than I had thought.

I’m trying to declare a variable as so
const startTime = new Date().toLocaleTimeString();

However if this is declared in the init context, since it’s run once per VU, I just get the start time of the LAST run VU which isn’t useful. If I declare it in the setup() section the variable cannot be accessed from handleSummary()

I cant use the built in custom metrics since those are for integer based data to be stored. I considered calculating the total length of the test and subtracting that time from the my endTime variable I declare in handleSummary() but that is proving to be a more complicated solution than I had thought.

Has anyone had experience recording start times for tests in handleSummary()? Thanks

Hi jnazemi,

Could you check this answer? It seems similar to what you’re trying to do.

Or, what you’re looking for is custom tags, or for more advanced usage is scenarios. Could you look at them and please tell us whether they solve your issue.

Thanks.

2 Likes

This did in fact solve my problem, thanks!

1 Like

Glad that it worked for you!