6 |
7 | # Convert a HAR (Http ARchive) file to a JMeter script and a Record XML file.
8 | [](https://central.sonatype.com/artifact/io.github.vdaburon/har-convertor-jmeter-plugin)
9 | [](https://github.com/vdaburon/CreateHtmlForFilesInDirectory/blob/main/LICENSE)
10 | 
11 | [](https://jmeter.apache.org/)
12 |
13 | An article about motivations to create this tool: https://dzone.com/articles/convert-a-har-file-to-jmeter-script
14 |
15 | Since version 7.0, **Websocket** is manage with samplers from the plugin "WebSocket Samplers by Peter Doornbosch".
16 |
17 | ## GUI interface in the JMeter Tools Menu
18 | This tool is present in the Menu Tools > vdn@github - HAR Convertor Tool
19 |
20 | 
21 |
22 | When you click and the menu line "vdn@github - HAR Convertor Tool", the tool GUI is display
23 |
24 | 
25 |
26 | ### Parameters
27 | Parameters are :
28 | * har_in the HAR file to read (exported HAR from Web Browser : Chrome, Firefox, Edge ...)
29 | * 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"
30 | e.g. har_in = myhar1.har, jmx_out is empty then file_out will be myhar1.jmx
31 | * record_out create the record xml file from the har file (could be open with the Listener View Results Tree)
32 | e.g. record_out = record.xml
33 | * add_result_tree_record, add a View Result Tree to view the Recording XML File Generated (default true), the record_out must be not empty
34 | * ws_with_pdoornbosch, create WebSocket Sampler if HAR contains WebSocket Connection (ws or wss) and WebSocket Exchange message (default false). Need this JMeter plugin "WebSocket Samplers by Peter Doornbosch" to open generated JMeter script.
35 | * external_file_infos, external csv file contains information about Timestamp, Transaction Name, date start or end.
36 | e.g. external_file_infos = myappli_transactions.csv
37 | * new_tc_pause time between 2 urls to create a new page (Transaction Controller) (default 5000 = jmeter property value : proxy.pause=5000)
38 | * e.g. 5000 for 5 sec between 2 urls
39 | * page_start_number, set the start page number for partial recording (default 1, must be an integer > 0)
40 | * sampler_start_number, set the start sampler number for partial recording (default 1, must be an integer > 0)
41 | * filter_include, the regular expression matches the URL to Include (first filter)
42 | * default all = empty (no filter)
43 | * e.g. filter_include=https://mysite.com/.*
44 | * filter_exclude, the regular expression matches the URL to Exclude (second filter)
45 | * default all = empty (no filter)
46 | * e.g. filter_exclude=https://notmysite.com/.*
47 | * or filter statics, filter_exclude=(?i).*\\.(bmp|css|js|gif|ico|jpe?g|png|swf|eot|otf|ttf|mp4|woff|woff2|svg)
48 | * remove_headers, remove a list of http headers (comma separator, case insensitive), e.g: -remove_headers "User-Agent,Pragma,X-TOKEN"
49 | * add_pause checkbox, add Flow Control Action Pause, parameter new_tc_pause must be > 0 (default true)
50 | * remove_cookie checkbox , remove header with cookie because add a Cookie Manager in the script (default true)
51 | * remove_cache_request checkbox, remove cache request header because add a Cache Manager in the script (default true)
52 | * har created with lrwr, the har file has been generated with LoadRunner Web Recorder Chrome extension and contains Transaction Name, expected values : true or false (default false = unchecked)
53 |
54 |
55 | Status, the status line contains the tool status or the tool result.
56 |
57 | e.g. : Status Results **OK**
58 | * Tool HAR Convertor Finished OK, fileJmxOut=C:\Temp\script1.jmx
59 | * Tool HAR Convertor Finished OK, fileJmxOut=C:\Temp\script1.jmx AND recordXmlOut=C:\Temp\record.xml
60 |
61 | e.g. : Status Results **KO**
62 | * Tool HAR Convertor Finished KO, CAN'T READ HAR fileHarIn = C:\Temp\harzzzz.har
63 | * Tool HAR Convertor Finished KO, exception = java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 2 (.))
64 | * Tool HAR Convertor Finished KO, exception = net.sf.saxon.trans.XPathException: Failed to create output file file:/c:/toto.jmx
65 |
66 | ### Action buttons
67 | * "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.
68 | * "CONVERT", generates the JMeter script and record.xml file if set.
69 |
70 | ## Creating a har file and run the tool har-to-jmx-convertor to simulate recording from the JMeter recording template
71 | This tool har-to-jmx-convertor try to **simulate** a script JMeter and a record xml file recording from the **JMeter Recording Template**.
72 |
73 | ### JMeter Recording Template and HTTP(S) Test Script Recorder - The standard way to record
74 | The JMeter Recording Template :
75 | 
76 |
77 | The result of recording with JMeter "HTTP(S) Test Script Recorder" :
78 | 
79 |
80 | ### HAR created on a Browser (e.g. Firefox) - The new way with the convertor tool
81 | Record the navigation in the web application with Developer tool : **Network** and **save** exchanges in **HAR** file format :
82 | 
83 |
84 | Launch the "Convertor tool" :
85 | 
86 |
87 | Tool results : Open the script created and the record.xml in a View Results Tree
88 | 
89 |
90 | ### Standard HAR file created with Firefox, Chrome, Edge with external csv file for transaction information
91 | You could add an external file that contains information about transaction name start and end.
92 |
93 | 
94 |
95 | The format is :
96 | - Timestamp iso format GMT;TRANSACTION;transaction name;start for starting a new transaction
97 | - Timestamp iso format GMT;TRANSACTION;transaction name;stop for ending transaction the precedent transaction
98 | - Separator ";"
99 | - Charset UTF-8
100 |
101 | E.g :
102 |
108 |
109 | A simple tool named "create-external-file-for-har" create easily this csv file. https://github.com/vdaburon/create-external-file-for-har
110 |
111 | You need to select the csv file in the text field : "(Optional) External csv file with transaction info (to read) "
112 |
113 | ### HAR created with BrowserUp Proxy
114 | This tool is compatible with Har file generated with BrowserUp Proxy.
115 |
116 | The BrowserUp Proxy create a har and could filter url or content (no binary).
117 |
118 | The proxy client could be a browser or a client http in an application.
119 |
120 | BrowserUp Proxy could be embedded in a java application or in Selenium java code application.
121 |
122 | 
123 |
124 | The BrowserUp Proxy **active** project is available at this url :
125 | [Goto the BrowserUp Proxy active project](https://github.com/valfirst/browserup-proxy)
126 |
127 | Note : The BrowserMod Proxy tool is no more active (since september 2017) and it's recommended to migrate to BrowerUp proxy https://github.com/valfirst/browserup-proxy the "valfirst" GitHub username is important.
128 |
129 | ### HAR created in Chrome Browser with the OpenText Professional Performance Engineering (LoadRunner) Web Recorder Chrome Extension
130 | This tool is compatible with Har file generated with the LoadRunner Web Recorder Chrome Extension.
131 |
132 | The main advantage is to declare **Transaction Names when recording** and navigate to the web site. This transactions will be Page Names (Transaction Controllers names) in the JMeter script.
133 |
134 | 
135 |
136 | The OpenText Professional Performance Engineering (LoadRunner) Web Recorder Chrome Extension is available at this url :
137 | [Download the Recorder extension for Chrome : "HarGeneratorChrome"](https://marketplace.opentext.com/appdelivery/content/recorder-extension-for-chrome)
138 |
139 | You need to check to checkbox "HAR was generated with LoadRunner Web Recorder and Transaction Names" to indicate that is a HAR file generated with LoadRunner Web Recorder (lrwr), default false (unchecked).
140 |
141 | ## Websocket use the plugin "WebSocket Samplers by Peter Doornbosch"
142 | If your Har file contains WebSocket Connection and Messages, check the checkbox ws_with_pdoornbosch (set true), this tool will try to create Websocket Samplers in the JMeter script generated and the exchanges in the Recording XML file if you set the record xml file name.
143 |
144 | Documentation at : https://bitbucket.org/pjtr/jmeter-websocket-samplers/src/master/
145 |
146 | The HAR is record from **Chrome** Browser not Firefox Browser and not Egde Browser (research in har file the attribute : '_webSocketMessages').
147 |
148 | Currently limitation to only one websocket connection and multi text messages (send or receive) in this websocket connection (binary message is not tested).
149 |
150 | Text message could be on "STOMP" format (https://en.wikipedia.org/wiki/Streaming_Text_Oriented_Messaging_Protocol) or no "STOMP" (simple text).
151 |
152 | Need the plugin "WebSocket Samplers by Peter Doornbosch" to open the generated script that contain Websocket Samplers.
153 |
154 | This demonstration use the web site : https://websocket.org/tools/websocket-echo-server/
155 |
156 | 
157 |
158 | If you click on the checkbox "Create WebSocket Sampler if HAR contains WebSocket Connection" but the JMeter **have not the plugin** "WebSocket Samplers by Peter Doornbosch" a warning message is display and the button "CONVERT AND LOAD GENERATED SCRIPT" is disable.
159 |
160 | 
161 |
162 |
163 | ## More documentation from har-to-jmeter-convertor CLI Tool
164 | This plugin use a **library** from the Command Line Interface tool (har-to-jmeter-convertor)
165 | For more documentation look at README from [har-to-jmeter-convertor](https://github.com/vdaburon/har-to-jmeter-convertor)
166 |
167 | ## Command line tool (CLI)
168 | This tool could be use with script shell Windows or Linux.
169 |
170 | Scripts shell are in <JMETER_HOME>\bin
171 | * har-convertor-to-jmeter.cmd for Windows OS
172 | * har-convertor-to-jmeter.sh for Linux/Mac OS
173 |
174 | Help to see all parameters :
175 |
176 |
177 | C:\apache-jmeter\bin>har-convertor-to-jmeter.cmd -help
178 |
179 | usage: io.github.vdaburon.jmeter.har.HarForJMeter [-add_pause <add_pause>] [-add_result_tree_record
180 | <add_result_tree_record>] [-external_file_infos <external_file_infos>] [-filter_exclude <filter_exclude>]
181 | [-filter_include <filter_include>] -har_in <har_in> [-help] -jmx_out <jmx_out> [-new_tc_pause <new_tc_pause>]
182 | [-page_start_number <page_start_number>] [-record_out <record_out>] [-remove_cache_request
183 | <remove_cache_request>] [-remove_cookie <remove_cookie>] [-remove_headers <remove_headers>]
184 | [-sampler_start_number <sampler_start_number>] [-use_lrwr_infos <use_lrwr_infos>] [-ws_with_pdoornbosch
185 | <ws_with_pdoornbosch>]
186 | io.github.vdaburon.jmeter.har.HarForJMeter
187 | -add_pause <add_pause> Optional boolean, add Flow Control Action Pause after Transaction
188 | Controller (default true)
189 | -add_result_tree_record <add_result_tree_record> Optional boolean, add 'View Result Tree' to view the record.xml file
190 | created (default true), record_out must be not empty
191 | -external_file_infos <external_file_infos> Optional, csv file contains external infos : timestamp transaction
192 | name and start or end
193 | -filter_exclude <filter_exclude> Optional, regular expression to exclude url
194 | -filter_include <filter_include> Optional, regular expression to include url
195 | -har_in <har_in> Har file to read (e.g : my_file.har)
196 | -help Help and show parameters
197 | -jmx_out <jmx_out> JMeter file created to write (e.g : script.jmx)
198 | -new_tc_pause <new_tc_pause> Optional, create new Transaction Controller after request ms, same
199 | as jmeter property : proxy.pause, need to be > 0 if set. Usefully
200 | for Har created by Firefox or Single Page Application (Angular,
201 | ReactJS, VuesJS ...)
202 | -page_start_number <page_start_number> Optional, the start page number for partial recording (default 1)
203 | -record_out <record_out> Optional, file xml contains exchanges likes recorded by JMeter
204 | -remove_cache_request <remove_cache_request> Optional boolean, remove cache header in the http request (default
205 | true because add a Cache Manager)
206 | -remove_cookie <remove_cookie> Optional boolean, remove cookie in http header (default true because
207 | add a Cookie Manager)
208 | -remove_headers <remove_headers> Remove a list of headers (comma separator, case insensitive),
209 | e.g:User-Agent,Pragma,X-TOKEN
210 | -sampler_start_number <sampler_start_number> Optional, the start sampler number for partial recording (default 1)
211 | -use_lrwr_infos <use_lrwr_infos> Optional, the har file has been generated with LoadRunner Web
212 | Recorder and contains Transaction Name, expected value :
213 | 'transaction_name' or don't add this parameter
214 | -ws_with_pdoornbosch <ws_with_pdoornbosch> Optional boolean, Manage websocket messages with the JMeter plugin
215 | from Peter DOORNBOSH (default false), if true need the plugin from
216 | Peter DOORNBOSH to open the generated script
217 | E.g : java -jar har-for-jmeter-<version>-jar-with-dependencies.jar -har_in myhar.har -jmx_out scriptout.jmx -record_out
218 | recording.xml -add_result_tree_record true -new_tc_pause 5000 -add_pause true -filter_include "https://mysite/.*"
219 | -filter_exclude "https://notmysite/*" -page_start_number 50 -sampler_start_number 250 -ws_with_pdoornbosch false
220 | -remove_headers "User-Agent,Pragma"
221 |
222 |