Search in sources :

Example 16 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class FifoSize method execute.

@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String fifoName = ((CompoundVariable) values[0]).execute();
    int size = FifoMap.getInstance().length(fifoName);
    String value = Integer.toString(size);
    JMeterVariables vars = getVariables();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, value);
    }
    return value;
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 17 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class WebDriverSamplerTest method createSampler.

@Before
public void createSampler() {
    browser = Mockito.mock(WebDriver.class);
    when(browser.getPageSource()).thenReturn("page source");
    when(browser.getCurrentUrl()).thenReturn("http://google.com.au");
    variables = new JMeterVariables();
    variables.putObject(WebDriverConfig.BROWSER, browser);
    JMeterContextService.getContext().setVariables(variables);
    sampler = new WebDriverSampler();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) Before(org.junit.Before)

Example 18 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class JSONPathExtractorTest method testProcess_default.

@Test
public void testProcess_default() {
    System.out.println("process def");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    context.setPreviousResult(res);
    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("DEFAULT", vars.get("test"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 19 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class JSONPathExtractorTest method testReported2.

@Ignore
// FIXME: we need to solve this one day
@Test
public void testReported2() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json3.getBytes());
    context.setPreviousResult(res);
    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("var");
    instance.setJsonPath("$.data[?(@.attr.value>0)][0].attr");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("var"));
    assertEquals("{value=1}", vars.get("var"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class JSONPathExtractorTest method testProcess_chinese.

@Test
public void testProcess_chinese() {
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    String chinese = "{\"carBrandName\":\"大众\"}";
    res.setResponseData(chinese.getBytes());
    context.setPreviousResult(res);
    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.carBrandName");
    instance.process();
    JMeterVariables vars = context.getVariables();
// freaking "static final" DEFAULT_ENCODING field in SampleResult does not allow us to assert this
// assertEquals("大众", vars.get("test"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Aggregations

JMeterVariables (org.apache.jmeter.threads.JMeterVariables)193 SampleResult (org.apache.jmeter.samplers.SampleResult)71 JMeterContext (org.apache.jmeter.threads.JMeterContext)64 BeforeEach (org.junit.jupiter.api.BeforeEach)46 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)27 Test (org.junit.jupiter.api.Test)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Test (org.junit.Test)16 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)11 Before (org.junit.Before)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)6 TestPlan (org.apache.jmeter.testelement.TestPlan)6 HashMap (java.util.HashMap)5 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)5 URL (java.net.URL)4 Arguments (org.apache.jmeter.config.Arguments)4 DebugSampler (org.apache.jmeter.sampler.DebugSampler)4