Different Doors In Apache JMeter
Jithin Somaraj
Senior QA Engineer | Specializing in Automation & Manual Testing | API Testing | Performance Testing | Expert in Enhancing Software Quality & Reliability
First of all this is my first ever article in the Linked in community. And I want to inform you that I'm not elaborating the content like the content creators usually doing on web to attract the readers. Here I writing my experiences which can be helpful for the fellow techies who is frustrated in JMeter in some way. Some of you may already knew this, Please correct me if there is any mistakes. And Let me take you to the good part.
In generally we can Perform a load testing in JMeter if we know the API parameters know properly. But the The problem occurring when we don't know that. As usual what we do is simply recording the feature and try to run with the Recorded data. It will be helpful to recognize the parameters but when we Try to run a test it will normally lead us to the failure. Not with all type of Applications I agreed. Today I want to share the two situations and I will share more later. The first one is that when we try to record and run a url or API which is run only by taking a particular value from the response of the previous one. For example if the result of API 1 is having a url like "https://abscd123456jkl.com" then the API 2 will only work if it passed the value"123456" from the above url. When it comes to bulk run we couldn't manage it by doing it manually so there is the problem arrives. Next one is the Solution.
The solution is we should use the Beanshell processor in JMeter so that by using it we can Extract the Response and filter it out. First we should extract the response with regular expression extractor and should filtered it out using the Beanshell Processor. I will attach a sample code below.
[url = vars.get("url");
file = new FileOutputStream("C:/Users/user/Desktop/apache-jmeter-5.4.3/user.csv", true); //specify true if you want to overwrite file. Keep blank otherwise.
p = new PrintStream(f);?
this.interpreter.setOut(p);?
print(token);
f.close();]
This will help to survive such situations. The Next Situation we stuck in Load Testing in JMeter is one that When we try to call API which is having a CSRF Token. Calling API's with authentication token from the response of login API feature is a little bit old these days. You will feel amazed and frustrated when you try to call API with all valid credentials and parameters and still it is not working. It is common when you try to call a CSRF token protected API's. It is working like a key. The key is different in each login. And also you may not get the CSRF Token from the login response it should be hidden. So what you want to do is that the Call in internal API in browser and inspect the page and you can find the CSRF from the Internal API values. Because the Internal API (create ,POST) couldn't called without the the CSRF token. So that Copy the CSRF value to the JMeter without making another Login Attempt so that you can successfully run it in JMeter. This all I want to say in this article. And I'm temporarily signing out......