-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlr2jm.ts
More file actions
667 lines (540 loc) · 23.5 KB
/
lr2jm.ts
File metadata and controls
667 lines (540 loc) · 23.5 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#!/usr/bin/env ts-node
/**
* lr2jm.ts — Convert LoadRunner scripts to JMeter .jmx test plans.
*
* Ported from lr2jm.pl (Perl) to TypeScript (Node.js, no dependencies).
*
* Usage:
* npx ts-node lr2jm.ts <LoadRunner Script Directory>
* # or compile first:
* tsc lr2jm.ts && node lr2jm.js <LoadRunner Script Directory>
*/
import * as fs from 'fs';
import * as path from 'path';
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
interface RequestData {
stepname: string;
method?: string;
domain?: string;
path?: string;
image_parser?: string;
params: Record<string, string>;
itemdata?: string[];
}
// ---------------------------------------------------------------------------
// Global state (mirrors Perl globals)
// ---------------------------------------------------------------------------
const webrequests: RequestData[] = [];
const tables: Record<string, string[]> = {}; // tableName -> [csvFilename, col1, col2, ...]
const paramsubs: Record<string, string> = {}; // paramName -> resolved column name
let dynamicParams: Record<string, string> = {}; // paramName -> regex
// ---------------------------------------------------------------------------
// Minimal XML builder (no dependencies)
// ---------------------------------------------------------------------------
function escapeXml(str: string): string {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
class XmlElement {
tag: string;
attrs: Record<string, string>;
children: XmlElement[];
text: string | null;
constructor(tag: string) {
this.tag = tag;
this.attrs = {};
this.children = [];
this.text = null;
}
set(name: string, value: string): this {
this.attrs[name] = value;
return this;
}
addChild(tag: string): XmlElement {
const child = new XmlElement(tag);
this.children.push(child);
return child;
}
toString(indent: number = 0): string {
const pad = ' '.repeat(indent);
const attrStr = Object.entries(this.attrs)
.map(([k, v]) => ` ${k}="${escapeXml(v)}"`)
.join('');
if (this.children.length === 0 && this.text == null) {
return `${pad}<${this.tag}${attrStr} />`;
}
let result = `${pad}<${this.tag}${attrStr}>`;
if (this.text != null && this.children.length === 0) {
result += escapeXml(this.text) + `</${this.tag}>`;
return result;
}
result += '\n';
if (this.text != null) {
result += `${pad} ${escapeXml(this.text)}\n`;
}
for (const child of this.children) {
result += child.toString(indent + 1) + '\n';
}
result += `${pad}</${this.tag}>`;
return result;
}
}
/**
* Add a property sub-element with a name attribute and optional text.
*/
function addProp(
parent: XmlElement,
tag: string,
name: string,
text?: string
): XmlElement {
const elem = parent.addChild(tag);
elem.set('name', name);
if (text !== undefined && text !== null) {
elem.text = text;
}
return elem;
}
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function paramSubstitution(inputString: string): string {
let result = inputString;
for (const [param, sub] of Object.entries(paramsubs)) {
result = result.split('{' + param + '}').join('${' + sub + '}');
}
return result;
}
function printMessage(message: string, color: 'red' | 'green'): void {
const colors: Record<string, string> = { red: '\x1b[31m', green: '\x1b[32m' };
const reset = '\x1b[0m';
console.log(colors[color] + message + reset);
}
// ---------------------------------------------------------------------------
// CLI
// ---------------------------------------------------------------------------
function readArguments(): string {
const args = process.argv.slice(2);
if (args.length < 1) {
console.error('Usage: ts-node lr2jm.ts <LoadRunner Script Directory>');
process.exit(1);
}
const scriptDir = args[0];
if (!fs.existsSync(scriptDir) || !fs.statSync(scriptDir).isDirectory()) {
printMessage(`${scriptDir}: not a valid directory`, 'red');
process.exit(1);
}
return scriptDir;
}
// ---------------------------------------------------------------------------
// .prm parameter file parsing
// ---------------------------------------------------------------------------
function getParametersFromLR(scriptDir: string): void {
const basename = path.basename(scriptDir);
const prmPath = path.join(scriptDir, basename + '.prm');
if (!fs.existsSync(prmPath)) return;
const content = fs.readFileSync(prmPath, 'utf-8');
// Perl uses local $/ = '[' to split on '[' as record separator
const records = content.split('[');
// Skip the first element (content before the first '[')
for (let i = 1; i < records.length; i++) {
const record = records[i];
const typeMatch = record.match(/Type="(.*?)"/);
const paramNameMatch = record.match(/ParamName="(.*?)"/);
const columnNameMatch = record.match(/ColumnName="(.*?)"/);
const tableMatch = record.match(/Table="(.*?)"/);
if (!typeMatch || !paramNameMatch) continue;
const paramType = typeMatch[1];
const paramName = paramNameMatch[1];
const columnName = columnNameMatch ? columnNameMatch[1] : '';
const tableName = tableMatch ? tableMatch[1] : '';
if (paramType !== 'Table') continue;
// Process each unique table file once
if (!(tableName in tables)) {
const csvFilename = tableName.replace(/\./g, '_') + '.csv';
const tabledata: string[] = [csvFilename];
const datPath = path.join(scriptDir, tableName);
const csvPath = path.join(scriptDir, csvFilename);
const datContent = fs.readFileSync(datPath, 'utf-8');
const datLines = datContent.split('\n');
let columns: string[] = [];
const csvLines: string[] = [];
for (let j = 0; j < datLines.length; j++) {
if (j === 0) {
columns = datLines[j].split(',').map(c => c.trim());
} else if (datLines[j].trim()) {
csvLines.push(datLines[j]);
}
}
fs.writeFileSync(csvPath, csvLines.join('\n') + (csvLines.length ? '\n' : ''));
tabledata.push(...columns);
tables[tableName] = tabledata;
}
// Resolve column name
const colMatch = columnName.match(/^Col (\d+)/);
if (colMatch) {
const colIdx = parseInt(colMatch[1], 10);
paramsubs[paramName] = tables[tableName][colIdx];
} else {
paramsubs[paramName] = columnName;
}
}
}
// ---------------------------------------------------------------------------
// .usr file parsing
// ---------------------------------------------------------------------------
function getActionFilesFromLR(scriptDir: string): string[] {
const basename = path.basename(scriptDir);
const usrPath = path.join(scriptDir, basename + '.usr');
const content = fs.readFileSync(usrPath, 'utf-8');
const actions: string[] = [];
for (let line of content.split('\n')) {
line = line.replace(/\s+$/, '');
if (line.endsWith('.c')) {
actions.push(line.split('=').slice(1).join('='));
}
}
return actions;
}
// ---------------------------------------------------------------------------
// LoadRunner function handlers
// ---------------------------------------------------------------------------
function consumeDynamicParams(): Record<string, string> {
const params = { ...dynamicParams };
dynamicParams = {};
return params;
}
function handleWebUrl(rawArgs: string): void {
const args = rawArgs.split(',');
const stepname = args[0].replace(/"/g, '');
const requestData: RequestData = {
stepname,
method: 'GET',
params: {},
};
for (const arg of args) {
const cleaned = arg.replace(/"/g, '');
const urlMatch = cleaned.match(/^URL=https?:\/\/(.*?)(\/.*)/);
if (urlMatch) {
requestData.domain = urlMatch[1];
requestData.path = urlMatch[2];
}
const modeMatch = cleaned.match(/^Mode=(.*)/);
if (modeMatch) {
requestData.image_parser = modeMatch[1].includes('HTML') ? 'true' : 'false';
}
}
requestData.params = consumeDynamicParams();
webrequests.push(requestData);
}
function handleWebSubmitData(rawArgs: string): void {
const args = rawArgs.split(',');
const stepname = args.shift()!.replace(/"/g, '');
const requestData: RequestData = { stepname, params: {} };
const itemdata: string[] = [];
for (let arg of args) {
arg = arg.trim().replace(/^"*/, '').replace(/"*$/, '');
const actionMatch = arg.match(/^Action=https?:\/\/(.*?)(\/.*)/);
if (actionMatch) {
requestData.domain = actionMatch[1];
requestData.path = actionMatch[2];
}
const modeMatch = arg.match(/^Mode=(.*)/);
if (modeMatch) {
requestData.image_parser = modeMatch[1].includes('HTML') ? 'true' : 'false';
}
const methodMatch = arg.match(/^Method=(.*)/);
if (methodMatch) {
requestData.method = methodMatch[1];
}
const nameMatch = arg.match(/^Name=(.*)/);
if (nameMatch) {
itemdata.push(nameMatch[1]);
}
const valueMatch = arg.match(/^Value=(.*)/);
if (valueMatch) {
itemdata.push(valueMatch[1]);
}
if (arg.includes('LAST') && itemdata.length > 1) {
requestData.itemdata = itemdata.slice();
}
}
requestData.params = consumeDynamicParams();
webrequests.push(requestData);
}
function handleWebCustomRequest(rawArgs: string): void {
const args = rawArgs.split(',');
const stepname = args.shift()!.replace(/"/g, '');
const requestData: RequestData = { stepname, params: {} };
const itemdata: string[] = [];
for (let arg of args) {
arg = arg.trim().replace(/^"*/, '').replace(/"*$/, '');
const urlMatch = arg.match(/^URL=https?:\/\/(.*?)(\/.*)/);
if (urlMatch) {
requestData.domain = urlMatch[1];
requestData.path = urlMatch[2];
}
const modeMatch = arg.match(/^Mode=(.*)/);
if (modeMatch) {
requestData.image_parser = modeMatch[1].includes('HTML') ? 'true' : 'false';
}
const methodMatch = arg.match(/^Method=(.*)/);
if (methodMatch) {
requestData.method = methodMatch[1];
}
const bodyMatch = arg.match(/^Body=(.*)/);
if (bodyMatch) {
const body = bodyMatch[1];
for (const nvpair of body.split('&')) {
const parts = nvpair.split('=');
itemdata.push(parts[0], parts.slice(1).join('='));
}
}
if (arg.includes('LAST') && itemdata.length > 1) {
requestData.itemdata = itemdata.slice();
}
}
requestData.params = consumeDynamicParams();
webrequests.push(requestData);
}
function handleWebRegSaveParam(rawArgs: string): void {
const args = rawArgs.split(',');
const paramname = args.shift()!.replace(/"/g, '');
let lb = '';
let rb = '';
for (let arg of args) {
arg = arg.trim().replace(/^"*/, '').replace(/"*$/, '');
const lbMatch = arg.match(/^LB=(.*)/);
if (lbMatch) lb = lbMatch[1];
const rbMatch = arg.match(/^RB=(.*)/);
if (rbMatch) rb = rbMatch[1];
}
dynamicParams[paramname] = lb + '(.*)' + rb;
paramsubs[paramname] = paramname;
}
// ---------------------------------------------------------------------------
// Action file parsing and dispatch
// ---------------------------------------------------------------------------
function parseActionFiles(scriptDir: string, actions: string[]): void {
for (const action of actions) {
const actionPath = path.join(scriptDir, action);
const rawLines = fs.readFileSync(actionPath, 'utf-8').split('\n');
// Strip whitespace and quotes from each line (mirrors Perl lines 157-163)
const lines = rawLines.map(line => line.trim().replace(/^"/, '').replace(/"$/, ''));
// Join all lines and split on semicolons to get function calls
const joined = lines.join('');
const functions = joined.split(';');
for (const funcStr of functions) {
const match = funcStr.match(/(.*)\((.*)\)/s);
if (!match) continue;
const funcName = match[1];
const funcArgs = match[2];
if (funcName.includes('web_url')) {
handleWebUrl(funcArgs);
} else if (funcName.includes('web_submit_data')) {
handleWebSubmitData(funcArgs);
} else if (funcName.includes('web_custom_request')) {
handleWebCustomRequest(funcArgs);
} else if (funcName.includes('web_reg_save_param')) {
handleWebRegSaveParam(funcArgs);
}
}
}
}
// ---------------------------------------------------------------------------
// JMX XML generation
// ---------------------------------------------------------------------------
function writeJmx(scriptDir: string): void {
const basename = path.basename(scriptDir);
const jmxPath = path.join(scriptDir, basename + '.jmx');
// Root structure
const root = new XmlElement('jmeterTestPlan');
root.set('version', '1.2');
root.set('properties', ' 1.8');
const rootHashtree = root.addChild('hashTree');
// --- TestPlan ---
const testplan = rootHashtree.addChild('TestPlan');
testplan.set('guiclass', 'TestPlanGui');
testplan.set('testclass', 'TestPlan');
testplan.set('testname', 'LR2JM Test Plan: ' + scriptDir);
testplan.set('enabled', 'true');
addProp(testplan, 'boolProp', 'TestPlan.functional_mode', 'false');
addProp(testplan, 'stringProp', 'TestPlan.comments');
addProp(testplan, 'stringProp', ' TestPlan.user_define_classpath');
addProp(testplan, 'boolProp', 'TestPlan.serialize_threadgroups', 'false');
const elemProp = testplan.addChild('elementProp');
elemProp.set('name', ' TestPlan.user_defined_variables');
elemProp.set('elementType', 'Arguments');
elemProp.set('guiclass', 'ArgumentsPanel');
elemProp.set('testclass', 'Arguments');
elemProp.set('testname', 'User Defined Variables');
elemProp.set('enabled', 'true');
addProp(elemProp, 'collectionProp', 'Arguments.arguments');
const testplanHashtree = rootHashtree.addChild('hashTree');
// --- ThreadGroup ---
const threadgroup = testplanHashtree.addChild('ThreadGroup');
threadgroup.set('guiclass', 'ThreadGroupGui');
threadgroup.set('testclass', 'ThreadGroup');
threadgroup.set('testname', 'LR2JM Thread Group');
threadgroup.set('enabled', 'true');
addProp(threadgroup, 'boolProp', 'ThreadGroup.scheduler', 'false');
addProp(threadgroup, 'stringProp', 'ThreadGroup.num_threads', '1');
addProp(threadgroup, 'stringProp', 'ThreadGroup.duration');
addProp(threadgroup, 'stringProp', 'ThreadGroup.delay');
addProp(threadgroup, 'longProp', 'ThreadGroup.start_time', '1187292555000');
addProp(threadgroup, 'stringProp', 'ThreadGroup.on_sample_error', 'continue');
addProp(threadgroup, 'stringProp', 'ThreadGroup.ramp_time', '1');
const loopProp = threadgroup.addChild('elementProp');
loopProp.set('name', 'ThreadGroup.main_controller');
loopProp.set('elementType', 'LoopController');
loopProp.set('guiclass', 'LoopControlPanel');
loopProp.set('testclass', 'LoopController');
loopProp.set('testname', 'Loop Controller');
loopProp.set('enabled', 'true');
addProp(loopProp, 'stringProp', 'LoopController.loops', '1');
addProp(loopProp, 'boolProp', 'LoopController.continue_forever', 'false');
addProp(threadgroup, 'longProp', 'ThreadGroup.end_time', '1187292555000');
const tgHashtree = testplanHashtree.addChild('hashTree');
// --- ConfigTestElement (HTTP Request Defaults) ---
const config = tgHashtree.addChild('ConfigTestElement');
config.set('guiclass', 'HttpDefaultsGui');
config.set('testclass', 'ConfigTestElement');
config.set('testname', 'HTTP Request Defaults');
config.set('enabled', 'true');
addProp(config, 'stringProp', 'HTTPSampler.domain', '');
addProp(config, 'stringProp', 'HTTPSampler.path');
addProp(config, 'stringProp', 'HTTPSampler.port', '80');
const configArgs = config.addChild('elementProp');
configArgs.set('name', 'HTTPsampler.Arguments');
configArgs.set('elementType', 'Arguments');
configArgs.set('guiclass', 'HTTPArgumentsPanel');
configArgs.set('testclass', 'Arguments');
configArgs.set('testname', 'User Defined Variables');
configArgs.set('enabled', 'true');
addProp(configArgs, 'collectionProp', 'Arguments.arguments');
addProp(config, 'stringProp', 'HTTPSampler.protocol');
tgHashtree.addChild('hashTree');
// --- CookieManager ---
const cookieMgr = tgHashtree.addChild('CookieManager');
cookieMgr.set('guiclass', 'CookiePanel');
cookieMgr.set('testclass', 'CookieManager');
cookieMgr.set('testname', 'HTTP Cookie Manager');
cookieMgr.set('enabled', 'true');
addProp(cookieMgr, 'boolProp', 'CookieManager.clearEachIteration', 'false');
addProp(cookieMgr, 'collectionProp', 'CookieManager.cookies');
tgHashtree.addChild('hashTree');
// --- CSVDataSet for each parameter table ---
for (const [, tabledata] of Object.entries(tables)) {
const csvFilename = tabledata[0];
const columns = tabledata.slice(1);
const csvDs = tgHashtree.addChild('CSVDataSet');
csvDs.set('guiclass', 'TestBeanGUI');
csvDs.set('testclass', 'CSVDataSet');
csvDs.set('testname', 'LR2JM Data Set');
csvDs.set('enabled', 'true');
addProp(csvDs, 'stringProp', 'delimiter', ',');
addProp(csvDs, 'stringProp', 'fileEncoding');
addProp(csvDs, 'stringProp', 'filename', csvFilename);
addProp(csvDs, 'boolProp', 'recycle', 'true');
addProp(csvDs, 'stringProp', 'variableNames', columns.join(','));
tgHashtree.addChild('hashTree');
}
// --- HTTPSampler for each web request ---
for (const requestData of webrequests) {
const httpsampler = tgHashtree.addChild('HTTPSampler');
const samplerHashtree = tgHashtree.addChild('hashTree');
// RegexExtractor for each dynamic param
const params = requestData.params;
for (const [paramName, regex] of Object.entries(params)) {
const extractor = samplerHashtree.addChild('RegexExtractor');
extractor.set('guiclass', 'RegexExtractorGui');
extractor.set('testclass', 'RegexExtractor');
extractor.set('testname', 'LR2JM Regex Extractor');
extractor.set('enabled', 'true');
addProp(extractor, 'stringProp', 'RegexExtractor.useHeaders', 'false');
addProp(extractor, 'stringProp', 'RegexExtractor.refname', paramName);
addProp(extractor, 'stringProp', 'RegexExtractor.regex', regex);
addProp(extractor, 'stringProp', 'RegexExtractor.template', '$1$');
addProp(extractor, 'stringProp', 'RegexExtractor.default');
addProp(extractor, 'stringProp', 'RegexExtractor.match_number', '1');
samplerHashtree.addChild('hashTree');
}
// HTTPSampler attributes
httpsampler.set('guiclass', 'HttpTestSampleGui');
httpsampler.set('testclass', 'HTTPSampler');
httpsampler.set('testname', requestData.stepname);
httpsampler.set('enabled', 'true');
// Arguments elementProp
const argsProp = httpsampler.addChild('elementProp');
argsProp.set('name', 'HTTPsampler.Arguments');
argsProp.set('elementType', 'Arguments');
argsProp.set('guiclass', 'HTTPArgumentsPanel');
argsProp.set('testclass', 'Arguments');
argsProp.set('enabled', 'true');
const collection = addProp(argsProp, 'collectionProp', 'Arguments.arguments');
// Form data / item data
const itemdata = requestData.itemdata || [];
for (let i = 0; i < itemdata.length - 1; i += 2) {
const name = paramSubstitution(itemdata[i]);
const value = paramSubstitution(itemdata[i + 1]);
const httpArg = collection.addChild('elementProp');
httpArg.set('name', '');
httpArg.set('elementType', 'HTTPArgument');
addProp(httpArg, 'boolProp', 'HTTPArgument.always_encode', 'false');
addProp(httpArg, 'stringProp', 'Argument.value', value);
addProp(httpArg, 'stringProp', 'Argument.metadata', '=');
addProp(httpArg, 'boolProp', 'HTTPArgument.use_equals', 'true');
addProp(httpArg, 'stringProp', 'Argument.name', name);
}
// Standard sampler properties
addProp(httpsampler, 'stringProp', 'HTTPSampler.domain', requestData.domain || '');
addProp(httpsampler, 'stringProp', 'HTTPSampler.port');
addProp(httpsampler, 'stringProp', 'HTTPSampler.protocol');
addProp(httpsampler, 'stringProp', 'HTTPSampler.method', requestData.method || '');
addProp(httpsampler, 'stringProp', 'HTTPSampler.contentEncoding');
addProp(httpsampler, 'stringProp', 'HTTPSampler.path',
paramSubstitution(requestData.path || ''));
addProp(httpsampler, 'boolProp', 'HTTPSampler.follow_redirects', 'true');
addProp(httpsampler, 'boolProp', 'HTTPSampler.auto_redirects', 'true');
addProp(httpsampler, 'boolProp', 'HTTPSampler.use_keepalive', 'true');
addProp(httpsampler, 'boolProp', 'HTTPSampler.DO_MULTIPART_POST', 'false');
addProp(httpsampler, 'stringProp', 'HTTPSampler.mimetype');
addProp(httpsampler, 'stringProp', 'HTTPSampler.FILE_NAME');
addProp(httpsampler, 'stringProp', 'HTTPSampler.FILE_FIELD');
addProp(httpsampler, 'boolProp', 'HTTPSampler.image_parser',
requestData.image_parser || 'false');
addProp(httpsampler, 'stringProp', 'HTTPSampler.monitor', 'true');
addProp(httpsampler, 'stringProp', 'HTTPSampler.embedded_url_re');
}
// Write XML
const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + root.toString(0) + '\n';
fs.writeFileSync(jmxPath, xml);
printMessage('JMeter test plan created: ' + jmxPath, 'green');
}
// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
function main(): void {
try {
const scriptDir = readArguments();
getParametersFromLR(scriptDir);
const actions = getActionFilesFromLR(scriptDir);
parseActionFiles(scriptDir, actions);
writeJmx(scriptDir);
} catch (err: unknown) {
const error = err as NodeJS.ErrnoException;
if (error.code === 'ENOENT') {
printMessage(error.message, 'red');
} else {
printMessage('Error: ' + error.message, 'red');
throw err;
}
}
}
main();