另一个请求输入参数的 Jmeter 响应令牌

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

如何从第一个请求中获取令牌并在第二个请求中使用它

 HTTPSampler httpAuth = new HTTPSampler();
 httpAuth.setDomain( baseUrl);
 httpAuth.setPort(443);
 httpAuth.setPath("/permissions");
 httpAuth.setMethod("GET");
 httpAuth.setName("HTTP Request One");
 httpAuth.setProtocol("https");
 httpAuth.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
 httpAuth.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
java jmeter
1个回答
0
投票

您需要为此添加合适的后处理器,例如正则表达式提取器

类似:

HTTPSampler httpAuth = new HTTPSampler();
httpAuth.setDomain(baseUrl);
httpAuth.setPort(443);
httpAuth.setPath("/permissions");
httpAuth.setMethod("GET");
httpAuth.setName("HTTP Request One");
httpAuth.setProtocol("https");
httpAuth.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
httpAuth.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

RegexExtractor regularExpressionExtractor = new RegexExtractor();
regularExpressionExtractor.setName("Regular Expression Extractor");
regularExpressionExtractor.setRegex("(your-regular-expression-for-extracting-the-token-here)");
regularExpressionExtractor.setRefName("token");
regularExpressionExtractor.setMatchNumber(1);
regularExpressionExtractor.setTemplate("$1$");
regularExpressionExtractor.setProperty(TestElement.TEST_CLASS,RegexExtractor.class.getName());
regularExpressionExtractor.setProperty(TestElement.GUI_CLASS, RegexExtractorGui.class.getName());

testPlanTree.add(testPlan);
HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
HashTree httpRequestTree = threadGroupHashTree.add(httpAuth,regularExpressionExtractor);
threadGroupHashTree.add(httpRequestTree);

更多信息:JMeter 命令行概述:启动测试的 5 种方法

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