DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • 10 Most Important Tools to Boost Your Productivity as a Developer
  • Apache Spark 3 to Apache Spark 4 Migration: What Breaks, What Improves, What's Mandatory
  • Zero Trust, Build High Scale TLS Termination Layer
  • Model Context Protocol Vs Agent2Agent: Practical Integration with Enterprise Data

Trending

  • Agentic Testing: Moving Quality From Checkpoint to Control Layer
  • The ORM Is Over: AI-Written SQL Is the New Data Access Layer
  • Ujorm3: A New Lightweight ORM for JavaBeans and Records
  • Smart Deployment Strategies for Modern Applications
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Motivation for Creating a Tool To Convert a HAR File to JMeter Script and a Manual

Motivation for Creating a Tool To Convert a HAR File to JMeter Script and a Manual

Recording a JMeter script via the classic method of using a "Recording template" requires several operations and requires high administrator rights on the machine.

By 
Vincent DABURON user avatar
Vincent DABURON
·
Apr. 03, 24 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
19.7K Views

Join the DZone community and get the full member experience.

Join For Free

Some Complications To Create a Script With JMeter

Recording a JMeter script via the classic method of using a "Recording template" requires several operations and requires high administrator rights on the machine.

In particular, it's necessary to declare for HTTPS sites the temporary JMeter certificate generated when starting the recording in the browser (with Firefox) or in Windows because, in HTTPS protocol, the JMeter recorder behaves like a "man in the middle" with one connection HTTPS between the browser and JMeter and another HTTP connection between JMeter and the application. So JMeter can listen to the exchanges.

You must then modify the browser proxy settings in order to use the JMeter recording proxy “HTTP(S) Test Script Recorder.”

In some cases, particularly on client PCs, browser network settings are protected by security policies and you cannot change browser proxy settings.

A useful solution is to use Firefox Portable (a simple zip to unzip) which does not need significant rights to install but may still be prohibited by the client's security policy and certain web applications may not work well with Firefox because they are developed only for Edge or Chrome.

Another reason for this tool is that Apache JMeter does not support the recording of the "HTTP(S) Test Script Recorder" of exchanges using the WebSocket protocol (ws and wss) and it crashes.

An alternative solution is to retrieve network exchanges at the browser level and save these exchanges in a standard HAR format (HTTP ARchive) then use a tool that will read the exchanges from the HAR file to generate a JMeter script and also a Record.xml file with a result close to the “classic” recording. This solution does not need elevated rights on the PC to work.

The advantage is that the HAR format is common to browsers.

Creating a HAR File in a Browser

Creating a HAR file in a browser is quite similar depending on the browser (Firefox, Chrome, or Edge).

For Firefox

Firefox keeps the content of exchanges, in particular the content of uploaded files.

In Firefox:

  1. Open dev tools with <F12>
  2. Tab "Network"
  3. Check Keep Activer "Keep logs or Exchanges". (Optional) If needed, delete the exchanges before browsing
  4. Navigate the application to generate network exchanges (wait a few seconds between pages in order to group the exchanges afterward)
  5. Save exchanges in HAR format

JPetStore

For Chrome

We note that Chrome does not keep the content of exchanges when uploading files and the HAR is often smaller than that recorded with Firefox.

In Chrome :

  1. Open dev tools with <F12>
  2. Tab "Network"
  3. Record button is ON.
  4. "Preserve log" is checked. (Optional) If needed, delete the exchanges before browsing
  5. Navigate the application to generate network exchanges (wait a few seconds between pages in order to group the exchanges afterward)
  6. Save exchanges in HAR format "Export HAR ..."

steps

har-convertor-jmeter-plugin Tool

Installing the Plugin in JMeter

The recommended solution to install the plugin is to use the plugin manager of the site.

The plugin name is « vdn@github - har-convertor-jmeter-tool »

The tool also comes with 2 shell scripts (1 for Windows and 1 for Linux) to launch the conversion tool in the Command Line Interface.

A 2nd solution is to download the tool in its latest version found in the Release part of the GitHub project.

And place the har-convertor-jmeter-plugin-<version>-jar-with-dependencies.jar jar file in the <JMETER_HOME>/lib/ext directory

Using the Plugin in JMeter

The steps of conversion of the tool are schematically as follows:

  1. Create the HAR
  2. Launch the conversion tool
  3. The JMeter script .jmx is created
  4. The record.xml exchange file is created

file created

The plugin is one of the tools found in the “Tools” menu of the JMeter interface.

tools

Tool interface and settings:

tool interface and settings

Parameters

Parameters are :

  • har_in the HAR file to read (exported HAR from Web Browser: Chrome, Firefox, Edge ...)
  • jmx_out the file JMeter script generated, if the text field is empty then the jmx_out is the file name of har_in without the extension with suffix ".jmx"
    • e.g. har_in = myhar1.har, jmx_out is empty then file_out will be myhar1.jmx
  • record_outcreate the record XML file from the har file (could be open with the Listener View Results Tree)
    • e.g. record_out = record.xml
  • new_tc_pausetime between 2 URLs to create a new page (Transaction Controller) (default 5000 = JMeter property value: proxy.pause=5000)
    • e.g. 5000 for 5 sec between 2 URLs
  • page_start_number, set the start page number for partial recording (default 1, must be an integer > 0)
  • sampler_start_number, set the start sampler number for partial recording (default 1, must be an integer > 0)
  • filter_include, the regular expression matches the URL to Include
  • default all = empty (no filter)
    • e.g. filter_include=https://mysite.com/.*
  • filter_exclude, the regular expression matches the URL to Exclude
  • default all = empty (no filter)
    • e.g. filter_exclude=https://notmysite.com/.*
    • or filter statics, filter_exclude=(?i).*\.(bmp|css|js|gif|ico|jpe?g|png|swf|eot|otf|ttf|mp4|woff|woff2)
  • add_pause checkbox, add Flow Control Action Pause, parameter new_tc_pause must be > 0 (default true)
  • remove_cookie checkbox, remove header with cookie because add a Cookie Manager in the script (default true)
  • remove_cache_request checkbox, remove cache request header because add a Cache Manager in the script (default true)

Status, the status line contains the tool status or the tool result.

e.g.: Status Results OK

  • Tool HAR Convertor Finished OK, fileJmxOut=C:\Temp\script1.jmx
  • Tool HAR Convertor Finished OK, fileJmxOut=C:\Temp\script1.jmx AND recordXmlOut=C:\Temp\record.xml

e.g.: Status Results KO

  • Tool HAR Convertor Finished KO, CAN'T READ HAR fileHarIn = C:\Temp\harzzzz.har
  • Tool HAR Convertor Finished KO, exception = java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 2 (.))
  • Tool HAR Convertor Finished KO, exception = net.sf.saxon.trans.XPathException: Failed to create output file file:/c:/toto.jmx

Action Buttons

  • "CONVERT AND LOAD GENERATED SCRIPT", generates the JMeter script and record.xml file if set, next if no error LOAD the generated script in the current JMeter.
  • "CONVERT", generates the JMeter script and record.xml file if set.

Comparison of the “Classic” Recording With the Recording Template and the Conversion Tool

Create a HAR File and Run the Tool HAR-To-JMX-Convertor To Simulate Recording From the JMeter Recording Template

This tool har-to-jmx-convertor try to simulate a script JMeter and a record XML file recording from the JMeter Recording Template.

JMeter Recording Template and HTTP(S) Test Script Recorder: The Standard Way to Record

The JMeter Recording Template

The JMeter Recording Template

The result of recording with JMeter "HTTP(S) Test Script Recorder"

The result of recording with JMeter "HTTP(S) Test Script Recorder"

HAR Created on a Browser (e.g. Firefox): The New Way With the Converter Tool

Record the navigation in the web application with the Developer tool: 

Network and save exchanges in HAR file format  

Network and save exchanges in HAR file format

Launch the "Convertor tool":

Convertor tool

Tool results: Open the script created and the record.xml in a View Results Tree 

View Results Tree

Comparison of the HAR-Convertor-JMeter-Plugin Tool With Other Conversion Solutions

BlazeMeter Converter

Converting a JMeter script with BlazeMeter.

The output of the BlazeMeter conversion against the har-convertor-jmeter-plugin tool.

The conversion is a JMeter script, however:

  • No page splitting (if delay of n seconds between URLs)
  • No pause between pages but timers (Uniform Random Timer) under each request
  • No HTTP Default with the hostname + scheme + port hardcoded on all HTTP samplers
  • No filter in include or exclude URLs
  • No URL numbering (prefix)
  • No record.xml file, this file is important for making future correlations
  • Limit upload size for the HAR file
  • Sensitive data may be transmitted to the BlazeMeter site contained in the HAR file

Plugin “HAR (HTTP Archive) Import” From Qytera-Gmbh

Another plugin for JMeter named: "HAR (HTTP Archive) Import" is also located in the "Tools" menu of JMeter

The conversion is a JMeter script, however:

  • No page splitting (if delay of n seconds between URLs)
  • No pause between pages but timers (Constant Timer) under each request
  • No HTTP Default with the hostname + scheme + port hardcoded on all HTTP samplers
  • No filter in include or exclude URLs
  • No URL numbering (prefix)
  • No record.xml file, this file is important for making future correlations

Links

Link to GitHub project.

The demonstration uses the JPetstore web application.

Google Chrome HTTPS Apache JMeter

Opinions expressed by DZone contributors are their own.

Related

  • 10 Most Important Tools to Boost Your Productivity as a Developer
  • Apache Spark 3 to Apache Spark 4 Migration: What Breaks, What Improves, What's Mandatory
  • Zero Trust, Build High Scale TLS Termination Layer
  • Model Context Protocol Vs Agent2Agent: Practical Integration with Enterprise Data

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook