S Singha
S Singha

Reputation: 41

how to stop thread for a particular condition in jmeter?

I am testing on a site which has multiple options.

**For example, **

let's say on the home page (1st sampler) we have two options Option A and Option B. So if I choose option it will navigate to another page (2nd sampler) and show me some results regarding option A and from those results I will click on any of the results and go to the next page (3rd sampler).

But when I click on Option B on the home page (1st sampler), there is no result to show me (in the 2nd sampler) so I don't want it to navigate and execute the 3rd sampler.

I want to stop the execution if there is no result coming in the result page of option B. How should I implement this in JMeter.

Upvotes: 1

Views: 5601

Answers (2)

Iske
Iske

Reputation: 1200

To accomplish this, you will need to add BeanShell PostProcessor on your Option B with the following code:

import org.apache.jmeter.threads.JMeterContextService;

String prevResult = JMeterContextService.getContext()
                        .getPreviousResult().getResponseDataAsString();

if(prevResult == null || prevResult.isEmpty()) // | ---> ||
      JMeterContextService.getContext().getThread().stop();

This will check previous response and if its empty stop current thread. If response is not empty, test execution will continue.

Upvotes: 2

Dmitri T
Dmitri T

Reputation: 168217

I would recommend using

combination like:

Test Action Sampler

Upvotes: 2

Related Questions