DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Use JMS ActiveMQ With Mule 4 - Part 6
  • Tips for Efficiently Testing and Validating Your Program
  • What Are Events? API Calls
  • Error Handling Inside Kumologica Subflow

Trending

  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation
  • Data Lake vs. Warehouse vs. Lakehouse vs. Mart: Choosing the Right Architecture for Your Business
  • Next Evolution in Integration: Architecting With Intent Using Model Context Protocol
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Easily Write a GOTO Statement in JMeter

Easily Write a GOTO Statement in JMeter

In this post, we take a look at how you can setup a GOTO statement in JMeter with ease! Read on for details on GOTO statements and instructions.

By 
Matias Fornara user avatar
Matias Fornara
·
Jul. 13, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
6.2K Views

Join the DZone community and get the full member experience.

Join For Free

What happens if you need to modify your Apache JMeter™ script’s flow according to an event? For example, going back to the homepage because a particular request failed, or skipping to a future step if a condition was fulfilled. This is where the GOTO statement comes in.

What Is a GOTO Statement?

The aim of a GOTO statement is to perform a reassignment to another line of code. In other words, the GOTO statement is very useful when you need to jump to another part of the flow, which is usually identified by a particular label.

Image title

Creating a GOTO Statement in JMeter

The first step to creating a GOTO statement in JMeter is realizing there is no predefined GOTO structure in JMeter. So, what we can do is to nest a Module Controller within an If Controller. The If Controller lets you choose whether the child elements below it are run or not. The Module Controller enables substituting test plan fragments. 

Let’s use a dummy scenario where we first log into a certain bank page, and then we go to the credit cards section where we perform some validations. If the login action goes wrong we would like to go back and try to log in again - this is the moment our GOTO statement will take place. 

In this scenario, the If Controller will check if the login was successful. If it failed, the Module Controller will redirect the user to the login page.

1. Add the If Controller from the Logic Controller list:

Right Click on the Thread Group →  Add →  Logic Controller → If Controller

Image title

2. Make sure to establish a condition that will redirect the flow when fulfilled. The condition has to be a Javascript condition returning “true” or “false,” or a JMeter function that evaluates to “true.”

For example: "${JMeterThread.last_sample_ok}==true" where JMeterThread.last_sample_ok is a function that returns true or false depending on whether the last sample was OK or not. 

3. In order to establish the desired condition, the “Condition (default javascript)“ field has to be filled inside the If Controller. We named the controller "GoTo."

Image title

In this case, we will check whether the login sampler was successful or not, by using “${JMeterThread.last_sample_ok}==false.” If it fails, i.e. this condition was fulfilled, the Module Controller will go into action. If it does not fail and the condition isn’t false, the flow will advance towards the credit card section.

4. Now that the If Controller is properly configured with an appropriate condition, it’s time to nest the Module Controller within the If Controller as follows:

Right Click on the If Controller →  Add →  Logic Controller →  Module Controller 

Image title

5. Once the Module Controller is created, tell the controller which flow to take in case the previous condition has been fulfilled, i.e the login failed. So, inside the Module Controller pick an existing flow. In this example, I named the Module Controller “goTo_mainPage” and directed it to the main event page.

Image title

If the login does not fail, the GOTO statement will evaluate the If Controller condition, and as it wasn’t fulfilled, the flow will follow as in the below image. 

Image title

But, if the login fails we will observe the following result. In the View Results Tree, we will see the login failed and the If Controller and the Module Controller directed the user back to the main page, to log in again.

Image title

And that’s it! You have set your own GOTO statement, very easily.

Flow (web browser) Test plan Cards (iOS) NEST (software) Event Moment Testing Tree (data structure)

Published at DZone with permission of , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Use JMS ActiveMQ With Mule 4 - Part 6
  • Tips for Efficiently Testing and Validating Your Program
  • What Are Events? API Calls
  • Error Handling Inside Kumologica Subflow

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!