KnowledgeBase
PERL
Using PERL to regenerate a LoadRunner SOAP request
Using PERL to regenerate a LoadRunner SOAP request
This program takes two files as parameters, an extract from a LoadRunner script and a subset of the VUGen output, and reconstructs the original XML request.
#------------------------------------------------------------------------------------------
# This routine takes two file parameters
# - LoadRunner request containing parameterised XML (web_custom_request or soap_request)
# - LoadRunner output containing log extract with actual substitutions
#
# It outputs the reconstructed XML request
#------------------------------------------------------------------------------------------
use strict;
my $in;
my $request;
my $xml;
# Load request (web_custom_request or soap_request) containing XML
open $in, '<', $ARGV[0] or die "Can't read request file: $!";
$request = do { local $/; <$in> };
chomp $request;
# Extract xml and clean it up
{ # Remove intervening linefeeds and quotes
local $/;
$request =~ s/",?\n\s+"//g;
}
$request =~ /(<\?xml.*>)/; # Extract the XML...
$xml = $1; # ...into a local variable
$xml =~ s/\\"/"/g; # De-escape the quotes
$xml =~ s/\\r\\n/\n/g; # Convert "\r\n" into newline
# Substitute parameters
open(PARAMS, $ARGV[1]) or die "Can't read params file: $!";
# For every line in the parameter file
for (<PARAMS>) {
if (/"(.+)" = "(.*)"/) { # Is it a real parameter line?
my $key = $1; # Save key name
my $value = $2; # Save value to substitute
my $count = $xml =~ s/{$key}/$value/; # Replace the {parameter}
}
}
print $xml;