How do I pass the Basic Authorization I get from the one-off Setup Thread Group to the main thread group - jmeter

I have only one user credentials and would like to simulate multiple users. I created a SetUp Thread Group to have HTTP Authorization manager and Beanshell Postprocessor (to carry forward the cookies to the main thread group which has a Beanshell PreProcessor to get this). But the first sampler in the main thread group is failing because the Authorization is not carried forward from Setup Thread group to the main thread. How do I get it to the main thread group?

A Cookie is a Header
Authorization header is not a Cookie
Therefore if you're copying only cookies it doesn't mean that the Authorization header is also copied.
HTTP Authorization Manager obeys JMeter Scoping Rules so if you move it one level up (to be at the same level with Thread Groups) it will be applied to both Thread Groups and generate the proper Authorization header for all the HTTP Request samplers in its scope.
P.S. Using Beanshell is a some form of a performance anti-pattern, since JMeter 3.1 users are advised to use JSR223 Test Elements and Groovy language

Related

JMeter - different HTTP request for different number of threads in the same thread group

I am load-testing a web application. I have recorded 5 different test scenarios using HTTP test script recorder under the same thread group.
I want to run the script with 5 threads, different thread for each request.
For Ex:
5 HTTP Requests in the same Thread Group.
5 Users. Different user for each HTTP request
1st user 1st HTTP request, 2nd user 2nd HTTP request... 5th user 5th HTTP request.
How to implement this. Any help would be much appreciated.
You can use Switch Controller for this and put __intSum() and __threadNum() functions combinatino as the "Switch Value"
This way each user will pick up the relevant Switch Controller's child:
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

How to clear cookies and cache in jmeter after each iteration?

The scenario is- After logging out from application either i have to close the browser or have to clear the cache in order to login with same user again, else browser will not give me login page and it will directly redirect me to post login.
When i am running my script from jmeter, its failing for 2nd iteration as its not able to find out the login page.
what needs to be done in jmeter for handling this scenario? i have added http cache and cookie manager in test plan.
I already tried
1.JSR223 Post Processor- sampler.getCacheManager().clear()
2.BeanShell PostProcessor- import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
manager.clear(); for all 3 requests of Logout transaction.
There is Same user on each iteration setting on Thread Group level.
If you untick it - both HTTP Cookie Manager and HTTP Cache Manager will be cleared when a thread (virtual user) starts new iteration. (only applies to Thread Group's iterations, controllers like Loop, Foreach, While, etc. won't be impacted)
If you want to proceed with scripting and copy-pasting the code without understanding what it's doing for JSR223 Post Processor the relevant code would be:
prev.getCacheManager().clear()
prev.getCookieManager().clear()
but make sure to place it as a child of the last HTTP Request sampler, see JMeter Scoping Rules - The Ultimate Guide article for more information on the impact of placement of JMeter test elements

How to use one access token generated for multiple users request in jmeter

I am working on jmeter for the First time. I am extracting the accesstoken and passing it on to other requests. but i am facing the issue that once I run it for 50 users the access token request is also running and becase of which other request is failing as new access token is generated and the request is failing to use that. I want to generate one access token for all the 50 request. I have tried keeping the request parted in two different thread groups.
enter image description here
#oshin, I am also new here but I will try what I did that might help yours too. I used JSR223 PreProcessor to get that access token and passed that in my other thread with another JSR223 preprocessor which reads that accesstoken. And passed that token in my header manager. See if this helps you.
Get token
Read access token in the following thread
Assign token to Header manager
Don't use Beanshell, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
Don't use scripting when something can be achieved using built-in JMeter Test Elements (or JMeter Plugins)
I would recommend:
Moving your "login" sampler under setUp Thread Group so it would be executed before the main thread group and only by 1 user
Storing the token into a JMeter Property via __setProperty() function
JMeter Properties are global and can be accessed by all threads in all thread groups so you will be able to use one token
Read the token using __P() function where required.

JMeter multiple header manager issue

I'm creating a record using post method from one user & verifying record with another user using Get method so for this I need 2 different tokens so what I did that I have used one Header Manager at the thread level & another Header Manager at HTTP-Request level now problem is that when I am running this Get API will get called & in the request header token of both user is getting passed. Can anyone know how to handle this?
If you need separate Header Manager per HTTP request, put each Header Manager under each HTTP request and not on thread level so it only affect the relevant request
HTTP Header Manager obeys JMeter Scoping Rules, so if you place it at the same level as Samplers - it will be applied to all Samplers.
If you add a HTTP Header Manager as a child of the Sampler - it will be applied to that Sampler only.

Jmeter - HTTP Headers

I recorded a web page using JMeter which has produced several samplers. Each of those samplers (http request) has a config HTTP Header Manager. Is it really necessary to have that for each sampler or can I just maintain one at the thread group level. Of course some of those Headers have referer header element and some don't.
You don't need one header per request, unless each request need a unique header.
You may not even need ONE at the threadgroup / test plan level, unless you are wanting to specify header information.
When you record, there is a checkbox in the HTTP Proxy to toggle capturing these.
It is enough one Header Manager per Thread. See documantation http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Header_Manager

Resources