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.

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:

Navigate to the script you want to execute. For example, ch1/getting_started.jmx provided with the sample code.

To launch the JMeter GUI on Windows, type in jmeter.bat . Alternatively, for Unix/Mac OS, type in ./jmeter .

Change to the directory of your JMeter install. We'll refer to this as JMETER_HOME .

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).

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.

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]