Data from Testplan
prev
[$index]
next$SP$SP$SP
$arg->{description}
$fail_str $arg->{method} $url
EOF
# print all called requests
my $subrequest_count = 0;
my $req = $r;
while (defined $req) {
print $PLANDATA
"$req->{_rc}",
"$SP",
"$req->{_request}->{_uri}
\n";
$subrequest_count++;
$req = $req -> {_previous};
}
print {$PLANDATA} "
\n";
# print POST data
if (defined $arg->{data} && %{$arg->{data}}) {
my @tbl = map {[$_, $arg->{data}->{$_}]} sort keys %{$arg->{data}};
print {$PLANDATA} pr_table("Data section of GET or POST", ["Attribute", "Value"], \@tbl, alter_colors());
print $PLANDATA "
\n";
}
# print assertions
my $fail_out = $arg->{fail_str};
$fail_out = [ $fail_out ] if ! ref $fail_out;
my @bool = qw(false true);
my @failed = map {
$_->[0] = $bool[$_->[0]] || $_->[0];
$_
} map {
(my $tmp = $_) =~ s/</g;
[ split(/\s+/, $tmp, 2) ]
} @$fail_out;
print {$PLANDATA} "\n";
print {$PLANDATA} "| \n", print_assert_xml("Define global assertion", $arg->{global_assert_xml}), " | \n" if $arg->{global_assert_xml};
print {$PLANDATA} "
| \n", pr_table("Predicates", [], \@failed, alter_colors()), " | \n";
print {$PLANDATA} "
| \n", print_assert_xml("Assertion (parsed source)", $_), " | \n" foreach(@{$arg->{assert_xml}});
print {$PLANDATA} "
\n";
# print xpath expressions
my $assert = $arg->{assert};
if (UNIVERSAL::isa($assert, "WWW::Webrobot::Assert")) {
my $postfix = (($arg -> {assert} || {}) -> {evaluator} || {}) -> {postfix} || [];
if ($postfix && scalar @$postfix) {
my @xpath = ();
foreach (@$postfix) {
next if ref $_ ne 'ARRAY';
my ($predicate, $parm) = @$_;
next if $predicate ne 'xpath';
my $xpath_expr = $parm->[0]->{xpath};
(my $xpath_result = $r->xpath($xpath_expr)) =~ s/\n/
/g;
push @xpath, [$xpath_expr, $xpath_result];
}
if (@xpath) {
print {$PLANDATA} pr_table("XPath expressions", ["XPath", "Value"], \@xpath, alter_colors());
print $PLANDATA "
\n";
}
}
}
# print variables that have been defined in this entry
if (defined $arg->{new_properties} && scalar @{$arg->{new_properties}}) {
print {$PLANDATA} pr_table("Defined variables", ["Name", "Value"], $arg->{new_properties}, alter_colors());
print $PLANDATA "
\n";
}
# print caller pages
if (my $cp = $arg->{caller_pages}) {
print $PLANDATA "This page was called by
\n";
foreach (@$cp) {
print $PLANDATA "$_
\n";
}
}
# print elapsed time
print $PLANDATA "Elapsed time: ", $r->elapsed_time(), " seconds
\n" if $r;
# Finish this frame
print $PLANDATA "\n";
close $PLANDATA;
# FILE: write frame(3): print all subrequests
$subrequest_count = 0;
$req = $r;
while (defined($req)) { # for all subrequests
# define and make directory
my $dir = "$self->{dir}/$index/$subrequest_count";
-d $dir || mkdir $dir || die "Can't make dir=$dir err=$!";
# write data for frame 3, request header
my $HEADER = open_die(">$dir/req_head.html");
my $xhtml_text0 = ($req->content_xhtml(1)) ?
"source-xhtml" : "";
my $navi_source = <Display content:
source
$xhtml_text0
display
EOF
print {$HEADER} make_html("Request and Response, Header and Data",
$navi_source,
"
\n",
print_http_header(
"Request Header",
($req->{_request}->{_method} || "no_method") . $SP . ($req->{_request}->{_uri} || "no_uri"),
$req->{_request}->{_headers}
),
"
\n",
print_http_header(
"Response Header",
($req->{_protocol} || "(no_protocol)") . $SP .
"$req->{_rc}" . $SP .
($req->{_msg} || "(no_message)"),
$req->{_headers}
),
);
close $HEADER;
# FILE: write response body (source)
my $SRC = open_die(">$dir/source.txt");
print {$SRC} $req -> content();
close $SRC;
# FILE: write response body (xhtml source)
if ($req->content_xhtml(1)) { #if (exists $req->{_content_xhtml})
my $XSRC = open_die(">$dir/source_xhtml.txt");
print {$XSRC} $req -> content_xhtml();
close $XSRC;
}
# FILE: write frame(4): write display version
my $content_type = norm_content_type($req->{_headers}->{"content-type"});
my $DISPLAY = open_die(">$dir/display.html");
SWITCH: for (@{$content_type}) {
/text\/html/ and do {
my $frame = "../../frame_undef.html";
my $txt = $req -> content();
# in aendern
$txt =~ s/()/$1$frame$2/gsi;
print $DISPLAY $txt;
last;
};
/text\/plain/ || /text\/xml/ || /text\/sgml/ and do {
my $txt = encode_text($req -> content());
print {$DISPLAY} make_html("", "$txt
\n");
last;
};
/image\/gif/ and do {
print {$DISPLAY} make_html("", "
");
my $FILE = open_die(">$dir/display_1.gif");
print $FILE $req->{_content};
close $FILE;
last;
};
/image\/png/ and do {
print {$DISPLAY} make_html("", "
");
my $FILE = open_die(">$dir/display_1.png");
print $FILE $req->{_content};
close $FILE;
last;
};
/image\/jpeg/ and do {
print {$DISPLAY} make_html("", "
");
my $FILE = open_die(">$dir/display_1.jpeg");
print $FILE $req->{_content};
close $FILE;
last;
};
do { # else
# ??? kann ein array sein!
my ($type, $charset) = split(/; */,
$req->{_headers}->{"content-type"} || "", 2);
my $mime_info = "";
$mime_info .= "type='$type'" if $type;
$mime_info .= " $charset" if $charset;
my $FILE = open_die(">$dir/any-mime");
if ($mime_info eq "") {
print {$FILE} make_html("EMPTY", "... Content is empty ...
");
}
else {
my $txt = <Click me
$mime_info
EOF
print {$FILE} make_html("Link To Body Of Response", $txt);
}
close $FILE;
}
}
close $DISPLAY;
# write frameset ((3), (4)) [resquest/response]
my $INDEX = open_die(">$dir/index.html");
print {$INDEX} make_html("Request and Response, Header and Data", <
Follow these links (you'd better enable frames):
Request/Response header
Display response
EOF
close $INDEX;
# set loop control variables
$subrequest_count++;
$req = $req -> {_previous};
}
}
########################################################################
### functions ##########################################################
########################################################################
sub print_http_header {
my ($title, $firstline, $headers) = @_;
my $color_obj = alter_colors();
my $color = $color_obj->();
my @tbl = map {[$_, $headers->{$_}]} sort keys %{$headers};
my $tmp_table = pr_table("", [], \@tbl, $color_obj);
my $txt = <$title
EOF
return $txt;
}
sub autoflush { #static
my ($handle) = @_;
my $save_handle = select($handle);
$| = 1;
select($save_handle);
}
sub new_handle {
do {local *FH; *FH};
}
sub open_die { #static
my ($filename) = @_;
my $handle = new_handle();
my ($package, $file, $line) = caller();
open($handle, $filename) or die("line $line: Can't open $filename, err=$!");
return $handle;
}
sub alter_colors { #static object factory
my @colors = @_;
#@colors = ("#E0E0E0", "#F3F3F3") if ! scalar @colors;
@colors = ("bgcolor='#E0E0E0'", "bgcolor='#F3F3F3'") if ! scalar @colors;
my $state = 0;
return sub {
$state = 0 if $state >= scalar @colors;
return $colors[$state++];
};
}
sub first_blue { #static object factory
my $state = 0;
return sub {
my $old_state = $state;
$state = 1;
return $old_state ? "black" : "blue";
};
}
sub make_html { # static
my ($title, @txt) = @_;
my $txt = join "", @txt;
return <
$title
$txt