当Authorization在Setup Thread组中时,仅获取Authorization的部分值就是获取Thread组下的请求

问题描述 投票:0回答:1

我面临以下问题

我已经捕获了登录请求的授权部分,其中包含一堆值并保存到 CSV 文件中并传递给以下请求。

这是测试计划

访问令牌 CSV 文件

设置线程组

Include Controller( Login test Fragment)

线程组

Requests

 Header Manager - has Authorization

问题:当对主线程组下的请求运行上述命令时获取部分值,即授权:{“userId”:5739之后没有捕获其余的值,如果您观察到我提到了文件编码:UTF-8,那么在之后应该不会有问题,也应该拾取其余的eth值。尝试过共享模式:所有线程都不起作用。

但是当我将包含控制器(登录测试片段)移至主线程组下时,它可以工作 Access Token CSV config When Login is in Setup Thread group Main Thread group HTTP Header Manager Authorization

尝试使用 JSR2233 PreProcseer 标头通过授权,但不幸的是仍然通过了截断的授权

import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import java.nio.charset.StandardCharsets;

 
// Read the entire line from the CSV file
String authorization = vars.get("captured_login_responsebody_admin");

if (authorization == null || authorization.isEmpty()) {
    log.error("Authorization is missing or empty!");
} else {
    log.info("Authorization  from CSV: " + authorization);
    
    // Ensure the sampler is an instance of HTTPSamplerBase (which it should be for HTTP requests)
    if (sampler instanceof HTTPSamplerBase) {
        // Add the Authorization header
        sampler.getHeaderManager().removeHeaderNamed("Authorization");
        sampler.getHeaderManager().add(new Header("Authorization", authorization));
        log.info("Authorization header set: " + authorization);
    } else {
        log.error("Sampler is not an instance of HTTPSamplerBase!");
    }
}
jmeter
1个回答
0
投票

如果您提取的值包含逗号,您将需要:

  1. CSV 数据集配置
    中将“允许引用数据”设置为 True

    enter image description here

  2. 以某种方式在值周围添加引号,并如果字段包含引号,则添加另一个引号

© www.soinside.com 2019 - 2024. All rights reserved.