Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 37 ยท Concepts and Setup

Config Elements: Defaults, Headers, Cookies and Data Files

Use JMeter config elements to avoid repetition: HTTP Request Defaults, HTTP Header Manager, Cookie Manager, Cache Manager, User Defined Variables and CSV Data Set Config.

Config elements store settings that samplers inherit: the server name, shared headers, cookies, data files. They are how you avoid typing the hostname into 40 requests and how you make virtual users behave like real browsers. This lesson covers the ones you will use in nearly every plan.

Honesty note. JMeter cannot run here, so these are descriptions of settings and menu paths. The runnable blocks are stand-ins that imitate the merging rules (defaults, headers, cookies) so you can see the logic.

Add config elements through Add > Config Element. Remember the scoping rule from Test plan elements: a config element applies to samplers at or below its parent, and config elements run before everything else for a sampler.

HTTP Request Defaults

Instead of filling Protocol, Server Name and Port on every sampler, add HTTP Request Defaults once at Thread Group (or plan) level. Samplers then leave those fields blank. To test a different environment, you change one element, or better, use a variable:

  • Server Name: ${__P(host,staging.example.test)}
  • Protocol: ${__P(protocol,https)}

and start with jmeter -n -t plan.jmx -Jhost=qa.example.test. See Variables, properties and functions.

The defaults element also carries Implementation (Java or HttpClient4), connect and response timeouts, and the option Retrieve all embedded resources. Set timeouts here: with none, a hung server blocks threads forever and ruins your numbers.

A sampler's own non-empty field always wins over the default.

HTTP Header Manager

Many APIs need headers on every call: Content-Type: application/json, Accept, Authorization, an API key, a custom User-Agent that identifies your load generator. Add a HTTP Header Manager under the Thread Group and list the name/value pairs. If a manager also sits under a particular sampler, headers are merged and the more specific one wins on duplicate names.

A good practice is to send a recognizable header such as X-Load-Test: jmeter, so operations can filter or exclude test traffic from analytics and logs.

Browsers keep cookies; JMeter threads do not unless you add an HTTP Cookie Manager. Without it, every request looks like a new visitor, so session logins fail. With it, each thread has its own cookie jar, so users do not share sessions. Useful settings:

  • Clear cookies each iteration: tick to make every loop a new visitor (and in a Thread Group untick Same user on each iteration for related behaviour).
  • Cookie Policy: leave as standard unless the site demands otherwise.

Common mistake: adding a login request but no Cookie Manager, then wondering why the next page redirects to the login form.

HTTP Cache Manager

Real browsers cache static files. The HTTP Cache Manager simulates this per thread: with Use Cache-Control/Expires header when processing GET requests ticked, repeated GETs of cacheable resources are skipped or sent as conditional requests. Enable it when you load embedded resources, otherwise JMeter will hammer the server with images that real users would load from cache once.

User Defined Variables

Add User Defined Variables to name values you reuse, for example BASE_PATH=/api/v2 and PAGE_SIZE=20. They are evaluated once at test start and shared by all threads. Use them for constants only. For values that change per thread or per iteration, use the CSV element below, or the User Parameters pre-processor.

CSV Data Set Config

This is the star of data-driven testing. It reads a CSV file line by line and puts each column in a variable. Settings:

Field Meaning
Filename Path to the file, relative to the plan or absolute
Variable Names Comma-separated names, for example username,password
Ignore first line Skip a header row when names are given here
Delimiter Usually ,
Recycle on EOF? Start over after the last line (True), or stop (False)
Stop thread on EOF? End the thread when the file is exhausted
Sharing mode All threads, Current thread group, Current thread, or custom

With the default All threads sharing mode, every thread takes the next row, so 100 threads read 100 different rows. In the requests you write ${username} and ${password}. Parameterization in the next lesson builds on this.

A typical users.csv:

TEXT
alice,Test-Pass-1
bob,Test-Pass-2
carol,Test-Pass-3

Use only test accounts with throwaway passwords; never put production credentials in files that live in a repository.

DNS Cache Manager, Keystore Config and others

Other config elements you will meet: DNS Cache Manager (resolve names yourself or override the host for each thread), Keystore Configuration (client certificates), JDBC Connection Configuration (database pools), Counter (incrementing numbers) and Random Variable. Each is added the same way and scoped the same way.

Stand-in: how defaults, headers and cookies merge

The stand-in below mimics the merging rules with plain objects: sampler fields override defaults; headers merge with sampler-level ones winning; a cookie jar stores a cookie from one response and sends it on the next request of the same thread.

JS Stand-in: defaults and header merging

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Stand-in: per-thread cookie jars and a CSV data set

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Without the manager, both users are told to log in; with it, each gets its own session.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main purpose of HTTP Request Defaults?

    Defaults remove repetition and make switching environments a one-place change.
  2. 2. Why add an HTTP Cookie Manager?

    JMeter threads do not store cookies by themselves. The manager gives each thread its own cookie jar.
  3. 3. In CSV Data Set Config with sharing mode All threads, what happens when thread 1 and thread 2 both read the file?

    The file is shared, so every read moves to the next line, giving different values to different threads.
  4. 4. Which header practice helps operations teams identify load test traffic?

    A recognizable custom header lets teams filter test traffic from logs and analytics.

Summary

  • Config elements run first and apply to samplers in their scope.
  • Use HTTP Request Defaults for server, protocol, port and timeouts, with variables for environment switching.
  • Header Manager, Cookie Manager and Cache Manager make threads behave like real clients.
  • CSV Data Set Config feeds different data to each thread; use test accounts only.
  • A sampler's own non-empty value overrides a default.

Next: Variables, Properties and Functions