JMeter Fundamentals
Jump to navigation
Jump to search
What is JMeter
- Open Source Project (released March 2001)
- Created for Automated Performance testing saves time and money
- Functional (though it is not the best tool, Regression and Load testing from
- JMeter files are simple XML
- Strong community
- Constant updates and improvements
- http://jmeter.apache.org/
What can you test in JMeter
- JMeter tests all kind of application (not only Java)
- Web Application
- SOAP Web Services, REST, XML-RPC
- JAR files
- LDAP
- Databases (via JDBC)
- JMS
- SMTP
- FTP
Installing JMeter
Windows
- Install JRE
- Download latest version http://jakarta.apache.org/site/downloads/
- Uncompress it
- go to bin folder
- Run jmeter.cmd
Linux
- apt-get install jmeter
- run jmeter
- If you want to have the newest version download it from the jmeter site
JMeter and Logs
- JMeter does not use pop-ups
- All errors and status is spewed out into a log file
- Log file is always located in the directory the jmeter command was invoked
Running JMeter Tests in Windows
GUI
- jmeterw.cmd - run JMeter in GUI using javaw (no terminal window)
- jmeter.bat - run JMeter in GUI mode
- jmeter-t.cmd - drop a JMX file on this to load it in GUI mode (t for Test)
CLI (Non GUI)
- jmeter-n.cmd - drop a JMX file on this to run a non-GUI test (n for non-GUI)
- jmeter-n-r.cmd - drop a JMX file on this to run a non-GUI test remotely
- jmeter-server.bat - start JMeter in server mode
- shutdown.cmd - Run the Shutdown client to stop a non-GUI instance gracefully
- stoptest.cmd - Run the Shutdown client to stop a non-GUI instance abruptly
Note: the special name LAST can be used with jmeter-n.cmd, jmeter-t.cmd and jmeter-n-r.cmd and means the last test plan that was run interactively.
Running JMeter Tests in Unix
- jmeter - run JMeter in GUI (JVM options specified)
- jmeter.sh - very basic JMeter script with no JVM options specified.
- jmeter-server - start JMeter in server mode
- shutdown.sh - Run the Shutdown client to stop a non-GUI instance gracefully
- stoptest.sh - Run the Shutdown client to stop a non-GUI instance abruptly
The Elements of a JMeter Test Plan
- Test Plan and WorkBench
- Thread Group
- Samplers
- Listeners
- Assertions
- Cookie Controller
- HTTP Defaults
- HTTP Headers Defaults
Test Plan vs WorkBench
- Test Plan is saved and where can run the script
- WorkBench is not saved with the Test Plan
Thread Group
- a group of instructions or actions representing one “actor” using your application
- always process instructions within them in chronological order
- allow you to specify simultaneous testing scenarios
Samplers
- Only within a Thread Group
- Samplers perform the actual work of JMeter
- Each sampler (except Test Action) generates one or more sample results
- The sample results can be viewed in listeners
Listeners
- Report back test results to you (in GUI or save them to a file)
- Listeners can work real time or use saved results
Assertions
- These are criteria you can set which the test must meet in order to pass
- E.g. Results of a samplers should not contain "Critical Error" phrase
Simple Controles
TODO Description TODO Screen shot
Creating Simple Test Plan
- Create a Thread Group
- Create a Sampler hitting localhost root page
- Run the test
- Check the log files
- Add the View Results Tree Listener and analyse the result
TODO: Put a screenshot here and jmx file
Running the Test Plan
- Top Right Corner of the GUI will show e.g. 20/40
- 40 is the total number of concurrent threads
- 20 is the number of concurrent threads currently running
TODO: Put a screenshot here
Recording Scenario
- Create a Proxy Server
- Configure Your Browser
- Use "1st Sample only"
- Start Recording
- Rename Samples are you record
Using different options of Proxy Server
TODO
Timers
- Specify a delay before an action (usually sampler) can occur
- Times should mimic human (or system) waiting time
- The best idea is to use logs to determine the distribution and distribution parameters of the waiting time
- Timers can be put in scope
- If two timers are put in the same level, the execution time add up
Saving Results
- Save results to a file
- Use another instance of JMeter to analyse results
- Saving Errors Only
- Saving Full Responses for one sample or group of samples
Biscuits manager
- Try to record the scenario where user:
- logs
- browses the front page
- logs out
- Play the scenario
- Check wether the user really was logged in
Assertions
- Create an assertion which checks wether user is really logged in
- Apply the assertion to all of the samples
Testing different Browsers
- HTTP Headers
- HTTP Headers defaults
Switching Servers
- HTTP Defaults
Functional Testing
- Run Thread Groups consecutively (one group at a time)
Reusing Elements
- Merging (Merge Proxy Server)
- Module Controller
- Include Controller (don't use it)
Variables
- Config Elements > User Defined Variables
- ${VARIABLENAME}
Variables from command line
HOST ${__P(host,www.example.com)} THREADS ${__P(threads,10)} LOOPS ${__P(loops,20)} jmeter ... -Jhost=www3.example.org -Jloops=13 jmeter-n "Test Plan1.jmx" -JCNT=10
Variable Substitution During Recording
- Setup a variable USER and set it to admin
- Login as an admin
- Look into the recorded samples
Dynamic Variables
- Pre Processors > User Parameters
- CSV
Running Test Periodically
- Run Test From Command Line
- ./jmeter -n -t TestPlan.jmx -j /dev/console
- JTL Report
- Creating User Report
Extractors
- Extractors allows you to save part of response in a variable for the future use
- Common Uses
- Security Tokens
- Dynamic data creation
Extractors Examples
Text in HTML:
name="file" value="readme.txt"
RegExp:
name="file" value="(.+?)"
- ( and ) - brackets enclose the portion of the match string to be returned
- . - match any character
- + - one or more times
- ? - don't be greedy, i.e. stop when first match succeeds
Extractors Exercises
- Record and run following sequence (remember about Cookie Manager)
- User access the content (node/add)
- User atrainer logs into the application
- User access the content (node/add)
- User logs out
- User access the content (node/add)
Loops and Counters
- Define a counter
- Create a page with title "Tile 1", "Title 2".... "Title 10"
- Run the script consecrative
- Create a script which runs it in parallel (extra exercise)
Stress Testing
- Ramp-up Time
- Summary Report
- Graph Summary