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

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.

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