Load Stitch
Load Stitch

Reputation: 167

Invoking Transaction controller or HTTP sampler from Bean shell/JSR223

Problem statement. Set of transactions(1000+) and need to call or reuse(without duplicating in different if/switch controllers) by invoking from the Beanshell or JSR233.

In SoapUI we have groovy script option to break sequential execution and divert control to any request using the below command.

if( Math.random() > 0.5 )
   testRunner.runTestStepByName( "Request 1")
else
   testRunner.runTestStepByName( "Request 2")

// do something else
....

Same functionality available in Loadrunner(Run time setting with different action) and neoload too.

Do we have any built-in objects or function to execute by transaction or Sampler name from JSR223/BeanShell without using if/while/switch controller ?

For Example:

In script 10 transactions are there and to use same script for different scenario by setting a JMeter property during execution through Jenkins or command prompt .

__P(Flow,RoomBooking)

Then from JSR233 /beanshell sampler

if(Flow=="RoomBooking"){

invoke Login 

invoke BookRoom

invoke Logout

} else if(Flow=="RoomBookingNBookItinerary")

invoke Login 

invoke BookRoom

invoke BookItinerary

invoke Logout

}else if(Flow=="RoomBookingNcancel")

invoke Login 

invoke BookRoom

Invoke ParkTicket 

invoke CancelRoom

invoke Logout

}Like different flows with different thread and throughput 

In this case I can mix and match different flows and and reuse same script for different flow. This would help to reduce script rework effort during application changes.

Upvotes: 2

Views: 1192

Answers (3)

Ori Marko
Ori Marko

Reputation: 58802

You are right, JMeter doesn't have JSR 223 Logic Controller at all,

I think that it can help changing also the if controller,

I suggest you open an enhancement to JMeter product (choose Severity: enhancement)

EDIT

There's a new Bug 61711 - Add JSR223 Logic Controller you can vote on.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168112

If you are looking for a way to execute a previous sampler one more time from the JSR223 Script it would be something like:

ctx.getPreviousSampler().sample(null)

where ctx stands for JMeterContext for all available methods and fields.

Demo:

JSR223 Execute Sampler One more Time


However a better idea would be using JMeter's Module Controller which allows executing a part of JMeter test plan somewhere else, this way you can implement a form of goto statement in JMeter

Upvotes: 1

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34536

You can possibly do it with Switch Controller

Test Plan

Any step will be a Transaction Controller

And in a JSR223 Sampler you'll set which step you want:

JSR223 Sampler

Upvotes: 0

Related Questions