Automated VB script to check the web application status and send mail to stakeholders when app is down

 VB script code:

Dim waittime : waittime = 60000

do

Set objOutlook = CreateObject("Outlook.Application")

set objMail = objOutlook.CreateItem(0)

Dim strWebsite

strWebsite = "vnothperformancetesting.blogspot.com"

MailSubject = "Application Status on" & " " & Now & " is down"

If PingSite( strWebsite ) Then

    WScript.Echo "Application" & strWebsite & " is up and running!"

Else

    WScript.Echo "Application" & strWebsite & " is down!!!"

objMail.Display

objMail.To = "katXXXu@gmail.com"

ObjMail.Recipients.Add("katXXXu@gmail.com")

objMail.cc = "katXXXu@gmail.com"

objMail.Subject = MailSubject

objMail.Body = "Hi, Ping status to application shows that application is Down!. Pls look into it."

objMail.Send

objOutlook.Quit

set objMail = Nothing

Set objOutlook = Nothing

End If

WScript.Sleep(waittime)

loop

Function PingSite( myWebsite )

    Dim intStatus, objHTTP

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    objHTTP.Open "GET", "http://" & myWebsite & "/", False

    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

On Error Resume Next

objHTTP.Send

intStatus = objHTTP.Status

On Error Goto 0

If intStatus = 200 Then

PingSite = True

Else

PingSite = False

End If

Set objHTTP = Nothing

End Function

Blazemeter execution failing with "Test Configuration Error"

Error: 

On running a Blazemeter test, test got stopped with the below error message in the screenshot.


On checking the bzt.log file, the following error message was seen in the log 

Aug 17, 2022, 4:44:04 AM[system][r-v4-62fca9eab948b393945869]File /tmp/artifacts/taurus-base-config.yml not found on disk

Solution:

Check the length of the Jmeter script / .jmx script file name and reduce it. 

Example: If the current file name is "01_Scenario_01_Tab_Navigation_All_Dashboard.jmx", then reduce the length of the file name "01_Scenario_Tab_Nav_Dshbrd.jmx"

Replace a part of the string in Jmeter

 There will be instances where we will have to replace a part of the correlation string and pass it on to subsequent request in Jmeter. This can be achieved in 2 methods. 

Actual Correlation Output: C_SID = Hello&#x2dWorld

Expected Correlation Output: C_SID_R = Hello-World

Method 1: Using the existing "__strReplace" function from "Custom JMeter Functions" Plugin.

Install the "Custom JMeter Functions" Plugin from plugins manager and restart the Jmeter.

Syntax: ${__strReplace(InputString,To Be Replaced,To Replace,OutputString)

Code : ${__strReplace(${C_SID},&#x2d,-,C_SID_R)



Method 2: Using a Beanshell sampler

Code:

String a = vars.get("C_SID");

String b = a.replaceAll("&#x2d", "-");

vars.put("C_SID_R",b);



Print Date and Time parameters to a text/csv file in Jmeter

 Below is code to print Date and Time parameters to a text/csv file in Jmeter


String Date = vars.get("${__time(MM/dd/yyyy,currentDate)}");

String Time = vars.get("${__time(hh:mm:ss,currentTime)}");

String Date = vars.get("currentDate");

String Time = vars.get("currentTime");

log.info(Date);

log.info(Time);

f = new FileOutputStream ("C:/[FilePath]/Timestamp.txt",true);

p = new PrintStream(f);

this.interpreter.setOut(p);

print(Date+","+Time);

f.close();

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'