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.
Join the DZone community and get the full member experience.
Join For FreeSome 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:
- Open dev tools with <F12>
- Tab "Network"
- Check Keep Activer "Keep logs or Exchanges". (Optional) If needed, delete the exchanges before browsing
- Navigate the application to generate network exchanges (wait a few seconds between pages in order to group the exchanges afterward)
- Save exchanges in HAR format
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 :
- Open dev tools with <F12>
- Tab "Network"
- Record button is ON.
- "Preserve log" is checked. (Optional) If needed, delete the exchanges before browsing
- Navigate the application to generate network exchanges (wait a few seconds between pages in order to group the exchanges afterward)
- Save exchanges in HAR format "Export HAR ..."
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:
- Create the HAR
- Launch the conversion tool
- The JMeter script .jmx is created
- The record.xml exchange file is created
The plugin is one of the tools found in the “Tools” menu of the JMeter interface.
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 thejmx_out
is the file name of har_in without the extension with suffix".jmx"
- e.g.
har_in = myhar1.har, jmx_out
is empty thenfile_out
will bemyhar1.jmx
- e.g.
record_out
create the record XML file from the har file (could be open with the Listener View Results Tree)- e.g.
record_out = record.xml
- e.g.
new_tc_pause
time 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, parameternew_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 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
Launch the "Convertor tool":
Tool results: Open the script created and the record.xml in a 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
The demonstration uses the JPetstore web application.
Opinions expressed by DZone contributors are their own.
Comments