- JMeter Cookbook
- Bayo Erinle
- 750字
- 2021-08-05 17:36:25
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:
- Open the command line prompt.
- Change to the directory of your JMeter install. We'll refer to this as
JMETER_HOME
.Note
Refer to Appendix for JMeter installation instructions.
- Change
JMETER_HOME
to thebin
directory. - To launch the JMeter GUI on Windows, type in
jmeter.bat
. Alternatively, for Unix/Mac OS, type in./jmeter
. - Navigate to File | Open.
Note
Alternative key binding: Mac OS (Command + O), Windows (Ctrl + O).
- Navigate to the script you want to execute. For example,
ch1/getting_started.jmx
provided with the sample code. - Press the green start icon at the top.
Note
Alternative key binding: Mac OS (Command + R), Windows (Ctrl + R).
- 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: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:

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
- 企業數字化創新引擎:企業級PaaS平臺HZERO
- Greenplum:從大數據戰略到實現
- SQL Server 2012數據庫技術與應用(微課版)
- Access 2007數據庫應用上機指導與練習
- Scratch 3.0 藝術進階
- 一個64位操作系統的設計與實現
- Lego Mindstorms EV3 Essentials
- MATLAB Graphics and Data Visualization Cookbook
- 數據科學工程實踐:用戶行為分析與建模、A/B實驗、SQLFlow
- 云原生數據中臺:架構、方法論與實踐
- HikariCP連接池實戰
- 探索新型智庫發展之路:藍迪國際智庫報告·2015(上冊)
- 數字IC設計入門(微課視頻版)
- 大數據數學基礎(Python語言描述)
- Python數據分析從小白到專家