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();
}
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();
}
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();
}
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));
}
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"));
}
Aggregations