Friday 14 December 2018

Jmeter - Pass HTTP failed request

While testing negative test cases with Jmeter, it is required to PASS the FAILED HTTP requests. This can be achieved by 2 ways.

  • You can use the Beanshell/Groovy code.
  • You can use the Response Assertion.(looks easy to me)
Here, I will show you how to use Response Assertion to pass the failed HTTP requests.

In case, you want all the HTTP requests to be PASSED, you can use only single Response Assertion in your script. However, if there are cases where some of the HTTP requests, if they get fail, should be marked as FAILED out of many HTTP requests. In that case, you should use Response Assertion element as child of each HTTP request for which you want to mark it PASSED.

Response Assertion can be found here



In order to PASS the FAILING requests, you have the enable the 'Ignore Status' checkbox of Response Assertion element and then use it accordingly. See below screenshot.


Without Response Assertion


With Response Assertion


Response Assertion for Single HTTP request.




Tuesday 4 December 2018

Handle Dynamic body in Jmeter

The below beanshell code can handle dynamic body of the JMeter requests when used in beanshell preprocessor.


   import org.apache.commons.io.FileUtils;
    int countRoom = Integer.parseInt(vars.get("countRoom"));
    int countChild = Integer.parseInt(vars.get("countChild"));
    String FinalString = "";
    int agecounter = 0;
    List linesChildAge = FileUtils.readLines(new File(vars.get("ChildAgeCsv")));
    List linesRoomAdult = FileUtils.readLines(new File(vars.get("RoomAdultCsv")));
    
    for (int i = 0; i < countRoom; i++) {
    String Adult = linesRoomAdult.get(i);
    FinalString = FinalString + "\r\n          <room adult=\"" + Adult + "\">";
   
    for (int i = 0; i < countChild; i++)
    {
    String Age = linesChildAge.get(agecounter);
    agecounter++;
    FinalString = FinalString + "\r\n               <children>\r\n                    <child age=\"" + Age + "\"/>\r\n               </children>";
    }
    FinalString = FinalString + "\r\n          </room>";
    vars.put("FinalString", FinalString);
    }











Note: If you want my script, drop me an email on rahul225sharma@gmail.com.

Set path environment variable via Powershell

The below code can be used to append path environment variable.

Param 
      (
                  [Parameter(Mandatory=$false)]
                  [System.String]
                  $pathtoAppend = "C:\Tools\java\bin"
        )
$env_Path = [Environment]::GetEnvironmentVariable("Path","Machine")
$finalPath = "$env_Path;$pathtoAppend"
[Environment]::SetEnvironmentVariable("Path",$finalPath ,"Machine")

In the similar way, you can set/Append any environment variables in windows.

Set browser Proxy Script via command prompt

Proxy script is a way to define different Proxies for multiple URL's. In normal cases, you can only define a single proxy in the browser, from where you want the browser traffic to be routed. However, this method fails when you want to use multiple proxies (for some URLs) and no-proxy for other URLs. Hence, PROXY script is helpful in such scenarios.


The below commands can be used to set proxy script in browser for windows.



Via powershell command


Set-ItemProperty -Path 'HKLM:Software\Microsoft\CurrentVersion\Internet Settings' -Name AutoConfigURL -Value 'C:\proxyscript.pac' 


Via windows command prompt


REG ADD "HKLM:Software\Microsoft\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "C:\proxyscript.pac" /f


Note: you can use the URL of the proxy script(if you have) in the above commands instead of local path.

Friday 7 September 2018

Testing PEGA application with JMeter


While testing PEGA application with JMeter, I came across an error where login functionality was not working properly. System was returning 500 response code.
All the parameters in the request were correct. HTTP Cookie manager was also added in the Jmeter script to manage sessions but somehow, the script was not working properly.

After trying many tricks, what works for me is changing cookie policy to “netscape”. This can be changed from HTTP Cookie manager. Please find below the screenshot.

 



In case, netscape is not working for you. Please try the other options in the drop-down.

Also, one needs to take care of “HarnessID” & “pzTransactionID” parameters while working on PEGA application. These parameters have to be correlated properly otherwise your scripts would not work fine. There were other parameters (in my case) which do not require any correlation. e.g. ContainerID, DynamicContainerID.

Saturday 18 August 2018

Jmeter - Capture multi-line(more than one line) value using regular expression extractor.

In case, you are familiar with any load testing tool, you must be aware of the correlation concept. The soul purpose of correlation is similar in all the tools; however, the implementation is somewhat different. In load runner, we have web_reg_save_param() function which requires left bound and right bound. Load runner also provides an option to use regular expressions to fetch values. Whereas, in Jmeter, we have an element "Regular expression extractor"  which can be used to extract data.

Creating a regular expression when one has to fetch data from a single line is somehow easy. However, it gets tricky when multiline values have to be extracted.

Solution - You need to use (?ms) before your regular expression in order to match multi-line values. Here, ms means multi select.

Go through the below example for more details.

Text to select


Using normal regular expression


Using multi-select 



Saturday 21 July 2018

HTTP Request to send multiple text Files using ${__FileToString()}

While working on Jmeter, we often came across situations where multiple files have to be sent to server as an attachment with the HTTP request.

In case, where a single file to be sent to server, below function works fine.

${__FileToString(C:\Users\user\Downloads\data.csv,,)}

However, in case of multiple files, one needs to work in the below manner.

Create a csv with all the file names. See below


Add a CSV Data Set config

The final HTTP request would look like


${__FileToString(C:\Users\XXX\Desktop\Final_Scripts\\${__V(filename)}.txt,,)}

Some people claim that ${__eval()} works with multiple/dynamic files. However, this did not worked for me. Hence, I used ${__V()}.

Don't forget to use double slash(\\) before the ${__V()} function.