Perl Excel to create a test plan with perl — specially very

2010-07-16 269 words 2 mins read

Today I came across a very interesting problem. I had to write a Test Case document that had quite a huge number of test cases. The interesting part was that the Procedure and the result remained same but the name of the frame and the fields were chaning. I felt that copy/paste and modification would be a complete waste of time, so wrote this perl script quickly. Does what is expected.

#!/usr/bin/perl

#===============================================================================

# FILE: gui.pl

# USAGE: ./gui.pl

# DESCRIPTION: Create excel TC Document using perl.

# OPTIONS: —

# REQUIREMENTS: —

# BUGS: —

# NOTES: —

# AUTHOR: Amit Agarwal(amit.agarwal@amit-agarwal.co.in)

# COMPANY:

# VERSION: 1.0

# CREATED: 09/14/2009 06:58:42 PM

# REVISION: —

#===============================================================================

use strict;

use warnings;

use Spreadsheet::WriteExcel;

my $procedure;

my $result;

my $frame;

my $field;

my $line;

my $row = 1;

my $workbook = Spreadsheet::WriteExcel->new(”amit_agarwal.xls”);

my $worksheet = $workbook->add_worksheet(”GUI_TC”);

# To use blod style, you can use the below format.

# my $bold = $workbook->add_format();

# $bold->set_bold();

# $worksheet->write(5, 0, ”amitag”, $bold);

# We will assume that file ”amit” exists in current directory

# and contains two fields per line. First field is frame name

# and second is the name of the field to check.

open(FILE,&#8221;<amit&#8221;)|| die &#8221;Cannot open file amit for input&#8221;;

for $line ()

{

my $col = 0;

chomp ($line);

($frame,$field)=split(/,/,$line);

$procedure = &#8221;Objective: Verify the frame $frame\n&#8221;;

$procedure .= &#8221;Procedure:\n&#8221;;

$procedure .= &#8221;1. Go to frame $frame\n&#8221;;

$result = &#8221;1. Verify that the frame ($frame)is displayed correctly.\n&#8221;;

$result .= &#8221;2. Verify that $field is displayed in $frame&#8221;;

$worksheet->write($row++,$col,&#8221;Verify the frame $frame&#8221;);

$worksheet->write($row,$col++,$procedure);

$worksheet->write($row++,$col,$result);

}

close (FILE);

$workbook->close();

exit;


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it