Write the Jmeter parameter values to a text file

Below is the BeanShell Script to write the Jmeter parameter values to a text file.

Create a Jmeter Script and Add-->Sampler-->BeanShell Sampler

Code Snippet:

String FailedUser = vars.get("P_UserID"); //Save the parameter that has to be written to a variable

f = new FileOutputStream("[Folderpath]/output.txt", true); //Path of the text file in which to write the parameter

p = new PrintStream(f); //open the text file to write

this.interpreter.setOut(p);

print(FailedUser); //Write the failed users to the text file

print(FailedUser+","+FailedUser); //optional step to print multiple comma separated variables

f.close(); // close the text file

How to pass parameters as your transaction names in Loadrunner

 Consider a scenario where you have to get transaction response time for the different sizes of file upload. Here the file upload request will be same and we have to print the file size in the transaction name so that we can map the response time with the corresponding file sizes.

lr_start_transaction(lr_eval_string("07_FileUpload_02_Choosefile_{P_File_Size}_Submit"));

File upload request

lr_end_transaction(lr_eval_string("07_FileUpload_02_Choosefile_{P_File_Size}_Submit"), LR_PASS);


P_File_Size is the parameter which has the file size. Say for example if you have two file sizes of 1MB & 10MB, you will get two transaction for the file upload in your analysis report.


Output:

07_FileUpload_02_Choosefile_1MB_Submit

07_FileUpload_02_Choosefile_10MB_Submit



How to pass Parameter values as Boundaries to the correlation function in loadrunner

When you want to pass the user defined parameter as left or right boundaries, you can directly pass the parameter as boundary values. In the below screenshot you can see that P_Server is the user defined parameter and it has been directly passed as the Left Boundary.


When you want to pass the Correlation parameter as left or right boundaries, you have to pass the parameter as boundary values using lr_eval_string function only.. In the below screenshot you can see that P_Server is the correlation parameter and it has been as the Left Boundary using lr_eval_string function.



Loadrunner Analysis Error - The SQL query produced by the analysis server is invalid.

 Error - Below error message pop up appears after some percentage of progress, when we try to open the Controller test results in Analysis engine.


Solution - This error is due to the high disk space utilized by the old analysis reports. So we have to delete or move the old reports to a different location and then try opening the results in the Analysis engine again. This time it will be successful.

C Program to extract string from the body of the mail using left and right boundaries - MAPI protocol

MAPI mapi = 0;

Action()

{

long logfile;

long fromfile;

char *CStr; //variable in which the response header will be saved

char *LB = "personal "; //Left Boundary of Session ID

char *RB = "until "; //Right Boundary of Session ID

char *CorrParam = NULL; //variable in which Session ID will be saved

char *start, *end;

 

int rc;

int loopTime;

int loopCount;

char * szSubj; 

int iCmpResult;

int ifromResult;

int iEmailCounter = 0;

char * szMyHost; 

char * message;

char * fromid;


//Logon to Exchange with proper credentials 

mapi_logon_ex(&mapi,"Logon", 

"ProfileName=Outlook",

"ProfilePass=",

LAST);

 

lr_think_time(5);

lr_start_transaction("MAILING");

loopTime=0;

do {

mapi_set_property_sz_ex(&mapi,"Message ID", ""); 

loopCount =0;

lr_output_message( "Never Loop");

// Preview all mails in Mailbox

do {

// Peek at next mail (don't mark it as read) 

rc = mapi_read_next_mail_ex(&mapi,

"NextMail",

"Show=all", // 

"Peek=True", // [Optional: default = False]

"Type=IPM",

"Save=body",

LAST); 


//Saving the mail content and from address to a C variable

message = mapi_get_property_sz_ex(&mapi,"Content");

fromid = mapi_get_property_sz_ex(&mapi,"From");


sleep (100);

loopTime++;

loopCount++;

if (rc != LR_PASS) break;

if (loopCount >=5) {

break;

}

 

 

//Obtains the subject & from address and compare with the expected subject & from address

szSubj=mapi_get_property_sz_ex(&mapi, "Subject");

iCmpResult = strstr(szSubj, lr_eval_string("{Subject}") );// check if email has a relevant SUBJECT

lr_output_message("the Subject of the mail is %s", szSubj);


fromid = mapi_get_property_sz_ex(&mapi,"From");

//ifromResult = strstr(fromid, lr_eval_string("") );

ifromResult = strstr(fromid, "Rudraraju, Madhusudhanaraju");// check if email has a relevant SUBJECT

lr_output_message("the from of the mail is %s", fromid);


if (iCmpResult != NULL && ifromResult != NULL) {

iEmailCounter++;

break;

}

 } while (rc == LR_PASS);

 if(iCmpResult !=NULL && ifromResult != NULL) {

break;

}

 } while ( loopTime < 900 );

 if (iEmailCounter != 0) {

//print the body property 

lr_output_message("the body of the mail is %s", message);


//String extraction using LB & RB

CStr = (char *)calloc(8000000,sizeof(char));

strcpy(CStr, message); //Save it to the C variable

if ( start = (char *)strstr( CStr, LB ) ) //Finds the first occurance of LB in CStr

    {

        start += strlen( LB );

        if ( end = (char *)strstr( start, RB ) ) //Finds the first occurance of RB in CStr

        {

            CorrParam = ( char * )malloc( end - start + 1 );

            memcpy( CorrParam, start, end - start );

            CorrParam[end - start] = '\0';

        }

    }

//Save the extracted string to a text file

if ((logfile = fopen("C:\\Users\\vinoth.srinivasan\\Desktop\\Email\\AuthCode.txt", "a+")) == NULL) 

{

return -1;

}

fprintf(logfile, "%s\n", CorrParam);

fclose(logfile);

if ((fromfile = fopen("C:\\Users\\vinoth.srinivasan\\Desktop\\Email\\AuthCodeFromID.txt", "a+")) == NULL) 

{

return -1;

}

fprintf(fromfile, "%s\n", fromid);

fclose(fromfile);

}

free( CorrParam );

lr_end_transaction("MAILING", LR_PASS);

mapi_logout_ex(&mapi);

return 0;

}



VB Script to delete a set of files based on file extension

There might be an instance that you will have to delete all the test data files at the end of each performance test run so that a fresh set of test data files can be created for the next run. Instead of doing this manually at the end of each run use this simple macro do it automatically for you.

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile("C:\Users\XXXX\Desktop\SoapTextFiles\*.txt"), DeleteReadOnly

Change the destination folder in the above code and your macro is ready. 

"*.txt" defines that any file with .txt extension will be deleted. 

For deleting files of a different extension replace ".txt" with you desired file extension. Say for example ".xls" to delete excel files.


How to Disable the outlook mail pop in LR Vugen MAPI Protocol

As we all know that MAPI protocol is used for performance testing of Mail boxes.When we run MAPI scripts to test outlook it establishes a connection with the defined outlook profile.After which we can send, read and delete mails.

When the MAPI script tries to read mail box, then Vugen throws a pop up (highlighted in the below image) seeking permission to access the Outlook address book.

So every time we have to click Allow button manually for the script to successfully execute and the same cannot be done when we are going to do a load test with that script.

This can be bypassed by changing the "Programmatic Access Security" settings under Trust Center in our Outlook.

In Outlook Goto File --> Options --> Trust Center --> Click Trust Center Settings --> Programmatic Access



Now select the option - Never warn me about suspicious activity (not recommended) and click ok.

Thats it. Now the Pop up seeking permission to access outlook address book from vugen will disappear when we run the MAPI script.