Prevent a LoadRunner script from running between two times

Some scripts cannot be run between certain times, this is especially the case when we are running long duration tests or preparing test data by data-seeding overnight.

In these cases it may be useful to specify times when you don’t want a script to run, for example you might want to schedule a script so that it can’t run when backups or system restarts are taking place.

The attached script contains an example of a function (CheckExclusionTime) which can prevent a script from running between certain times. The script is made more complicated by the fact that you might want to prevent a script from running between 23:50 one day and 00:15 the next day. To achieve the desired result it is necessary to convert any time into an integer value representing the number of minutes which have passed from 00:00 on Monday until the current time and then calculating if the current time falls within the excluded period.

2016-10-06-12_45_30-timeexclusion-hp-virtual-user-generator-web-http_htmlThe integers 1 through to 7 represent the days Monday through to Sunday.

Other integers are used to represent the exclusion start time and exclusion end time.

Sample LoadRunner scripts, demonstrating LOOPs

I have found numerous occasions where I need to use a LOOP within a LoadRunner script to repeatedly perform an action. There are several ways that LOOPs can be used to repeat actions for either a specified number of times or until a particular occurrence is observed.

 

This script includes an example of FOR, WHILE and DO LOOPs.

Click here to download the script.
LoopExample.zip

 

 

Convert a number to text

Another Mark Sibley function.

This converts a number into text. It relies on the number already being saved as a character string.

It’s currently set to create a title case word but could be amended to create an all upper or lower case word easily enough.

The words it creates are going to be mostly nonsense, however because it could have occasionally created a real word I removed all of the vowels to reduce the likelihood of creating any offensive words.

Copy and paste the following into a LoadRunner script to see it in action.

int ConvertNumberToText(char * sInput)
{
int i;
int c;
char n;
char sText[50];
char sCharacter[10];
char * sUpper[10];
char * sLower[10];

sUpper[0] = “B”; sUpper[1] = “C”; sUpper[2] = “D”; sUpper[3] = “F”; sUpper[4] = “G”;
sUpper[5] = “H”; sUpper[6] = “J”; sUpper[7] = “K”; sUpper[8] = “L”; sUpper[9] = “M”;

sLower[0] = “b”; sLower[1] = “c”; sLower[2] = “d”; sLower[3] = “f”; sLower[4] = “g”;
sLower[5] = “h”; sLower[6] = “j”; sLower[7] = “k”; sLower[8] = “l”; sLower[9] = “m”;

for (i = 0; i < strlen(sInput); i++) {

sscanf(sInput+i,”%c”,&n);
sprintf(sCharacter,”%c”,n);
c = atoi(sCharacter);

// This ensures that the first character is an upper case letter and that the rest are lower case.
// If you want a word that is either all upper or lower case then amend the appropriate [sUpper] or [sLower]
if (i == 0) {strcpy(sText,sUpper[c]);}
else  {strcat(sText,sLower[c]);}
}

lr_save_string(sText,”sName”);
lr_output_message(lr_eval_string(“Output:[{sName}]”));
}

Action()
{
int p = 459332;
char string[50];

itoa(p,string,10);

lr_save_string(“50328″,”sNumber”);

ConvertNumberToText(string);
ConvertNumberToText(“2168”);
ConvertNumberToText(lr_eval_string(“{sNumber}”));

return 0;
}