2

The web application is built in AngularJS and has AJAX calls. It is built on Service now platform. Recently the platform is upgraded and there are complete UI changes.

Before the upgrade, we were able to see the list of ticket ids in a web page in HTML mode. The flow was to pick one ticket randomly and perform action on the same.

After the upgrade, we are able to see only header part of the page where as ticket id table is not displaying. After analysis, it has been understood that the get call for the page needs to be sent along with one API now post call which contains JSON payload to view the table.

I tried to use groovy sampler as described in blazemeter knowledge base . I am able to define the URLs but not the post request payload also tried example sampler with no luck.

Please suggest the work around to solve the issue.

enter image description here

  • @Dmitri T Can you please help – Raj Sep 16 '17 at 2:47
1

If your question is about how to send a HTTP POST request with JSON body from JSR223 Sampler, kindly find example code below:

import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils

def client = HttpClientBuilder.create().build()

def entity = new StringEntity(
        '{"put_your":"json_here"}',
        ContentType.APPLICATION_JSON)

def post = new HttpPost('http://put_your_url_here')
post.setEntity(entity)

def response = client.execute(post)

SampleResult.setResponseCode(response.getStatusLine().getStatusCode() as String)
SampleResult.setResponseMessage(response.getStatusLine().getReasonPhrase())
SampleResult.setResponseData(EntityUtils.toByteArray(response.getEntity()))

Check out Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests.

  • 1
    Thank u @Dmitri T for the response. My requirement is to send one get request + one Post request containing JSON body simultaneously. I tried defining both urls using JSR233 Sampler. parameters but not sure how to call both get and Post in groovy script. Please find the sample requirement screenshot – Raj Sep 18 '17 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.