Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
JMeter Cookbook

You're reading from   JMeter Cookbook 70 insightful and practical recipes to help you successfully use Apache JMeter

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher
ISBN-13 9781783988280
Length 228 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Bayo Erinle Bayo Erinle
Author Profile Icon Bayo Erinle
Bayo Erinle
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. JMeter Fundamentals FREE CHAPTER 2. Handling Responses 3. Building Robust Test Plans with Controllers 4. Testing Services 5. Diving into Distributed Testing 6. Extending JMeter 7. Building, Debugging, and Analyzing the Results of Test Plans 8. Beyond the Basics A. Installing the Supporting Software Needed for this Book Index

Executing a test script

Sometimes, the test scripts to execute have already been recorded and handed over to you to run. In this recipe, we will show you just how to go about executing a script that was prerecorded.

How to do it…

To execute a test script, perform the following steps:

  1. Open the command line prompt.
  2. Change to the directory of your JMeter install. We'll refer to this as JMETER_HOME.

    Note

    Refer to Appendix for JMeter installation instructions.

  3. Change JMETER_HOME to the bin directory.
  4. To launch the JMeter GUI on Windows, type in jmeter.bat. Alternatively, for Unix/Mac OS, type in ./jmeter.
  5. Navigate to File | Open.

    Note

    Alternative key binding: Mac OS (Command + O), Windows (Ctrl + O).

  6. Navigate to the script you want to execute. For example, ch1/getting_started.jmx provided with the sample code.
  7. Press the green start icon at the top.

    Note

    Alternative key binding: Mac OS (Command + R), Windows (Ctrl + R).

  8. View the results from one of the added listeners. If you are using getting_started.jmx from step 6, click on the View Results Tree listener as shown in the following screenshot:
    How to do it…

    Executing a test script

How it works…

Test scripts are a series of prerecorded requests issued against an application. They are captured interactions of a user's actions with the application. These include visiting a URL, navigating around several pages, logging in, and so on. JMeter, like most test tools, has the ability to record and replay back test scripts. JMeter test scripts are stored in the XML (extendable markup language) format with the .jmx extension. Curious users can open the test script in a text editor of their choice (for example, Sublime Text, Notepad, and so on) and view exactly what it is doing, though, it is much more clear to understand what a script does by looking at it in JMeter's GUI.

After executing the test, results are reported through any configured listeners. A script can have one or several listeners attached to it (see recipes in Chapter 7, Building, Debugging, and Analyzing the Results of Test Plans).

There's more…

Scripts can also be executed in what JMeter refers to as non-GUI mode, which is completely on the command line without launching the JMeter GUI. To do this, instead of executing jmeter.bat or JMeter, like we did in step 4, we'll use certain JMeter command-line arguments to specify the test script and the resulting output file, which we can then go back and view with the JMeter GUI after the tests are executed.

On Unix/Mac OS, type in the following command:

./jmeter -n -t [path to test script] -l [path to results files]

On Windows, type in the following command:

jmeter.bat -n -t [path to test script] -l [path to results files]

An example of running in non-GUI mode

Here is an example of running code in non-GUI mode: This is how we executed the google_simulation.jmx test script in our bundled sampled in non-GUI mode. As you can see, we supplied parameters –n and –t and the absolute path to where our script is located (/Users/berinle/workspace/jmeter-cookbook/ch1/google_simulation.jmx) followed by the path to the results file (/Users/berinle/workspace/jmeter-cookbook/ch1/google_simulation_result.csv).

./jmeter -n -t /Users/berinle/workspace/jmeter-cookbook/ch1/google_simulation.jmx -l /Users/berinle/workspace/jmeter-cookbook/ch1/google_simulation_result.csv

Created the tree successfully using /Users/berinle/workspace/jmeter-cookbook/ch1/google_simulation.jmx.

Starting the test @ Tue Feb 25 05:07:45 EST 2014 (1393322865378)

Waiting for possible shutdown message on port 4445.

Tidying up ... @ Tue Feb 25 05:08:46 EST 2014 (1393322926156)

... end of run

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

To view the results after the test has been executed, open up the JMeter GUI, create a new test plan, and add a listener to it by navigating to Test plan | Add | Listener | Aggregate Report. Click on the Browse… button to navigate to the location of the results file and open it. This is demonstrated in the following screenshot:

An example of running in non-GUI mode

Viewing the results of a test run

There are several reasons why you might want to execute a test in non-GUI mode. Some of the reasons include:

  • Running on a Unix machine with no GUI layer (that is, the JMeter GUI does not even open up)
  • Running a distributed test
  • Performance reasons of the JMeter GUI, which can sometimes be resource intensive; running in non-GUI mode alleviates this issue
You have been reading a chapter from
JMeter Cookbook
Published in: Oct 2014
Publisher:
ISBN-13: 9781783988280
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image