SlideShare a Scribd company logo
Bean Shell Scripting in
Apache JMeter
NAVEENKUMAR NAMACHIVAYAM
Founder – QAInsights.com
http://QAInsights.com
Introduction to Beanshell
• BeanShell is a Java-like scripting language, invented by Patrick Niemeyer.
• Pure Java
• Free
• Runs in the Java Runtime Environment and uses Java syntax
• BeanShell is small and embeddable, so you can call BeanShell from your Java applications to
execute Java code dynamically at run-time
• standalone BeanShell scripts to manipulate Java applications; working with Java objects and
APIs dynamically.
• Runs in four modes: Command Line, Console, Applet, Remote Session Server.
• With BeanShell you can create custom outputs, perform logical operations, manipulate
variables, etc.
Scripting Features
• Optionally typed variables.
• Scripted methods with optionally typed arguments and return values
• Scripted objects (method closures)
• Scripted interfaces and event handlers.
• Convenience syntax for working with JavaBean properties, hashtables, and primitive wrapper
types.
• Auto-allocation of variables to emulate Java properties files.
• Extensible set of utility and shell-like commands
• Dynamic classpath management including find grained class reloading
• Dynamic command loading and user command path
• Sophisticated namespace and callstack management
• Detailed error reporting
Bean Shell Sampler
• In order to manipulate and work on the response data, Bean Shell sampler would be a great
element.
• To add Bean Shell sampler, right click, Add > Sampler > Bean Shell Sampler.
Bean Shell Sampler
• In this example, user name will be retrieved and manipulated using Bean Shell sampler.
• If the username is not equal to NAVEENKUMAR NAMACHIVAYAM, then the thread will stop.
• Use Regular Expression Extractor to extract the username as shown below.
Bean Shell Sampler
• Once the username is extracted, add Bean Shell Sampler to manipulate.
• Here the username will be stored in username variable.
• To get the extracted value in Bean Shell sampler, use below syntax.
• String userName = vars.get("username");
• Next step is to check the condition using if statement.
• if (userName != "NAVEENKUMAR NAMACHIVAYAM")
• You can use Data set config file variable too, if you do not want to hard code the user name.
• Now, if the condition is true, following statement will be used to terminate the execution.
• SampleResult.setStopThread(true);
• Below statement will be used to return the value.
• return userName
Bean Shell Sampler
Bean Shell Sampler Output
Bean Shell Sampler – Some more enhancement
• To print the output to command prompt, you can use
• System.out.println statement
• System.out.println("Response Code is " + ResponseCode);
• System.out.println("Response Message is " + ResponseMessage);
• if (SampleResult.isSuccessful())
• {
• System.out.println("Success");
• SampleResult.setStopTest(true);
• SampleResult.setStopThread(true);
• }
Bean Shell Sampler – Some more enhancement
Thank you
Please visit http://qainsights.com/services for more training programs.

More Related Content

What's hot (20)

PPTX
Performance testing using jmeter
Rachappa Bandi
 
PPTX
Maven ppt
natashasweety7
 
PDF
JMeter vs LoadRunner | Edureka
Edureka!
 
PPT
Performance Testing
sharmaparish
 
PPTX
Selenium with java
Gousalya Ramachandran
 
PPTX
Postman. From simple API test to end to end scenario
HYS Enterprise
 
PPTX
Performance testing
Jyoti Babbar
 
PPTX
STLC
Karuna Thakur
 
PPS
JUnit Presentation
priya_trivedi
 
PPTX
Automation Framework Presentation
Ben Ngo
 
PPT
Performance testing : An Overview
sharadkjain
 
PPT
Performance and load testing
sonukalpana
 
PPT
SOAP-UI The Web service Testing
Ganesh Mandala
 
PPTX
Performance Testing using LoadRunner
Kumar Gupta
 
PPTX
Performance Testing
Selin Gungor
 
PPT
Maven Introduction
Sandeep Chawla
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PDF
Neoload
Kumar Gupta
 
PDF
Jmeter Performance Testing
Atul Pant
 
PDF
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 
Performance testing using jmeter
Rachappa Bandi
 
Maven ppt
natashasweety7
 
JMeter vs LoadRunner | Edureka
Edureka!
 
Performance Testing
sharmaparish
 
Selenium with java
Gousalya Ramachandran
 
Postman. From simple API test to end to end scenario
HYS Enterprise
 
Performance testing
Jyoti Babbar
 
JUnit Presentation
priya_trivedi
 
Automation Framework Presentation
Ben Ngo
 
Performance testing : An Overview
sharadkjain
 
Performance and load testing
sonukalpana
 
SOAP-UI The Web service Testing
Ganesh Mandala
 
Performance Testing using LoadRunner
Kumar Gupta
 
Performance Testing
Selin Gungor
 
Maven Introduction
Sandeep Chawla
 
Selenium Automation Framework
Mindfire Solutions
 
Neoload
Kumar Gupta
 
Jmeter Performance Testing
Atul Pant
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 

Viewers also liked (10)

PPTX
Installing Groovy engine in Apache Jmeter
NaveenKumar Namachivayam
 
PPT
Performance testing and reporting with JMeter
jvSlideshare
 
PPTX
How to Analyze Reports in Jmeter
Viviana Lesmes
 
PPT
Performance Testing With Jmeter
Adam Goucher
 
PPTX
Timers in Apache JMeter
NaveenKumar Namachivayam
 
PDF
Automated Performance Testing With J Meter And Maven
PerconaPerformance
 
PDF
How to start performance testing project
NaveenKumar Namachivayam
 
PPTX
Автоматизация нагрузочного тестирования в связке JMeter + TeamСity + Grafana ...
Positive Hack Days
 
PDF
Algorithm Class is a Training Institute on C, C++, CPP, DS, JAVA, data struct...
http://algorithmtraining.com/advanced-python-training-hyderabad/
 
Installing Groovy engine in Apache Jmeter
NaveenKumar Namachivayam
 
Performance testing and reporting with JMeter
jvSlideshare
 
How to Analyze Reports in Jmeter
Viviana Lesmes
 
Performance Testing With Jmeter
Adam Goucher
 
Timers in Apache JMeter
NaveenKumar Namachivayam
 
Automated Performance Testing With J Meter And Maven
PerconaPerformance
 
How to start performance testing project
NaveenKumar Namachivayam
 
Автоматизация нагрузочного тестирования в связке JMeter + TeamСity + Grafana ...
Positive Hack Days
 
Algorithm Class is a Training Institute on C, C++, CPP, DS, JAVA, data struct...
http://algorithmtraining.com/advanced-python-training-hyderabad/
 
Ad

More from NaveenKumar Namachivayam (17)

PPTX
Start up ideas - Search Engines for Apps
NaveenKumar Namachivayam
 
PPTX
Interesting facts about IRCTC and Lessons for Performance Testers
NaveenKumar Namachivayam
 
PPTX
Web service testing using QTP (UFT)
NaveenKumar Namachivayam
 
PPTX
Types of performance testing
NaveenKumar Namachivayam
 
DOCX
Internationalization Test Approach - Full Whitepaper
NaveenKumar Namachivayam
 
PPTX
Working faster MS Outlook Advance
NaveenKumar Namachivayam
 
PPTX
Customizing Outlook MS Outlook Advance
NaveenKumar Namachivayam
 
PPTX
Formatting Options MS Outlook Advance
NaveenKumar Namachivayam
 
PPTX
Message modifications MS Outlook Intermediate
NaveenKumar Namachivayam
 
PPTX
Email Enhancements MS Outlook Intermediate
NaveenKumar Namachivayam
 
PPTX
Journal and Notes
NaveenKumar Namachivayam
 
PPTX
Organizing messages
NaveenKumar Namachivayam
 
PPTX
Email Feature
NaveenKumar Namachivayam
 
PPTX
Messages - MS Outlook
NaveenKumar Namachivayam
 
PPTX
Getting started with Outlook
NaveenKumar Namachivayam
 
Start up ideas - Search Engines for Apps
NaveenKumar Namachivayam
 
Interesting facts about IRCTC and Lessons for Performance Testers
NaveenKumar Namachivayam
 
Web service testing using QTP (UFT)
NaveenKumar Namachivayam
 
Types of performance testing
NaveenKumar Namachivayam
 
Internationalization Test Approach - Full Whitepaper
NaveenKumar Namachivayam
 
Working faster MS Outlook Advance
NaveenKumar Namachivayam
 
Customizing Outlook MS Outlook Advance
NaveenKumar Namachivayam
 
Formatting Options MS Outlook Advance
NaveenKumar Namachivayam
 
Message modifications MS Outlook Intermediate
NaveenKumar Namachivayam
 
Email Enhancements MS Outlook Intermediate
NaveenKumar Namachivayam
 
Journal and Notes
NaveenKumar Namachivayam
 
Organizing messages
NaveenKumar Namachivayam
 
Messages - MS Outlook
NaveenKumar Namachivayam
 
Getting started with Outlook
NaveenKumar Namachivayam
 
Ad

Recently uploaded (20)

PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Digital Circuits, important subject in CS
contactparinay1
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 

Beanshell scripting in Apache JMeter

  • 1. Bean Shell Scripting in Apache JMeter NAVEENKUMAR NAMACHIVAYAM Founder – QAInsights.com http://QAInsights.com
  • 2. Introduction to Beanshell • BeanShell is a Java-like scripting language, invented by Patrick Niemeyer. • Pure Java • Free • Runs in the Java Runtime Environment and uses Java syntax • BeanShell is small and embeddable, so you can call BeanShell from your Java applications to execute Java code dynamically at run-time • standalone BeanShell scripts to manipulate Java applications; working with Java objects and APIs dynamically. • Runs in four modes: Command Line, Console, Applet, Remote Session Server. • With BeanShell you can create custom outputs, perform logical operations, manipulate variables, etc.
  • 3. Scripting Features • Optionally typed variables. • Scripted methods with optionally typed arguments and return values • Scripted objects (method closures) • Scripted interfaces and event handlers. • Convenience syntax for working with JavaBean properties, hashtables, and primitive wrapper types. • Auto-allocation of variables to emulate Java properties files. • Extensible set of utility and shell-like commands • Dynamic classpath management including find grained class reloading • Dynamic command loading and user command path • Sophisticated namespace and callstack management • Detailed error reporting
  • 4. Bean Shell Sampler • In order to manipulate and work on the response data, Bean Shell sampler would be a great element. • To add Bean Shell sampler, right click, Add > Sampler > Bean Shell Sampler.
  • 5. Bean Shell Sampler • In this example, user name will be retrieved and manipulated using Bean Shell sampler. • If the username is not equal to NAVEENKUMAR NAMACHIVAYAM, then the thread will stop. • Use Regular Expression Extractor to extract the username as shown below.
  • 6. Bean Shell Sampler • Once the username is extracted, add Bean Shell Sampler to manipulate. • Here the username will be stored in username variable. • To get the extracted value in Bean Shell sampler, use below syntax. • String userName = vars.get("username"); • Next step is to check the condition using if statement. • if (userName != "NAVEENKUMAR NAMACHIVAYAM") • You can use Data set config file variable too, if you do not want to hard code the user name. • Now, if the condition is true, following statement will be used to terminate the execution. • SampleResult.setStopThread(true); • Below statement will be used to return the value. • return userName
  • 9. Bean Shell Sampler – Some more enhancement • To print the output to command prompt, you can use • System.out.println statement • System.out.println("Response Code is " + ResponseCode); • System.out.println("Response Message is " + ResponseMessage); • if (SampleResult.isSuccessful()) • { • System.out.println("Success"); • SampleResult.setStopTest(true); • SampleResult.setStopThread(true); • }
  • 10. Bean Shell Sampler – Some more enhancement
  • 11. Thank you Please visit http://qainsights.com/services for more training programs.