You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JMeter测试计划结构咨询:50用户登录后并行执行HTTP请求

Alright, let's walk through building a JMeter test plan that perfectly fits your authentication and workflow requirements. I'll break this down into clear, actionable components so you can replicate it easily:

JMeter Test Plan Design for Authentication & Multi-API Initialization Workflow

1. Core Test Plan Setup

Start with the foundational elements to handle your 50-user dataset:

  • Add a Thread Group: Set the number of threads to 50 (one per user), adjust ramp-up time based on how quickly you want users to start (e.g., 10 seconds for gradual load), and set loop count to 1 (so each user runs the workflow once).
  • Add a CSV Data Set Config (as a child of the Thread Group) to feed user credentials:
    • Filename: Path to your CSV file (e.g., ./user_credentials.csv)
    • Variable Names: Define names matching your CSV columns, like username, password
    • Configure "Recycle on EOF" to False and "Stop thread on EOF" to True—this ensures each user is used exactly once.

2. Fetch the Session Data Key

First, we need to grab the sessiondataKey from the login page:

  • Add an HTTP Request for the login page (usually a GET request):
    • Enter the login page URL and ensure the method is set to GET.
  • Add a Regular Expression Extractor (child of this request) to capture the key:
    • Reference Name: sessionDataKey
    • Regular Expression: Tailor this to how the key appears in the response (e.g., <input type="hidden" name="sessiondataKey" value="(.+?)" /> for HTML forms)
    • Template: $1$
    • Match No.: 1 (captures the first occurrence of the key)
      Pro tip: Use the View Results Tree listener to inspect the login page response and refine your regex if needed.

3. Login with Session Key & Credentials

Next, send the login request with the required headers and user data:

  • Add an HTTP Request for the login endpoint (typically a POST request):
    • Enter the login API URL and set method to POST.
  • Add an HTTP Header Manager (child of this request) to include the session key and any required content headers:
    • Add a header like sessiondataKey: ${sessionDataKey} (uses the extracted variable from step 2)
    • Include content type headers, e.g., Content-Type: application/x-www-form-urlencoded (for form data) or application/json (for JSON bodies)
  • Configure the request body/parameters:
    • For form data: Use parameters like username=${username}&password=${password}
    • For JSON: Use a body like {"username":"${username}","password":"${password}"}
  • Add a JSON Extractor (child of the login request) to capture the authorization token:
    • Reference Name: authToken
    • JSON Path Expression: Match your response structure (e.g., $.authorization_token or $.token)
    • Match No.: 1

4. Trigger the Initialization Request

After logging in, run the initialization request:

  • Add an HTTP Request for the initialization endpoint:
    • Set the correct method and URL.
  • Ensure your HTTP Header Manager (can reuse a group-level one or add a request-specific one) includes the authorization token:
    • Add Authorization: Bearer ${authToken} (adjust the prefix if your token uses a different scheme like Basic).

5. Simulate Concurrent XHR API Requests

Since the site fires multiple API calls post-initialization, use a Parallel Controller to mimic this behavior:

  • First, install the Parallel Controller via the JMeter Plugins Manager (it’s essential for simulating concurrent requests).
  • Add the Parallel Controller as a child element right after the initialization request.
  • Inside the Parallel Controller, add individual HTTP Request elements for each XHR API endpoint:
    • For each request, attach an HTTP Header Manager (or use a shared one) that includes Authorization: Bearer ${authToken}
    • Configure each request’s method, URL, and parameters to match the actual API specs.

6. Optional: Add Listeners for Result Analysis

Include these listeners to track test performance and debug issues:

  • View Results Tree: Great for debugging (disable this in production test runs to save resources)
  • Summary Report: Provides aggregated metrics like response times, error rates, and throughput
  • Response Times Graph: Visualizes response time trends over the test run

Quick Best Practices

  • Scope Matters: Ensure extractors are children of the request they’re extracting from, and Header Managers are scoped to apply to all relevant requests (Thread Group level for global headers).
  • Validate Variables: Use the Debug Sampler to check if sessionDataKey and authToken are being captured correctly before running full load tests.
  • Handle Dynamic Content: If there are other dynamic values (like CSRF tokens), add additional extractors as needed.

内容的提问来源于stack exchange,提问作者Nirmal Dholakiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:14:14