-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhar2jmxConverter.html
88 lines (72 loc) · 2.55 KB
/
har2jmxConverter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<div>
Select HAR File:
<br>
<input id="harFile" type="file" accept=".har">
</div>
<br>
<div>
<input id="button" type="button" name="convert" value="Convert HAR to JMX File" disabled>
</div>
<br>
<div>
JMX Contents
<br>
<textarea id="jmxArea" rows="50" cols="200" wrap="soft" style="resize: none;"></textarea>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="/har2jmx/js/har2jmx.js"></script>
<script>
var harFile = document.getElementById("harFile");
var convertButton = document.getElementById("button");
var harText;
var harFileName;
harFile.onchange = function() {
var file = harFile.files[0];
var dotIndex = file.name.lastIndexOf(".");
var fileType = file.name.slice(dotIndex + 1);
if (fileType != "har") {
window.alert("Please Select *.har File");
harFile.value = "";
return;
}
harFileName = file.name.substring(0, dotIndex);
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function() {
harText = reader.result;
convertButton.removeAttribute("disabled");
}
}
convertButton.onclick = function() {
$.ajax({
url: location.origin + "/har2jmx/template.jmx",
async: false,
dataType: "xml",
success: function(response) {
template = response;
}
});
var har2JmxConverter = new Har2JmxConverter();
var jmxArea = document.getElementById("jmxArea");
jmxArea.value = har2JmxConverter.convert(template, harText);
download(harFileName + ".jmx", jmxArea.value);
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:application/xml;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
</script>
</body>
</html>