Updated LoadRunner Date/Time sample script

A couple of days ago, I read Scott Moore’s interesting article about using multipliers to increment LoadRunner date/time variables by multiples of more than one day.

This made me look at my own date/time sample script, mentioned in an earlier post, and incorporate Scott’s suggestions in there. I added some sample code to check to see what day it was and calculate the number of days until next Monday.

Next Monday LoadRunner

Click the icon below to download the script containing this code together with other examples of date/time manipulation in LoadRunner.
zip
DateTimeSamples

 

For those of you who like to see “code” in posts, here is the “Next Monday” code in full…

//What date is next Monday?
lr_save_datetime(“%A”, DATE_NOW, “Today”);

if (strcmp (lr_eval_string(“{Today}”),”Monday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*7), “DDMMYY”);
lr_output_message(“Today is Monday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Tuesday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*6), “DDMMYY”);
lr_output_message(“Today is Tuesday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Wednesday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*5), “DDMMYY”);
lr_output_message(“Today is Wednesday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Thursday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*4), “DDMMYY”);
lr_output_message(“Today is Thursday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Friday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*3), “DDMMYY”);
lr_output_message(“Today is Friday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Saturday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*2), “DDMMYY”);
lr_output_message(“Today is Saturday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}
if (strcmp (lr_eval_string(“{Today}”),”Sunday”)==0)
{
lr_save_datetime(“%d/%m/%y”, DATE_NOW+(ONE_DAY*1), “DDMMYY”);
lr_output_message(“Today is Sunday, next Monday’s Date is %s”,lr_eval_string(“{DDMMYY}”));
}

 

 

New GESHI syntax highlighter for LoadRunner 11.5

In August 2010, I put Stuart Moncrieff’s syntax highlighter on my website so that I could easily copy and past LoadRunner code into documents in the correct colours. Since LoadRunner 11.5 was released with a new compiler and different colours in the script editor, I thought that it was time for an update.

The links below take you to the old and new GeSHi pages which format text in LR 9.x and LR 11.x colours.

http://bish.co.uk/geshi/LR_9_5.php
LoadRunner 9.5 script editor colours

http://bish.co.uk/geshi/LR_11_5.php
LoadRunner 11.5 script editor colours

 

Whilst this may be useful to you, you may also be pleased to know that the new editor supports pasting directly from VUGen into Word or other programs and the source formatting is preserved. This is great if you want to insert code snippets into documents and keep the code readable.

 

Evaluate string content in LoadRunner

This little bit of code was passed to bish.co.uk by Mark Sibley. I thought that I’d reproduce it here because it looked useful. You can use this function to check whether a captured string contains a certain piece of text, this allows you to check for the presence of an error “word” when your captured string may not always use the same boundaries.

This gives similar functionality as web_reg_find but without the overhead of searching HTML as it is returned to the vUser, it allows “post processing” of captured text which tends to have a lower performance hit on the vUser.

 
	// Use this if you want to check whether something you captured contained a piece of text
	// It's handy if the same word appears in more than one type of error or warning message but doesn't // always have the same boundaries.
	if ((char *)strstr(lr_eval_string("{cCapturedString}"), "rejected") != NULL)
	{
		lr_save_string(lr_eval_string("DATA USED:: Rows:[{cRowText}] Param Name:[{sCatParamTitle}] sCatTxt:[{sCatTxt}]"),"sDataUsed");

		lr_fail_trans_with_error("Expected:[%s] %s",Expected,lr_eval_string("Received:[{cCaptured}] User:[{pUserID}] I:[{pIteration}] T:[{sTransaction}] {sDataUsed}")); 
		lr_exit(LR_EXIT_MAIN_ITERATION_AND_CONTINUE,LR_FAIL);
	}
	else
	{
		lr_vuser_status_message(lr_eval_string("User [{pUserID}] completed I:[{pIteration}] T:[{sTransaction}]"));
	}