Wednesday, October 15, 2014

Run a test suite using Perl

So you have a bunch of functionality you've automated and you'd like to execute the scripts unattended both on a set schedule as well as on certain triggers.
In this quick post (which I also did a while back here) I show you one way of running a test suite executing tests sequentially (i.e. one after the other) from the command line by using Perl. The script is appropriately named
The code
1:  #!C:/Perl64/bin/perl  
2:  use strict;  
3:  use warnings;  
5:   my $result_dir = "C:\\Automation\\Tests\\$ARGV[0]\\";  
6:   opendir (my ($dh), $result_dir) or die "can't open dir: $!";  
8:   while (readdir $dh){  
9:    if ($_ =~ /pl$/){  
10:     system ( $result_dir . $_ );  
11:    }  
12:   }  
This script takes one parameter [line 5], the name of directory in the C:\Automation\Tests folder which is where the test scripts should reside. We use this value to read all of the files in the directory [line 6] and, using regular expressions, only action on the ones that end in pl [line 9] (since we're looking for Perl files). Finally we use the system function to execute the script [line 10]
Once you have the above script, assuming you have perl.exe in your path and Perl mapped to open your pl files, to run manually type
1:  c:\> functional_tests   
Alternatively you can add the Perl script, using your services manager or crontab, to the list of services to be run periodically. Or add it to your CI flow to be executed when certain conditions are met.

No comments:

Post a Comment

Creative Commons License
VGP-Miami Web and Mobile Automation Blog by Alfred Vega is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.