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
Conferences
Free Learning
Arrow right icon
JMeter Cookbook
JMeter Cookbook

JMeter Cookbook: 70 insightful and practical recipes to help you successfully use Apache JMeter

eBook
£7.99 £29.99
Paperback
£36.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

JMeter Cookbook

Chapter 1. JMeter Fundamentals

In this chapter, we will cover the following recipes:

  • Executing a test script
  • Recording a script via HTTP(S) Test Script Recorder
  • Recording scripts via the Chrome browser extension
  • Converting HTTP web archives (HAR) to JMeter test plans
  • Viewing and analyzing test results
  • Feeding data into a script
  • Using timers
  • Managing HTTP user sessions
  • Testing Single Page Applications (SPAs)
  • Testing AJAX-centric applications

Introduction

In this chapter, you will learn the fundamentals and intermediate skills that will help you work better with JMeter. Tasks such as executing or recording scripts are routine and you can be almost certain that you will need to perform them, sometimes on a daily basis. Also, we will learn how to view and analyze the results of test executions, feed data into test scripts, and make test scripts mimic user behavior with the aid of timers. In later recipes, we dive into dealing with handling authentication, authorization, and testing today's new breed of applications with JMeter.

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

Recording a script via HTTP(S) Test Script Recorder

Recording scripts is where you will spend most of your time. It is often the first step to develop test plans for applications. Though you can develop test plans manually by building them from within the JMeter GUI, or generating them via some domain-specific language (DSL), recording scripts by JMeter's HTTP(S) Test Script Recorder is one of the available options you have when building your test plans.

How to do it…

In this recipe, we cover how to record test scripts with HTTP(S) Test Script Recorder. Perform the following steps:

  1. Start JMeter. Perform the following steps:
    • Open the command-line prompt
    • Change to the directory of your JMeter install (JMETER_HOME)
    • Change to the bin directory
    • Execute the following command:

      For Windows, type the following command:

      	jmeter.bat
      

      For Mac OS/Unix, type the following command:

      	./jmeter
      
  2. Once the GUI is opened, click on the Templates… button (the icon that appears immediately to the right of the new test plan icon) on the toolbar.

    Note

    Templates were added in JMeter 2.10, so don't expect to see them in versions prior to that.

  3. In the drop-down menu of the Select Template box, choose Recording and click on the Create button.
  4. Click on the HTTP(S) Test Script Recorder element (under WorkBench) and change Port (under Global Settings) from 8888 to 7000.
    • You can use a different port if you want to. What is important to choose is a port that is not currently used by an existing process on the machine. The default is 8888.
  5. Leave the rest of the components with the default set values.
  6. The template does an excellent job and is configured with sensible defaults. The defaults provide the following:
    • Target the recorded actions to Recording Controller added by the template.
    • Group a series of requests that constitute a page load. We will see more on this topic later.
    • Instruct the script recorder to bypass recording requests of a series of elements that are not relevant to test execution. These include JavaScript files, style sheets, and images.
    • Add the often-used components, including user-defined variables, HTTP Request Defaults, and HTTP Cookie Manager, to the test plan.
    • Add Thread Group and Recording Controller to the test plan.
    • Add a View Results Tree listener to view results of the test plan.
  7. Click on the Start button at the bottom of the HTTP(S) Test Script Recorder component.

With these settings, the test script recorder server will start on the port 7000, monitor all requests going through that port, and record them to a test plan using the default recording controller. For details, see the following screenshot:

How to do it…

HTTP(S) Test Script Recorder configuration

How it works…

These steps instruct JMeter to act as an HTTP proxy and listen for incoming and outgoing requests from your browser to the Internet on the assigned port, in our case 7000.

We now need to configure the browser to use the proxy server we just configured and redirect requests to the assigned port. There are several ways to do that, but we will focus here on the two most common ways.

There's more…

Modern browsers have a vibrant and active plugin ecosystem that allows you to extend the capabilities of your browser with an added plugin. FoxyProxy is one such plugin (http://getfoxyproxy.org/). It is a neat add-on for a browser that allows you to set up various proxy settings and toggle between them on the fly, without having to mess around with system settings on the machine. It really makes the work hassle free. Thankfully, FoxyProxy has a plugin for all major browsers including Google Chrome, Firefox, and Internet Explorer. If you are using any of those, you are lucky; head over and grab it!

Changing the machine system settings

The other common way to configure the browser is to change the system settings. The following are the details on how to configure Windows and Mac OS.

On Windows OS, perform the following steps to configure a proxy:

  1. Navigate to Start | Control Panel | Network and Internet | Internet Options.
  2. In the Internet Options dialog box, click on the Connections tab.
  3. Click on the LAN Settings button.
  4. To enable the use of a proxy server, check the Use a proxy server for your LAN (These settings will not apply to dial-up or VPN connections) box as shown in the following screenshot.
  5. In the proxy Address box, enter localhost in the IP address.
  6. In the Port number text box, enter 7000 (to match the port you set up for your JMeter proxy earlier).
  7. If you want to bypass the proxy server for the local IP addresses, select the Bypass proxy server for local addresses checkbox.
  8. Click on OK to complete the proxy configuration process. This is shown in the following screenshot:
    Changing the machine system settings

    Manually setting a proxy on Windows 7

On Mac OS, perform the following steps to configure a proxy:

  1. Navigate to System Preference | Network | Advanced….
  2. Go to the Proxies tab.
  3. Check Web Proxy (HTTP).
  4. Under Web Proxy Server, enter localhost.
  5. For port, enter 7000 (to match the port you set up for your JMeter HTTP proxy earlier).
  6. Do the same for Secure Web Proxy (HTTPS).
  7. Click on OK, as shown in the following screenshot:
    Changing the machine system settings

    Manually setting a proxy on Mac OS

For all other systems, consult the related operating system documentation.

With both JMeter's HTTP(S) Test Script Recorder and browser configured to use it, we are now ready to record a test. Perform the following steps:

  1. Point your browser to a website of your choice.
  2. Navigate to a few links.
  3. Notice that all user actions are being captured under the Thread Group component in the JMeter GUI.
  4. Stop the recording by stopping HTTP(S) Test Script Recorder.

The HTTP(S) Test Script Recorder server is set up to listen to requests on a particular port and then set the browser or system to redirect all requests to the assigned port. This allows us to capture the user actions as they interact with web applications, allowing us to replay their actions like we did in the Executing a test script recipe.

See also

  • The Recording scripts via the Chrome browser extension recipe in Chapter 8, Beyond the Basics
  • The Writing Test scripts through Ruby DSL recipe
  • The Converting HTTP web archives (HAR) to JMeter test plan recipe

Recording scripts via the Chrome browser extension

Recording test scripts is one you will be doing quite often. There are many alternatives to how we can record test scripts in JMeter.

How to do it…

In this recipe, we show you how to record test scripts with just a browser add-on installed on the Google Chrome browser. Perform the following steps:

  1. Install the Google Chrome browser if it's not already installed on your machine.
  2. Open the Chrome Web Store.
  3. Search for blazemeter on the web store.
  4. Install the BlazeMeter browser extension by clicking on the Free button.

    Note

    Once installed, a new BlazeMeter icon will be placed in the top-right corner of your browser toolbar.

  5. Click on the newly added BlazeMeter extension button in the top-right corner of your browser toolbar.
  6. Press the Record button.
  7. Point your browser to a website of your choice.
  8. Navigate through the website as you will normally do as a user.
  9. After the previous step, stop the recording and click on the export to jmx button (.jmx). This will download a copy of your script to your local machine.
  10. Open the exported test script in JMeter.
  11. Add View Results in Tree Listener to the test plan (Test plan | Add | Listener | View Results in Tree Listener).
  12. Run the exported test script with JMeter.
  13. View the results.

    Tip

    Exporting your recorded test plan requires a free account with BlazeMeter for you to be logged in.

    How to do it…

    Installing the BlazeMeter Chrome extension

The BlazeMeter Chrome extension should look similar to what is shown in the preceding screenshot. Using this extension, additional properties can be configured in the Advance section of the extension. The following is a screenshot of the extension:

How to do it…

Using the BlazeMeter Chrome extension

How it works…

The browser extension captures the user interaction with the website in the JSON format as long as the recorder is on.

When the recording is stopped, no further user actions are captured. After the export button has been clicked on the JSON format is then converted to the XML format, which JMeter understands and can work with. The downloaded recorded script can then be edited and run within JMeter like any other script.

There's more…

The extension allows you to selectively capture requests by providing you with the ability to pause recording in between the user interactions. It also allows you to filter out unwanted traffic you might not be interested in capturing in your test scripts through the include filter pattern text area.

Furthermore, the Advance menu option allows you to gain more control over which requests are captured in your script, allowing you to capture only the top-level requests (default), disable browser cache (default), disable recording cookies (default), and edit the setting before proceeding to run.

Finally, as BlazeMeter (one of the many providers offering distributed testing in the Cloud) provides this extension, it offers additional features including the following:

  • Allows you to run your scripts directly in the Cloud (see Chapter 5, Diving into Distributed Testing)
  • Allows you to simulate thousands of users with ease (see Chapter 5, Diving into Distributed Testing)

Converting HTTP web archives (HAR) to JMeter test plans

Another alternative to recording test scripts in JMeter is converting the existing HTTP web archives directly into JMeter test scripts.

How to do it…

This recipe shows you how to generate a test script from captured HTTP web requests in your browser. Perform the following steps:

  1. Install and launch the Google Chrome browser (if you don't already have it).
  2. Open Developer Tools by navigating to Tools | Developer Tools.

    Note

    Alternative key bindings: Mac OS (Command + Shift + I), Windows (Ctrl + Shift + I).

    How to do it…

    Opening Chrome Developer Tools

  3. Click on the Network tab.
  4. Make sure that the Preserve log checkbox is checked.
  5. Browse the websites as you normally would.
  6. Once you have finished browsing, open the developer tool window, right-click and select Copy All as HAR.
  7. Point your browser to https://flood.io/har2jmx.
  8. Copy the contents of the clipboard to the input box.
  9. Click on the Convert button.
  10. Launch the JMeter GUI.
  11. Open and examine the downloaded test script.
  12. Add View Results in Tree Listener to the test plan (Test plan | Add | Listener | View Results in Tree Listener).
  13. Save and run the exported test script.
  14. View the results.

Make sure that the Preserve log checkbox in the Network tab is checked to ensure all the user actions are captured, as illustrated in the following screenshot:

How to do it…

Preserve log checkbox in the Network tab

As shown in the following screenshot, while on the Network tab, right-click to see the Copy All as HAR option:

How to do it…

Copy All as HAR

How it works…

With the help of built-in browser tools and plugins, a browser is able to capture all interactions between a user and a web application into the JSON (JavaScript Object Notation) format known as the web archive (HAR). This resulting JSON object includes all the information about each request including HTTP headers, methods, query strings, and so on. Given the JSON object or a file with its content, the HAR to JMX converter can then read, parse, and construct JMeter elements for each user request, similar to what a JMeter HTTP proxy would have done.

There's more…

For command-line fans who do not wish to go through the Flood IO's website to do a conversion, there's a command-line tool that can be used to achieve the HAR TO JMX conversion. Har2jmeter located at http://seitenbau.github.io/har2JMeter/ is a utility written in the Groovy language. It's still in its infancy, so you might encounter a few quirks here and there. While testing it, one thing we found out is that it currently didn't play well with secure connections (HTTPS). Also, it didn't group requests into logical controllers. We mention it here just to make you aware that it exists and such bugs will probably be fixed in the near future.

Tip

For Firefox, the firebug plugin allows you the same capability to capture requests as HAR. Visit http://www.ehow.com/how_8789702_create-har-files-using-firebug.html to see how this can be accomplished.

Viewing and analyzing test results

When it comes to viewing your test results, JMeter comes with a vast number of components to aid this regard. Each component gives a different perspective into how to visualize your test results. Deciding which to use depends mostly on what kind of data you are interested in for a test run. Also, JMeter doesn't place a limit on how many of these listeners you can use on a test script, so it's not uncommon to see scripts with several results listeners.

How to do it…

In this recipe, we will cover three of the most popular built-in viewing components you will most likely need for your scripts. This is by no means an exhaustive list, so be sure to explore other viewing components. Perform the following steps:

  1. Launch JMeter.
  2. Open a previously recorded test script.
  3. Add a View Results Tree listener by navigating to Test plan | Add | Listener | View Results Tree.
  4. Add a Aggregate Report listener by navigating to Test plan | Add | Listener | Aggregate Report.
  5. Add View Results in table by navigating to Test plan | Add | Listener | View Results In Table.
  6. Start the test.
  7. Examine the results on each of the added results listeners. The entire process is shown in the following screenshot:
    How to do it…

    Adding the View Results Tree listener

The View Results Tree component is shown in the following screenshot:

How to do it…

How it works…

Once added, the test results will be written in real time to these listeners as the test is going on. Each listener gives a different data representation of the test results. Depending on what you are interested in, you will use a different set of listeners.

There's more…

There are graph listeners that plot graphs in real time, helping you visualize your test results in a graphical way. Also, there are extensions to JMeter that provide even additional result listeners just in case you need more than the built-in listener components.

Feeding data into a script

More often than not, we will need to provide varying input datasets to our scripts to simulate realistic user interaction with an application. Most applications, for instance, need to be authenticated against to view certain restrictive areas of the application. The way to accomplish this is by supplying an input datafile to the test script. The file is normally in the form of comma-separated values (CSV).

How to do it…

This recipe shows you how to feed data into your script to handle such scenarios. Perform the following steps:

  1. Download the book code samples from http://www.packtpub.com/jmeter-cookbook/book.

    Note

    Alternatively, you can clone the sample from the GitHub repository at http://github.com/jmeter-cookbook/bundled-code.

  2. Extract the contents of the ZIP file.
  3. Launch JMeter.
  4. Open the ch1_feed_me_data.jmx script from the scripts/ch1 directory.
  5. Add CSV Data Set Config to the test plan by navigating to Test Plan | Add | Config Element | CSV Data Set Config. Let's configure it:
    1. In the Filename box, enter input.txt.
    2. Leave the rest of the entries blank.
  6. Save and run the test. The execution of the script is shown in the following screenshot:
    How to do it…

How it works…

Assuming you haven't changed the default sharing mode of the added CSV dataset configuration, with each iteration run of our test plan, a line of the input.txt file is consumed. The consumed values are then turned into JMeter variables named after the first line of our input datafile, which are user and pass in our case. The values are then used further down the execution chain to fill in the username and password to access our application. In this particular test plan, as we have more threads than the amount of input data, the input data is recycled once the end of the file is reached.

There's more…

In our example, we have just provided the name of the file to read the input feed from. If you examine the CSV dataset configuration element closely, you will notice that it has other properties that can be filled in. These include the following:

  • Variable Names: Provide the comma-separated names of the variables. As we left this blank, the first line of our input script will be treated as the variable name.
  • Delimeter: Change to this option if you want to use a different delimiter other than a comma. For instance, you can use tab spaces (\t) or the colon symbol (:) instead of commas.
  • Allow Quoted Data: Set to True, if you would like to allow quoted data. For example, 'hello' as opposed to hello.
  • Recycle on EOF: In cases where you have more threads than the input data, this attribute specifies whether to allow the input data to be recycled. In such a case, the input feed will start from the beginning of the file once the data feed has run out.
  • Stop thread on EOF: This option determines whether to kill the thread has been reached.
  • Sharing mode: The default option is All meaning all threads; even those in a different thread group get to share the same data. The other options are Current thread group and Current thread, which specify that only the threads within a particular thread group and only a particular thread can retrieve data from the file, respectively.

Using timers

By default, when test scripts are recorded in JMeter, they contain no pauses between page requests. This is sometimes known as the think time in test scripts. In reality though, most users will frequently pause for a duration of time on every page before moving on to another page in the application. In JMeter, the ways to achieve these pauses are through timers. JMeter comes with a wealth of timers to achieve this purpose.

How to do it…

In this recipe, we will show you how to mimic realistic user behaviors using the JMeter timers.

  1. Launch JMeter.
  2. Open the ch1_add_timers.jmx test script located in the scripts/ch1 directory.
  3. Add Gaussian Random Timer by navigating to Test plan | Add | Gaussian Random Timer.
  4. Change Deviation (in milliseconds) from 100 to 1000.
  5. Change Constant Delay Offset (in milliseconds) from 300 to 500.
  6. Save and execute the test script.

How it works…

With our configuration, each thread will pause for a duration of 0.5 to 1.5 seconds after each request before proceeding to the next request. This is because we applied the timer at the root level of the test plan. If we wanted to have pauses after each logical page rendering, we will add a timer at the transaction controller level. This option is mostly what you will go with as a single rendered web page often consists of multiple requests.

There's more…

There are many more timers that come bundled with JMeter even through additional plugins that serve different purposes. There are timers that simulate constant delay, constant throughput, random delay, and so much more. Depending on your use case and what you are trying to simulate, you will choose one or several of these.

Managing HTTP user sessions

Most websites have a means of authenticating users, thereby enabling them to gain access to protected data or content that only pertains to them. Also, it is very common for websites to give users different roles based on what the user will be doing. For instance, a user called Joe could be given admin privileges while Susan is only given user privileges. Whatever the case, JMeter has a way to maintain HTTP user sessions for your test scripts.

How to do it…

In this recipe, we will detail how to accomplish this with JMeter. Perform the following steps:

  1. Launch JMeter.
  2. Open the add_cookie_manager.jmx test script.
  3. Run the test plan.
  4. Notice the failed requests, even though the log in request succeeded:
    • The Request immediately option following the log in request is indicative of this. The Request tab shows no cookies were sent with the request. Refer to the following code:
      	GET http://evening-citadel-2263.herokuapp.com/
      	 [no cookies]
      	Request Headers:
      	Connection: keep-alive
      	Host: evening-citadel-2263.herokuapp.com
      	User-Agent: Apache-HttpClient/4.2.6 (java 1.5)
    • Furthermore, our response assertions fail, as subsequent requests were not associated with the existing user, but were treated as new requests.
  5. Clear the results (Mac OS: Command + Shift + E and Windows: Ctrl + Shift + E).
  6. Add HTTP Cookie Manager to the test plan by navigating to Test plan | Add | Config Element | HTTP Cookie Manager.
  7. Save and run the test plan.
  8. Observe the results in the View Results in Tree listener and notice how all the requests now succeed:
    • If you observe the request immediately following the log in request, you will notice that the cookie information is correctly sent with the request, thanks to the added HTTP Cookie Manager. You should see something similar to this:
      	GET http://evening-citadel-2263.herokuapp.com/
      	Cookie Data:		     	connect.sid=s%3AWN5ITZxWEKyzmmAB5sct7PjA.6UAJ36%2F9%2BWFQPjdzA%2B7%2B1NL4%2Bf0HzC %2BOQI%2Bol0V0eJ0
      	Request Headers:
      	Connection: keep-alive
      	Host: evening-citadel-2263.herokuapp.com
      	User-Agent: Apache-HttpClient/4.2.6 (java 1.5) 

How it works…

The HTTP Cookie Manager stores and sends cookies like a web browser does. The cookie of any request that contains one is automatically extracted and stored by the component to be used for all future requests from that particular thread. Each JMeter thread gets its own session just like in a regular web browser to prevent users' sessions from overlapping with each other.

There's more…

Apart from the automatically extracted cookies by the HTTP Cookie Manager component, JMeter provides a way to add user-defined cookie values to a test plan. Unlike their automatically extracted counter parts, once defined, all threads executing in the test plan will share these values.

Testing Single Page Applications (SPAs)

Single-page applications are the new wave of web applications being developed in today's technological industry. The benefits of developing such applications can't be overstated. They relieve the servers of enormous load and bring faster responsiveness to the end user. They are architected differently from traditional web applications, which make them slightly different to develop test scripts for.

How to do it…

In this recipe, we will work through creating a script for an SPA. Perform the following steps:

  1. Launch JMeter.
  2. Add HTTP(S) Test Script Recorder and set it up for recording (see the Recording a script via JMeter HTTP proxy recipe).
  3. Click the Add suggested Excludes button.
  4. Start the HTTP(S) Test Script Recorder.
  5. Point your browser to http://angular.github.io/peepcode-tunes/public/.
  6. Add the two available albums (on the right) to your playlist (on the left).
  7. Randomly select a song to listen to.
  8. Use the buttons on the player to jump to the next or previous song or pause them.
  9. Stop the HTTP(S) Test Script Recorder.
  10. Add a listener to your test plan.
  11. Save and run the test plan.

How it works…

The actions of the user are tracked and recorded via the script recorder we set up in step 2. Like traditional web applications, we record all actions and exclude irrelevant static resources, such as images, JavaScript, and style sheets. Every call that makes a server call to backend services is also recorded as part of the test plan and is available for replay during test execution. At the end, we have a script that is almost identical to what we would get when recording a traditional web application.

There's more…

Most SPAs tend to be JavaScript-intensive. As JMeter isn't a web browser, JavaScripts embedded within a page or included from a separate file altogether won't be executed. With this in mind, it means JMeter can't be accurately used to measure page load times or browser DOM rendering. What it can do, however, is record any calls made to the server from your JavaScript files and play those back when the test is re-executed.

Such calls have an impact on the servers and are critical to measure to know how slow or fast a user's experience will be when the application is under considerable load.

Testing AJAX-centric applications

In today's stack of web applications, it is almost unthinkable to build an application without some dynamic content being retrieved from a backend service. Most of the time, these applications tend to lean towards partial page fresh. That is, only the needed sections of a rendered page are refreshed as opposed to the whole page loading its entire content again. This leads to more responsive pages, which improves the overall experience of the user.

How to do it…

In this recipe, we will walk through how you can test such applications using JMeter. Perform the following steps:

  1. Launch JMeter.
  2. Add HTTP(S) Test Script Recorder and set it up for recording (see the Recording a script via JMeter HTTP proxy recipe).
  3. Click the Add suggested Excludes button.
  4. Start the HTTP(S) Test Script Recorder.
  5. Point your browser to https://maps.google.com.
  6. Perform a couple of searches in the provided search box (for example, pizza, restaurants, hotels, and so on).
  7. Click on a few of the returned results.
  8. Repeat steps 6 and 7 two more times.
  9. Stop the HTTP(S) Test Script Recorder.
  10. Add a listener to your test plan.
  11. Save and run the test plan.

How it works…

The actions of the user are tracked and recorded via the script recorder we set up in step 2. Like traditional web applications, we record all actions and exclude irrelevant static resources, such as images, JavaScript, and style sheets. Calls that trigger backend server calls are trapped and are available for replay later. At the end, we have a script that is almost identical to what we would get when recording a traditional web application.

There's more...

AJAX-centric applications tend to involve a lot of asynchronous server requests made from within the client (frontend). These calls are normally made from embedded script tags within a view technology, for example, HTML, Java Server Pages (JSP), Groovy Server Pages (GSP), or from an included JavaScript file in the page. As such, JMeter records all such server requests and they can be played back at the time of running our test plans. This allows us to simulate the intended load on our servers, as though the application was the one making the AJAX calls.

Left arrow icon Right arrow icon

Description

This book is great for you if you are a developer, quality assurance engineer, tester, or test manager who is looking to get a firmer grasp of elementary, deep, and advanced testing concepts using Apache JMeter. It’s assumed you have access to a computer and an Internet connection. No prior testing or programming experience is required, but would be helpful.
Estimated delivery fee Deliver to Great Britain

Standard delivery 1 - 4 business days

£4.95

Premium delivery 1 - 4 business days

£7.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 29, 2014
Length: 228 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988280
Vendor :
Apache
Category :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Great Britain

Standard delivery 1 - 4 business days

£4.95

Premium delivery 1 - 4 business days

£7.95
(Includes tracking information)

Product Details

Publication date : Oct 29, 2014
Length: 228 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988280
Vendor :
Apache
Category :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 102.97
Performance Testing with JMeter 2.9
£32.99
JMeter Cookbook
£36.99
Performance Testing with JMeter, 2nd Edition
£32.99
Total £ 102.97 Stars icon
Banner background image

Table of Contents

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

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(8 Ratings)
5 star 25%
4 star 50%
3 star 0%
2 star 12.5%
1 star 12.5%
Filter icon Filter
Top Reviews

Filter reviews by




Vividh S Viswanatha Jan 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
JMeter is fairly an easy tool to use! However when you start to use JMeter and configure it to the way you would like to run a performance test, you often get stuck and find yourself looking for information on JMeter online documentation. Don't get me wrong, JMeter has very good documentation but doesn’t have good practical examples or integration documentation with other tools like JMeter plugins, Blazemeter and continues integration tools.Now getting to this book, it has everything and more. In fact if you don’t know anything about JMeter you can still buy this book and as the only book it has a dedicated chapters to introduce you to JMeter and take you to the next level and help setup a performance test framework for your project.This book has some recipes and information which cannot be found anywhere else at least in the details provide by the author in this book. Few of the examples for this are with regards to Ruby DSL to write JMeter test scripts and also integration with few of the cloud service like Blazemeter and Flood.io. After reading this book I plan to make changes to my current JMeter framework.Few of the recipes require you to use a specific tool, which might not be relevant to your setup or what you require in your setup. Hence you might have to at time to modify the recipe to match your setup.I recommend this book to anyone, who is getting started on performance testing using JMeter and would like to get some ideas on how to setup JMeter. However please note that this is a book on JMeter not on the concepts of performance testing.
Amazon Verified review Amazon
TYS Feb 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
なんとなく最低限のパフォーマンステストだけしていた自分には目からうろこのアドオンや使い方が乗っていて非常に参考になりました。今まではシナリオ作成から、レスポンスタイムとスループットの測定に結構な手間をかけて測定していましたが、それが簡単にできるようになったのが大変なコスト削減ですぐ元が取れました。JMeter使いの方は一見の価値有りです。
Amazon Verified review Amazon
nandan Mar 10, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book is great for starters.I was new to JMeter and this book is a perfect guide to begin with.Also a quick refresher if you haven't used JMeter in a while. Explanation is simple and easy to understand step by step instructions on getting set-up to run your load and performance tests. It also covers advanced topics too.
Amazon Verified review Amazon
Clare Avieli Jan 21, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Great for all JMeter users - from total beginners to very advanced users. It covers a wide spectrum of topics, with clear step-by-step instructions for each one. This is a useful book to have at hand while you're load testing, you can just dip in and out of it to quickly and easily find the solutions you need. It's also a fantastic way to generally extend your capabilities and knowledge. Well worth buying.
Amazon Verified review Amazon
Amazon Customer Jan 19, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Very Helpful and useful. Nice Quick reference guide.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela