I've got a URL with following format, I'm not quite sure how to generate this URL after "# " using an HTTP request using Jmeter, Any pointers would be highly appreciated.
${url}}/a/?case_type_category=cases#/case/list?cf={"case_type_category":"cases","case_manager":[2]}
Just put everything into "Path" field of the HTTP Request sampler and JMeter will parse it
You don't need to construct URLs manually, they can be recorded using HTTP(S) Test Script Recorder or JMeter Chrome Extension
See URL.hash MDN documentation chapter for more details
Related
I am trying to upload a sound to myinstants.com using java and OkHttp.
I used the Chrome dev tools to look at what requests get made and try to recreate them using OkHttp but I'm failing at the login part.
Chrome dev tools tells me that this is the form post, with a content-type of application/x-www-form-urlencoded.
And I try to replicate the post using the following code:
RequestBody loginBody = new FormBody.Builder()
.add("csrfmiddlewaretoken", token) //this token is comes from inside the <input> tag that is retrieved in the HTML of a normal get request to https://myinstants.com/accounts/login and is diffrent every time you load the page
.add("login", username)
.add("password", password)
.add("remember", "on")
.add("next", "/new/")
.build();
Request login = new Request.Builder()
.url("https://www.myinstants.com/accounts/login/?next=/new/")
.addHeader("cookie", CookieHandler.getCookie()) // cookie that is generated from the "set-cookie" response headers of the get request to https://myinstants.com/accounts/login
.addHeader("content-type", "application/x-www-form-urlencoded")
.post(loginBody)
.build();
Response response = new OkHttpClient().newCall(login).execute();
According to the chrome dev tools, the response of the above post request should have a couple of set-cookie response headers, but they are not present for me.
I don't think the issue is with the cookie I'm using because when comparing to what is found in the chrome dev tools, the cookie matches that exaclty (except for some things that are new every time you visit the site), so I think the issue is with the form post. Any ideas what I am doing wrong?
Some servers block the requests if they see you're making the requests from outside a browser.
What often works (but not always) is to try tricking the server into thinking you're using a browser. You can do this by setting the "User-Agent" header.
To do so, open the dev tools of your browser (F12), access the "Network" tab and make a request to any site. Then, look into the "Request Headers" section for the "User-Agent" value. Just copy it and send it with your request.
If all this fail, it's possible that the site has a bot protection based in Javascript. In this kind of site, the login page contains a javascript that triggers right before the login process and generates a random token that you need to send along with the credentials in order to login successfully. Since you're accessing without a browser, you can't run JavaScript and thus, you can't generate this token.
If that's the case, the best thing you can do is to use a real browser controlled programmatically. For Java you can use Selenium, but I personally prefer to use Puppeteer from NodeJS. In essence they're the same thing, an API to remote control a modified version of the chromium/chrome browser.
But with Puppeteer you have a little more flexibility than with Java because you don't need to convert between Java and Javsacritp objects and vice-versa.
I don't know what may be wrong and I don't have time to test your code now. But as a suggestion, you could try to make the upload using another library and see if it works.
I recommend Apache Fluent API:
https://mvnrepository.com/artifact/org.apache.httpcomponents/fluent-hc
I"M practicing JMeter performance testing using this website. There is username, password field and login button.
How to know the username URL, password URL and login action URL which need to supply to POST method in JMeter?
You can obtain the request curl using any proxy tool or simply using "inspect" feature on your browser.
From the curl, you can easily generate the jmeter script you want.
Use your browser's "inspect element" feature.
Request URL - https://www.phptravels.net/demo/account/login
Request Method - POST
Form Data
username - username
password - password
The easiest way of building a web test plan is just recording it using JMeter's HTTP(S) Test Script Recorder
From JMeter's main menu choose File -> Templates -> Recording and click "Create"
Open HTTP(S) Test Script Recorder and click "Start"
Locate ApacheJMeterTemporaryRootCA.crt file in "bin" folder of your JMeter installation and add it to your browser.
Amend your browser proxy configuration to look like
Execute your test steps in browser
JMeter should capture the requests and generate the relevant HTTP Request samplers under the Recording Controller
The alternative way of recording a JMeter test is using JMeter Chrome Extension, in this case you will not have to worry about proxies and certificates.
I'm trying to do a rest call which has the query params like:
https://www.tutorialspoint.com/?hasName=true
I have to set hasName=true in Jmeter. I'm getting a 500 and I do have JSON data that I want to post at the same time. If I set the parameters using the parameter tab then I can't update JSON data in the body data. How can I do both things at same time? I tried adding user defined variables and it did not work.
You can set in HTTP Request the JSON in Body Data tab and put full URL in Path field
https://www.tutorialspoint.com/?hasName=true
As a special case, if the path starts with "http://" or "https://" then this is used as the full URL.
Do a successful request in the browser or any other tool and compare the request you're sending through jmeter. Check everything including request urls, cookies, headers etc. If you think its all exactly the same. Reach out to the server admins/app devs to check the web server/application logs to find out what is wrong either in server or your request.
The 500 Internal Server Error is a very general HTTP status code that
means something has gone wrong on the website's server, but the server
could not be more specific on what the exact problem is.
I am not able to capture POST request payload which is sent by chrome browser for forms.
I have tried Browser mob proxy but it only captures in har file the request url, response code but not request payload.
I want to validate the request payload via java or selenium or any automation script and not via manual verification.
Any suggestion will be helpful.
As browser mob only captures request url and response status but not payload data. I stopped using browsermob.
I used Fiddler instead which worked perfectly for me. The only problem was unlike browser mob I had to install Fiddler application in my system for which I had to approached to my superiors for permissions for fiddler installation.
I have recorded a script and running it. But I'm receiving the following error.
HTTP Status 405 - Request method 'POST' not supported in jmeter
I'm not sure whether it is script issue or coding issue.
Our application is installed on HTTPS but security certificate not yet installed.
Could any one please help me out.
It could be one of below
The endpoint you are requesting is not supported for POST, It may support only GET, Please change the method in Jmeter to GET or the method your url supports
The endpoint may expect proper CSRF token. It might mismatch with one you recorded. So Please extract CSRF token from previous request's response and use it. You can do via RegEx Extractor in Jmeter.
JMeter does support POST method so it may be due to:
Endpoint you're using doesn't support POST method (it expects other method(s) like GET, PUT, DELETE, etc.)
You're sending not properly configured request.
The most common reason is missing relevant Content-Type header. You can use HTTP Header Manager in order to send the relevant Content-Type header which is usually application/json for REST or text/xml or similar for SOAP.
See Testing SOAP/REST Web Services Using JMeter article for more information on API testing using JMeter.
You can also consider the following approach:
Use specialized Web Services testing tool like SoapUI or RESTClient to fire a request
Either use aforementioned tool or 3rd-party sniffer like Wireshark to capture the request
Configure JMeter to send exactly the same request