I am trying to simulate a parallel ajax requests using a JSR223 sampler, as mentioned here https://www.blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter
But for my set of requests ,I am getting an error,Invalid API/Auth Key
I assume it is is becuase the authentication cookie is not being passed ,I tried to grab the cookie from the previous sampler using
HTTPSamplerProxy previousSampler = ctx.getPreviousSampler();
CookieManager cookieManager = previousSampler.getCookieManager();
HTTPSampleResult previousResult = (HTTPSampleResult)ctx.getPreviousResult();
log.info("Cookie Count is : "+ cookieManager.getCookieCount());
But I get the error
Cannot invoke method getCookieCount() on null object
,I do have the cookie manager enabled in my test plan.
Any help on what I am doing wrong would be great .
The error you're getting means that there is no HTTP Cookie Manager associated with the sampler. You need to add it to your Test Plan and your code should start working as expected.
Be aware that as of now there is a much easier way to implement AJAX requests without having to do any coding, there is Parallel Controller which can be used to mimic AJAX calls by running its children in parallel. Just add it to your Test Plan and move HTTP Request samplers which represent AJAX calls under it. See How to Use the Parallel Controller in JMeter for more details if needed.
Related
Problem Statement: In my application there is a token which is unable to generate it from the api call directly and other way because the it is implemented with OAUTH. So I took a detour and automate it through API. by using Webdriver sampler. with following script.
WDS.sampleResult.sampleStart()
WDS.browser.get('appurl');
java.lang.Thread.sleep(10000);
WDS.browser.findElement(org.openqa.selenium.By.id("details-button")).click();
WDS.browser.findElement(org.openqa.selenium.By.id("proceed-link")).click();
WDS.browser.findElement(org.openqa.selenium.By.id("i0116")).sendKeys("username"); //enter user name and password in login.microsoft.com
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
WDS.browser.findElement(org.openqa.selenium.By.id("i0118")).sendKeys("password");
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
//WDS.sampleResult.sampleEnd()
This works fine and I am able to retrieve the token by using regex extractor.
Using the Token in API Call and getting retry error
JMeter Failure (getting IO error exceeded number of retry =, tried with 20, 50 ,200 and now 500)
Browser:
Suspecting the session id may be I am not transferring or is there anything I am missing (remember I am not terminating the browser session)
If I would be in your shoes, I should go with Dmitri answer. But we had a similar issue recently and we were sending JSessionId and Dead-SessionId in the cookie. We resolved by doing following
Add a Http Cookie manager to your test plan.
In the UI sampler please add the sample code,
WDS.vars.putObject('sessionCookies', WDS.browser.manage().getCookies())
Add a JSR223 PreProcessor to your Http request with following script
vars.getObject('sessionCookies').each { scookie ->
sampler.getCookieManager().add(new org.apache.jmeter.protocol.http.control.Cookie
(scookie.getName(),
scookie.getValue(),
scookie.getDomain(),
scookie.getPath(),
scookie.secure,
System.currentTimeMillis() + 10000))
}
In our case we were not sending the expiry which was giving us
ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTime() on null object at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.3.jar:3.0.3]
So we replaced cookie.getExpiry().getTime() with System.currentTimeMillis() + 10000
I think you need to copy the cookies from the browser to the HTTP Request sampler
Add HTTP Cookie Manager to your Test Plan
Add the next line to your WebDriver Sampler code:
WDS.vars.putObject('cookies', WDS.browser.manage().getCookies())
Add JSR223 PreProcessor as a child of the HTTP Request sampler where you want to copy the session from the UI and put the following code into "Script" area:
vars.getObject('cookies').each { cookie ->
sampler.getCookieManager().add(new org.apache.jmeter.protocol.http.control.Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.secure, cookie.getExpiry().getTime()))
}
That's it, the HTTP Request sampler should send the cookies now and you should be authenticated
More information on manipulating cookies with Groovy code: Modifying Cookies in JMeter with Groovy
I am using the HTTP request sampler, In which I have used Post Method.
When I Execute the request, it executes the another HTTP request from another thread.
I want to extract the data from that thread because that HTTP request contains the transaction id and I want to use that transaction id in other threads.
The said transaction id is only showing in the pop up message.
Kindly help me.
Solution for the first problem retrieving data from request URL i.e.transaction id using a postprocesser, you can refer the following thread,
Post processer for extracting a value from the URL in the request method.
Solution for the second problem passing the variable from one thread to another,
You need to add a beanshell assertion and set it a property variable like ${__setProperty(transaction_id, ${transID})}
In the second thread group add a preprocesser and accept the property variable.
String tid= props.get("transaction_id");
vars.put("TID",tid);
Thread1:
Thread2:
JMeter can only extract data from response body, message, code, headers, or URL.
If you send the request which triggers another request and the data you're looking for is not in the 1st request response scope - unfortunately you won't be able to get it.
The only option I can think of is using WebDriver Sampler which provider JMeter integration with Selenium browser automation framework so you would be able to execute the request and get the data from the popup using real browser.
WebDriver Sampler can be installed using JMeter Plugins Manager
I have a login form that has form method set to POST, form-action set to a servlet, and an OnSubmit function to check the field data.I want to performance test a file download funcitonality that lies behind this login form. To acheive this i am running a parallel sampler to login and then download the file.
The first sampler is for the login and the second one is to dowload the file.
In the first sampler, I want to POST data on this form using JMeter's HTTP Reqest Sampler.
I have inspected the form and created a sampler with three parameters, the username, the password and one more non-discloseable field. I have set the path to the servlet since it is the one handling the requests for the form.
The post request doesn't do anything in this case.
What should i do or check or modify to make sure that the POST request is hitting the correct endpoint and that it actually submits the form data.
You need the samplers to be sequential, I think if you attempt to download the file without prior logging in - the request will fail somewhere somehow.
If it is not sufficient and you would like to add an extra level of checks, i.e. test that the endpoint returns anticipated response code or has certain text you could add Response Assertion as a child of the request and add pass/fail criteria there.
If you don't know how to properly build login and download requests, the easiest way is just recording them using HTTP(S) Test Script Recorder, JMeter will capture the requests and generate relevant HTTP Request samplers and HTTP Header Managers
I'm facing a problem when writing a JMeter test plan.
The goal is to test an OpenXava based application.
I perform the request with firefox then I try to copy the headers, parameters and cookies in my HTTP request sampler (thus in JMeter).
There are a lot of parameters (36) sent when trying to login. I copied all of them.
However, I can't make it work.
The HTTP response seems useless. It's nearly the same I get when sending a wwrong password with Firefox :
throw 'allowScriptTagRemoting is false.';
//#DWR-INSERT
//#DWR-REPLY
var s0={};
dwr.engine._remoteHandleCallback('1','0',{application:"bdsa",changedParts:null,currentRow:-1,dialogLevel:0,dialogTitle:null,error:null,focusPropertyId:null,forwardInNewWindow:false,forwardURL:null,forwardURLs:null,hideDialog:false,module:"SignIn",nextModule:null,propertiesUsedInCalculations:null,reload:true,resizeDialog:false,selectedRows:null,showDialog:false,strokeActions:s0,urlParam:null,viewMember:"",viewSimple:false});
Do you have a clue about what is happening ? Should I try to test the login page with another method ?
Why don't you just record your flow using JMeter's HTTP(S) Test Script Recorder and your browser.
Set up JMeter Proxy Server
Set up your browser to use JMeter as the proxy
Perform the test scenario in the browser - JMeter should capture the requests under the Recording Controller
Perform correlation if required. If your application is deployed in the Internet you might get benefit of cloud-based proxy service which can perform automated detection of dynamic parameters and generating the relevant code to extract the values and substitute recorded hard-coded parameters with the variables
Don't forget to add HTTP Cookie Manager to your Test Plan - it deals with cookies and cookie-based authentication
How to use JMeter with ajax request?
I have a button with is clicked and by using fiddler I can find the session id which is being sent to the server.
What should I do next using the JMeter in order to handle this.
EDIT:
Let's say I have in my hand the header which call the request. The JSESSIONID AJAXREQUEST
and so on where should I put it ?...
I putted it in http header manager name and value.
Jmeter will not execute Javascript embedded in your web page. However AJAX request is also a HTTP request that Jmeter will be able to run as a separate HTTP request and upon getting the response you can have post processors (using XPATH or REGEX) to extract the session id in a Jmeter variable.
Alternatively you can record the Jmeter scripts using Jmeter proxy and then all the HTTP requests will be recorded for you and you will just need to attach a post processor manually.