0
votes

I want to test rest service thorough Jmeter, I have tested Rest call using postman and its working fine. thing is to run rest service from any client like postman, I need to login to my application first in browser and after login rest call will work in RESTClient(Firefox). But in case of Jmeter how to run then. I have added authorization. (Username and password) using HTTP Authorization manager still facing. Even I have added bean shell script bellow:

import org.apache.commons.codec.binary.Base64;

byte[] encodedUsernamePassword = Base64.
           encodeBase64("harshal.shewale1@viewics.com:Harshal@1".getBytes());
vars.put("base64HeaderValue",new String(encodedUsernamePassword));

Still not running rest. Giving error as a Bad credentials.

Someone please guide me.

2
can you show your plan ?UBIK LOAD PACK
I hope this is not your real username and password...Kiril S.

2 Answers

0
votes

You're making things overecomplicated. JMeter comes with HTTP Authorization Manager which automatically adds the relevant "Authorization" header basing on username/password combination you provide

HTTP Authorization Manager

See How to Use HTTP Basic Authentication in JMeter guide for details.


There are no problems with your Beanshell code.

-1
votes

You might be having cookie issue in this case. So add cookie manager to your test plan. Compare the rest call you are making from Firefox and rest call you are making from are similar. Check cookies and headers and try to mimic the same for you rest call.

You can use following approach:

  1. Create a thread group.
  2. Add once only controller. Add login request under this controller.
  3. Add rest service call after once only controller.

In this way if there are any cookies the rest call expects will be passed and your script should work.