Beanshell script to handle Correlation Value "Not Found" equal to "ERROR" in Jmeter

 In Loadrunner we have an attribute in the correlation function which will fail the request/user if the correlation value "Not Found" is set to ERROR. But in the Jmeter we do not have any such straight forward approach and the same can be achieved using the below code in the Beanshell assertion. 

C_SAMLC_RelayState are the two correlations that has been done in a request and below code will check if they are null (Empty) and if that is true, it will fail the request.

Code to the Placed in Beanshell Assertion:

String SAML = vars.get("C_SAML"); //Save the correlation value to a string
String RelayState = vars.get("C_RelayState"); //Save the correlation value to a string
if (C_SAML != null && C_RelayState != null) //if condition to check if the value is not null
{
Failure = false; //if the value is null fail the sampler or request
}
else
{
Failure = true; //if the value is not null pass the sampler or request
}

Note: Make Sure to leave the Default value field as empty in the Boundary or RegEx extractor while using the above validation approach. 

Bean shell script to validate and use correlation values by setting the ordinal value to all.

Below is the bean shell script which will pick the store id if its stock level is in-stock.

Create two correlation parameters named C_StoreID    & C_StockAvail and get all their values from the response by setting Match.No = -1.

Now C_StoreID_matchNr is the jmeter variable which will have the total count of the store id's that we were found.

C_StockAvail will have three different values that are "in-stock" , "Limited", "out of  stock" and here we will use the "in-stock" value and get the stores associated with it.


Handling Parent request sampler failure due to redirect failures in Jmeter

Consider a situation in which your parent request is redirecting to lot of other requests and in that one of the redirected request fails. On analyzing using the developer tools you find out that that particular redirect is failing even manually. But the problem with Jmeter is that it will mark the Parent request as failed when one of the redirect fails and this has to be handled by validating only the response of the parent request, as this is not an issue with the script.

Most people will handle this by adding the response assertion and just enable the "Ignore status". But this approach is wrong, as this will make the parent sampler request "Pass" even if the parent sampler request itself fails.

The correct approach to handle this is, to validate the response code of the parent sampler request and ignore the status of the failed redirect request.

Add a Response Assertion to the request which is failing due to redirects and set the below options

Apply to         --> Main sample only

Field to Test         --> Response Code

Field to Test         --> Enable "Ignore Status"

Pattern Matching Rules --> Equals

Patterns to Test         --> Click Add & Enter '200'



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.