Search in sources :

Example 46 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class WebDriverSamplerTest method shouldReturnFailureSampleResultWhenScriptSetsSampleResultToFailure.

@Test
public void shouldReturnFailureSampleResultWhenScriptSetsSampleResultToFailure() throws MalformedURLException {
    sampler.setScript("WDS.sampleResult.setSuccessful(false);");
    final SampleResult sampleResult = sampler.sample(null);
    assertThat(sampleResult.isSuccessful(), is(false));
    assertThat(sampleResult.getResponseCode(), is("500"));
    assertThat(sampleResult.getResponseMessage(), not("OK"));
    assertThat(sampleResult.getResponseDataAsString(), is("page source"));
    assertThat(sampleResult.getURL(), is(new URL("http://google.com.au")));
    verify(browser, times(1)).getPageSource();
    verify(browser, times(1)).getCurrentUrl();
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) URL(java.net.URL) Test(org.junit.Test)

Example 47 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class WebDriverSamplerTest method shouldReturnFailureSampleResultWhenEvalScriptIsInvalid.

@Test
public void shouldReturnFailureSampleResultWhenEvalScriptIsInvalid() {
    sampler.setScript("x.methodThatDoesNotExist();");
    final SampleResult sampleResult = sampler.sample(null);
    assertThat(sampleResult.isResponseCodeOK(), is(false));
    assertThat(sampleResult.getResponseMessage(), containsString("ReferenceError"));
    assertThat(sampleResult.isSuccessful(), is(false));
    verify(browser, never()).getPageSource();
    verify(browser, never()).getCurrentUrl();
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 48 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class WebDriverSamplerTest method shouldReturnSuccessfulSampleResultWhenEvalScriptCompletes.

@Test
public void shouldReturnSuccessfulSampleResultWhenEvalScriptCompletes() throws MalformedURLException {
    sampler.setName("name");
    sampler.setScript("var x = 'hello';");
    final SampleResult sampleResult = sampler.sample(null);
    assertThat(sampleResult.isResponseCodeOK(), is(true));
    assertThat(sampleResult.getResponseMessage(), is("OK"));
    assertThat(sampleResult.isSuccessful(), is(true));
    assertThat(sampleResult.getContentType(), is("text/plain"));
    assertThat(sampleResult.getDataType(), is(SampleResult.TEXT));
    assertThat(sampleResult.getSampleLabel(), is("name"));
    assertThat(sampleResult.getResponseDataAsString(), is("page source"));
    assertThat(sampleResult.getURL(), is(new URL("http://google.com.au")));
    verify(browser, times(1)).getPageSource();
    verify(browser, times(1)).getCurrentUrl();
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) URL(java.net.URL) Test(org.junit.Test)

Example 49 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class WebDriverSamplerTest method shouldHaveExpectedInstanceVariablesOnScriptContext.

@Test
public void shouldHaveExpectedInstanceVariablesOnScriptContext() {
    sampler.setName("name");
    sampler.setParameters("p1 p2 p3");
    final SampleResult sampleResult = new SampleResult();
    final ScriptEngine scriptEngine = sampler.createScriptEngineWith(sampleResult);
    final ScriptContext scriptContext = scriptEngine.getContext();
    final WebDriverScriptable scriptable = (WebDriverScriptable) scriptContext.getAttribute("WDS");
    assertThat(scriptable.getLog(), is(instanceOf(Logger.class)));
    assertThat(scriptable.getName(), is(sampler.getName()));
    assertThat(scriptable.getParameters(), is(sampler.getParameters()));
    assertThat(scriptable.getArgs(), is(new String[] { "p1", "p2", "p3" }));
    assertThat(scriptable.getBrowser(), is(instanceOf(WebDriver.class)));
    assertThat(scriptable.getSampleResult(), is(sampleResult));
}
Also used : ScriptContext(javax.script.ScriptContext) SampleResult(org.apache.jmeter.samplers.SampleResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 50 with SampleResult

use of org.apache.jmeter.samplers.SampleResult 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)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)379 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7