Я добавил препроцессор JSR223 в сэмплер HTTP, чтобы иметь возможность выбрать параметр строки запроса и добавить к нему новое значение.
т.е.:
до
designer=17827&size=3350&color=1
Выбранный параметр = Размер
Новое значение для добавления = 9999
ПОСЛЕ
designer=17827&size=3350|9999&color=1
Для этого я разработал код Groovy ниже:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
def listing_page_filter_name = "size";
def filter_values_value = "9999";
def listing_filters = "designer=17827&size=3350&color=1";
def prefix = listing_page_filter_name;
Pattern r = Pattern.compile(prefix + '=(.+?)&|' + prefix + '=(.+?)\\$');
String pattern = r.toString();
//Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(listing_filters);
log.info("FILTER: " + listing_page_filter_name);
log.info("FILTER VALUE: " + filter_values_value);
if(m.find())
{
log.info("Found value ------> " + m.group(1));
def regex_match = m.group(1);
def replacement = regex_match + "|" + filter_values_value;
log.info('Replacing it by: $1' + replacement);
String str = m.replaceFirst(Pattern.quote(pattern),Pattern.quote(replacement));
log.info(str);
//log.info(m.replaceFirst(/=(.+?)&|/,"lalalalalalala"));
}
Вывод, который я получаю:
2019-05-15 11:28:02,765 INFO o.a.j.m.J.JSR223 PreProcessor: RANDOMLY CHOSEN FILTER: size
2019-05-15 11:28:02,765 INFO o.a.j.m.J.JSR223 PreProcessor: RANDOMLY CHOSEN FILTER VALUE: 9999
2019-05-15 11:28:02,765 INFO o.a.j.m.J.JSR223 PreProcessor: Found value ------> 3350
2019-05-15 11:28:02,766 INFO o.a.j.m.J.JSR223 PreProcessor: Replacing it by: $13350|9999
2019-05-15 11:28:02,766 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.regex.Matcher.replaceFirst() is applicable for argument types: (java.lang.String, java.lang.String) values: [\Qsize=(.+?)&|size=(.+?)\$\E, \Q3350|9999\E]
Possible solutions: replaceFirst(java.lang.String)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_211]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.regex.Matcher.replaceFirst() is applicable for argument types: (java.lang.String, java.lang.String) values: [\Qsize=(.+?)&|size=(.+?)\$\E, \Q3350|9999\E]
Possible solutions: replaceFirst(java.lang.String)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71) ~[groovy-all-2.4.16.jar:2.4.16]
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) ~[groovy-all-2.4.16.jar:2.4.16]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136) ~[groovy-all-2.4.16.jar:2.4.16]
at Script36.run(Script36.groovy:23) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) ~[groovy-all-2.4.16.jar:2.4.16]
... 9 more
Кто-нибудь знает почему?
Заранее спасибо!