Saturday, July 2, 2011

How to create a selenium test suite using Perl

Selenium is becoming increasingly popular now a days, mainly because, well it's FREE! :)

Recently, while checking out one of the Selenium automation forums we monitor I came across the question of how to run multiple test script written in Perl as part of a suite of tests. While I am sure there are many ways of implementing this, here is one of my methods of choice in Perl. Another option is to use a MySQL database. Ask me how!

creating a driver script that calls
all of your Perl scripts in order. This driver script could be a
windows .bat file, Linux shell script or even a Perl script that
simply contains n system calls to your individual scripts.
For example:
Assuming that your test scripts reside in the directory C:\Automation\Scripts\, this is how i would do it in perl.


  my $result_dir = "C:\\Automation\\Scripts\\"
  opendir (my $dh, $result_dir) or die "can't open dir: $!";
  while (readdir $dh){
   if ($_ =~ /pl$/){
     system ( $_ );
   }
  }

The above:
  1. Opens the directory C:\Automation\Scripts
  2. Reads the directory
  3. If any of the files contained in it end in PL it gets executed by the system call
Files that end in .pl are assumed to be Perl scripts.
Simple isn't it? :)

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.