-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptUpdaterWeb.html
119 lines (111 loc) · 4.94 KB
/
ScriptUpdaterWeb.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<title>Script Updater</title>
</head>
<body>
<label>Select the Script file:</label>
<input type="file" id="fileInput">
<button onclick="updateScript()">Update Script</button>
<script>
function updateScript() {
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
const reader = new FileReader();
console.log("I am inside updateScript function ");
reader.onload = function() {
const scriptFileName = reader.result;
const updatedScript = scriptUpdater(scriptFileName);
const updatedFile = new Blob([updatedScript], { type: file.type });
const a = document.createElement("a");
a.href = URL.createObjectURL(updatedFile);
a.download = file.name;
a.click();
};
reader.readAsText(file);
}
function scriptUpdater(scriptFileName) {
console.log("I am inside script Updater function");
console.log("Before updateding Script : ", scriptFileName);
let transactionName = "";
let newValue1 = `,"ID:{PVuserID} | Iteration : {PIterationID} | TimeStamp : {PTimestamp} | Username : {PUsername} | Error at step : `;
let updatedScript = "";
let lines = scriptFileName.split("\n");
for (let line of lines) {
if (line.includes("web_reg_find")) {
if (line.includes("Text=")) {
let parts = line.split("Text=");
let textCheck = parts[1].substring(0, parts[1].indexOf(","));
line = `web_reg_find("Text=${textCheck}${newValue1}${transactionName}"",LAST);`;
}
}
if (line.includes("lr_start_transaction")) {
let parts = line.split("\"");
transactionName = parts[1];
}
if (line.includes("lr_end_transaction")) {
transactionName = "";
}
updatedScript += line + "\n";
}
return updatedScript;
}
function TransactionScript() {
const fileInput = document.getElementById("inputFile");
const appCICodeField = document.getElementById("appCICodeField").value;
const scriptNameField = document.getElementById("scriptNameField").value;
const funcNameField = document.getElementById("funcNameField").value;
const file = fileInput.files[0];
const reader = new FileReader();
console.log("I am inside Transaction Script function ");
reader.onload = function() {
const scriptFileName = reader.result;
const updatedScript = updateFile(scriptFileName, appCICodeField, scriptNameField, funcNameField);
const updatedFile = new Blob([updatedScript], { type: file.type });
const a = document.createElement("a");
a.href = URL.createObjectURL(updatedFile);
a.download = file.name;
a.click();
};
reader.readAsText(file);
}
function updateFile(scriptFileName, appCICodeField, scriptNameField, funcNameField) {
console.log("I am inside update file function ");
let transactionNum = 1;
console.log("appCICodeField: ", appCICodeField);
console.log("scriptNameField: ", scriptNameField);
console.log("funcNameField: ", funcNameField);
const lines = scriptFileName.split('\n');
let updatedScript = '';
for (let line of lines) {
if (line.includes('lr_start_transaction')) {
const startIndex = line.indexOf('lr_start_transaction') + 21;
const endIndex = line.indexOf('"', startIndex + 1);
let transactionName = line.substring(startIndex + 1, endIndex);
transactionName = `${appCICodeField}_${scriptNameField}_${funcNameField}_${String(transactionNum).padStart(2, '0')}_${transactionName}`;
line = line.substring(0, startIndex + 1) + transactionName + line.substring(endIndex);
transactionNum++;
}
if (line.includes('lr_end_transaction')) {
const startIndex = line.indexOf('lr_end_transaction') + 19;
const endIndex = line.indexOf('"', startIndex + 1);
let transactionName = line.substring(startIndex + 1, endIndex);
let endTransactionNum = transactionNum-1;
transactionName = `${appCICodeField}_${scriptNameField}_${funcNameField}_${String(endTransactionNum).padStart(2, '0')}_${transactionName}`;
line = line.substring(0, startIndex + 1) + transactionName + line.substring(endIndex);
}
updatedScript += line + '\n';
}
//console.log("final updatedScript value: ", updatedScript);
return updatedScript;
}
</script>
<div>
<input type="text" id="appCICodeField" placeholder="Enter App CI Code">
<input type="text" id="scriptNameField" placeholder="Enter Script Name">
<input type="text" id="funcNameField" placeholder="Enter Function Name">
<input type="file" id="inputFile">
<button onclick="TransactionScript()">Update File</button>
</div>
</body>
</html>