Skip to content

Commit

Permalink
Version 3.0, Add Load generated script if no error. File Chooser sele…
Browse files Browse the repository at this point in the history
…ct only file and no directory.
  • Loading branch information
DABURON Vincent committed Mar 18, 2024
1 parent 04b5c71 commit 5f5a473
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ e.g. : Status Results **KO**
* 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.

## Creating 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**.
Expand Down Expand Up @@ -131,9 +134,11 @@ The maven groupId, artifactId and version, this plugin is in the **Maven Central
```xml
<groupId>io.github.vdaburon</groupId>
<artifactId>har-convertor-jmeter-plugin</artifactId>
<version>2.0</version>
<version>3.0</version>
```
## Versions
Version 3.0 date 2024-03-18, Add Load generated script if no error. File Chooser select only file and no directory.

Version 2.0 date 2024-03-12, for POST multipart/form-data don't put the content of the file in the Record.xml file because binary content could be large and not XML compatible. Add parameters : page_start_number and sampler_start_number to facilitate partial recording of website navigation.

Version 1.0 date 2024-03-11, First Release.
Expand Down
Binary file modified doc/images/har_convertor_tool_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/images/jmeter_script_record_created.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.vdaburon</groupId>
<artifactId>har-convertor-jmeter-plugin</artifactId>
<version>2.0</version>
<version>3.0</version>
<packaging>jar</packaging>

<name>Apache JMeter Plugin to convert a HAR file to a JMeter script and Record XML</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.jmeter.gui.plugin.MenuCreator;
import org.apache.jmeter.gui.util.EscapeDialog;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.save.SaveService;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.gui.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -50,6 +52,7 @@ public class HarConvertorGui extends AbstractAction implements
private static final String BROWSE_JMX_OUT = "BROWSE_JMX_OUT";
private static final String BROWSE_RECORD_OUT = "BROWSE_RECORD_OUT";
private static final String ACTION_CONVERT = "ACTION_CONVERT";
private static final String ACTION_CONVERT_AND_LOAD_SCRIPT = "ACTION_CONVERT_LOAD";
private static final String ACTION_MENU_TOOL = "ACTION_MENU_TOOL";

private EscapeDialog messageDialog;
Expand All @@ -70,6 +73,7 @@ public class HarConvertorGui extends AbstractAction implements
private JCheckBox isRemoveCacheRequestHeaderCheckbox;

private JButton btConvert;
private JButton btConvertAndLoad;
private String lastJFCDirectory;
private JTextField labelStatus;

Expand Down Expand Up @@ -148,7 +152,7 @@ public void actionPerformed(ActionEvent action) {
}
}

if (command.equals(ACTION_CONVERT)) {
if (command.equals(ACTION_CONVERT) || command.equals(ACTION_CONVERT_AND_LOAD_SCRIPT)) {
String fileHarIn= fileHarInTextField.getText();

File fFileIn = new File(fileHarIn);
Expand Down Expand Up @@ -243,10 +247,17 @@ public void actionPerformed(ActionEvent action) {
labelStatus.setText("Tool HAR Convertor Finished OK, fileJmxOut=" + fileJmxOut);
}
labelStatus.setForeground(java.awt.Color.BLACK);

if (command.equals(ACTION_CONVERT_AND_LOAD_SCRIPT)) {
// open the script generated in current JMeter
final HashTree tree = SaveService.loadTree(new File(fileJmxOut));
org.apache.jmeter.gui.action.Load.insertLoadedTree(1,tree);
}
} catch (Exception e) {
e.printStackTrace();
except = e;
btConvert.setEnabled(true);
btConvertAndLoad.setEnabled(true);
labelStatus.setText("Tool HAR Convertor Finished KO, exception = " + e);
labelStatus.setForeground(java.awt.Color.RED);
}
Expand All @@ -255,6 +266,7 @@ public void actionPerformed(ActionEvent action) {
btConvert.setEnabled(true);
}
}

if (command.equals(BROWSE_HAR_IN)) {
fileHarInTextField.setText(showFileChooser(fileHarInTextField.getParent(),
fileHarInTextField, false, new String[] { ".har" }));
Expand Down Expand Up @@ -283,7 +295,13 @@ private JPanel createControls() {
btConvert.setActionCommand(ACTION_CONVERT);
btConvert.setEnabled(true);

btConvertAndLoad = new JButton("CONVERT AND LOAD GENERATED SCRIPT");
btConvertAndLoad.addActionListener(this);
btConvertAndLoad.setActionCommand(ACTION_CONVERT_AND_LOAD_SCRIPT);
btConvertAndLoad.setEnabled(true);

JPanel panel = new JPanel();
panel.add(btConvertAndLoad);
panel.add(btConvert);
return panel;
}
Expand Down Expand Up @@ -388,7 +406,7 @@ private JPanel setupFileChooserPanel() {
* @param locationTextField
* the textField that will receive the path
* @param onlyDirectory
* whether or not the file chooser will only display directories
* whether or not the file chooser will only display directories or Files only
* @param extensions File extensions to filter
* @return the path the user selected or, if the user cancelled the file
* chooser, the previous path
Expand All @@ -398,7 +416,7 @@ private String showFileChooser(Component component, JTextField locationTextField
if (onlyDirectory) {
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
} else {
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
if(extensions != null && extensions.length > 0) {
JMeterFileFilter currentFilter = new JMeterFileFilter(extensions);
Expand Down

0 comments on commit 5f5a473

Please sign in to comment.