2

How do I override the response content in a JMeter WebDriver sampler test? When I run the following code, the response that is shown in the response tab of the WebDriver Sampler is the full content of the webpage rather than what I expected to see, a string value of "a message" . Any idea on what I am doing wrong?

var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
WDS.log.info("Start...")
WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()
java.lang.Thread.sleep( 500 )
WDS.sampleResult.setResponseMessage( "a message" )
WDS.sampleResult.setSuccessful(true) 

To reproduce this you need to download the WebDriver plugin pack for JMeter and add a "WebDriver Sampler" step and a "Firefix Driver Config" to your Test plan.

This doesn't work either:

WDS.sampleResult.responseMessage = 'a message'
WDS.sampleResult.successful = true 

Nor did this:

WDS.sampleResult.setResponseData("a message", "utf-8")
WDS.sampleResult.setSuccessful(true)

Nor did this:

var message = "Hello World".split('')
WDS.sampleResult.setResponseData( message, 'utf-8' )
WDS.sampleResult.setSuccessful(true)

I am just trying to set a value that I can retrieve in a subsequent test step.

djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

1

As per code:

ResponseMessage and ResponseData are overwritten by sampler after calling your script code.

So you can't do what you want to.

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • 1
    Thanks for the code reference. That helps. I was able to work around this by using the WDS.sampleResult.setResponseHeaders(), which does in fact behave as I was expected. So, even though I can't override the reponse data content, I am able to modify the headers after the Sampler has finished by using WDS.sampleResult.setHeaders() and then , on a subsequent Beanshell call, get the values. – djangofan Aug 09 '14 at 06:04
  • @djangofan Thanks for this note! I had been down so many roads trying to get some data out of my webdriver sampler and this solved my problem! I used a regular expression extractor the retrieve the response headers and it worked perfectly. – jlunavtgrad Mar 26 '15 at 18:23