Hi Monks,
I am stuck at a situation in my task and want your help in solving it. A brief background about the problem statement is as below.
I am parsing the Below xml using the XML::parser module and i am able to parse the XML. My XML and the code i am using to parse is as below.
My script should perform the below operations.
1)Access each testcase defined in the XML and perform the operations mentioned in each step. For each step there is a command and parameters for the command. This command is basically a perl function module which i have written and its placed in a seperate perl file.
2)My script should access each step and trigger the corresponding function with the specified parameter. The parameters are specified as Arguments in my XML, Uptil now i was only able to parse the XML using the below code but i am not able to trigger functions based on the steps, since the output of the parser is kind a confusing and i don't know how i can use this output. Please suggest how i can proceed, if you have any doubts in regarding the problems please let me know.
<DCA>
<testcase type = "Interactive">
<step command ="LaunchApp " param1 = "executablepath" param2 = "di
+rpath"/>
<step command = "Gohere"/>
<step command = "Changemode" param1 = "100"/>
<step command = "CaptureRectanlge" param1 = "3" param2 = "96" para
+m3 = "726" param4 = "580"/>
<step command = "CompareImage" param1 = "D:\\img1.jpg" param2 = "D
+:\\img2.jpg "/>
</testcase>
<testcase type = "broswer">
<step command ="Launchapp " param1 = "executablepath" param2 = "di
+rpath"/>
<step command = "Gohere"/>
<step command = "Channgemode" param1 = "100"/>
<step command = "CaptureRectanlge" param1 = "3" param2 = "96" para
+m3 = "726" param4 = "580"/>
<step command = "CompareImage" image1 = "D:\\img1.jpg" image2 = "D
+:\\img2.jpg "/>
</testcase>
</DCA>
MyCode:
use warnings;
use 5.010;
use XML::Simple;
#using XML::Parser
use XML::Parser;
my $parser = new XML::Parser;
$parser->setHandlers(Start => \&startElement,
End => \&endElement);
+
$parser->parsefile('D:\\ABC\\Perl Projects\\DCA.xml');
sub startElement {
my( $parseinst, $element, %attrs ) = @_;
SWITCH: {
if ($element eq "testcase") {
$count++;
$tag = "testcase";
print "Testcase $count:\n";
for my $attr (keys %attrs) {
print "$attr: $attrs{$attr}\n";
}
last SWITCH;
}
if ($element eq "step") {
print "Step: ";
$tag = "step";
for my $attr (keys %attrs) {
print "$attr: $attrs{$attr}\n";
}
last SWITCH;
}
}
}
sub endElement {
my( $parseinst, $element ) = @_;
if ($element eq "testcase") {
print "\n\n";
} elsif ($element eq "title") {
print "\n";
}
}
Output of my script
Testcase 1:
type: Interactive
Step: param2: dirpath
param1: executablepath
command: Launchsimulator
Step: command: Homescreen
Step: param1: 100
command: Channelchange
Step: param4: 580
param2: 96
param3: 726
param1: 3
command: CaptureRectanlge
Step: param2: D:\\img2.jpg
param1: D:\\img1.jpg
command: CompareImage
Testcase 2:
type: Netfront
Step: param2: dirpath
param1: executablepath
command: Launchsimulator
Step: command: Homescreen
Step: param1: 100
command: Channelchange
Step: param4: 580
param2: 96
param3: 726
param1: 3
command: CaptureRectanlge
Step: image1: D:\\img1.jpg
image2: D:\\img2.jpg
command: CompareImage
Testcase 3:
type: HTML
So if you see the output i am getting tiggers for each of my registered handlers but i am not able to make use of the output for my scenario. Any suggestion is highly appreciated. If you have better design idea also please provide your suggestions.