use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class HtmlExtractor method process.
/**
* Parses the response data using CSS/JQuery expressions and saving the results
* into variables for use later in the test.
*
* @see org.apache.jmeter.processor.PostProcessor#process()
*/
@Override
public void process() {
JMeterContext context = getThreadContext();
SampleResult previousResult = context.getPreviousResult();
if (previousResult == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("HtmlExtractor {}: processing result", getName());
}
// Fetch some variables
JMeterVariables vars = context.getVariables();
String refName = getRefName();
String expression = getExpression();
String attribute = getAttribute();
int matchNumber = getMatchNumber();
final String defaultValue = getDefaultValue();
if (defaultValue.length() > 0 || isEmptyDefaultValue()) {
// Only replace default if it is provided or empty default value is explicitly requested
vars.put(refName, defaultValue);
}
try {
List<String> matches = extractMatchingStrings(vars, expression, attribute, matchNumber, previousResult);
int prevCount = 0;
String prevString = vars.get(refName + REF_MATCH_NR);
if (prevString != null) {
// ensure old value is not left defined
vars.remove(refName + REF_MATCH_NR);
try {
prevCount = Integer.parseInt(prevString);
} catch (NumberFormatException nfe) {
if (log.isWarnEnabled()) {
log.warn("{}: Could not parse number: '{}'.", getName(), prevString);
}
}
}
// Number of refName_n variable sets to keep
int matchCount = 0;
String match;
if (matchNumber >= 0) {
// Original match behaviour
match = getCorrectMatch(matches, matchNumber);
if (match != null) {
vars.put(refName, match);
}
} else // < 0 means we save all the matches
{
matchCount = matches.size();
// Save the count
vars.put(refName + REF_MATCH_NR, Integer.toString(matchCount));
for (int i = 1; i <= matchCount; i++) {
match = getCorrectMatch(matches, i);
if (match != null) {
final String refNameN = refName + UNDERSCORE + i;
vars.put(refNameN, match);
}
}
}
// Remove any left-over variables
for (int i = matchCount + 1; i <= prevCount; i++) {
final String refNameN = refName + UNDERSCORE + i;
vars.remove(refNameN);
}
} catch (RuntimeException e) {
if (log.isWarnEnabled()) {
log.warn("{}: Error while generating result. {}", getName(), e.toString());
}
}
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestCookieManagerThreadIteration method setUp.
@BeforeEach
public void setUp() {
jmctx = JMeterContextService.getContext();
jmvars = new JMeterVariables();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestAuthManagerThreadIteration method setUp.
@BeforeEach
public void setUp() {
jmctx = JMeterContextService.getContext();
jmvars = new JMeterVariables();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestCacheManagerThreadIteration method setUp.
@BeforeEach
public void setUp() throws Exception {
this.cacheManager = new CacheManager();
this.currentTimeInGMT = makeDate(new Date());
this.url = new URL(LOCAL_HOST);
this.sampleResultOK = getSampleResultWithSpecifiedResponseCode("200");
this.httpMethod = new HttpPostStub();
this.httpResponse = new HttpResponseStub();
this.httpMethod.setURI(this.url.toURI());
jmctx = JMeterContextService.getContext();
jmvars = new JMeterVariables();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestValueReplacer method setUp.
@BeforeEach
public void setUp() {
variables = new TestPlan();
variables.addParameter("server", "jakarta.apache.org");
variables.addParameter("username", "jack");
// The following used to be jacks_password, but the Arguments class uses
// HashMap for which the order is not defined.
variables.addParameter("password", "his_password");
variables.addParameter("normal_regex", "Hello .*");
variables.addParameter("bounded_regex", "(<.*>)");
JMeterVariables vars = new JMeterVariables();
vars.put("server", "jakarta.apache.org");
JMeterContextService.getContext().setVariables(vars);
JMeterContextService.getContext().setSamplingStarted(true);
}
Aggregations