Saturday, July 2, 2011

Is there a way to save Selenium captured screen shots with timestamp in its name?

I use Perl to interface with RC and in all of my test scripts I always
generate a timestamp.
This timestamp is then used to identify all test artifacts including
screen captures as well as log and test files produced during the test
run.
The example below is how I implemented it. Basically I wrote a perl
sub that does this work for me and I call it from any of my scripts.

sub get_timestamp
{
  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

  $year += 1900;
  $mon++;

  return $year . sprintf('%02u%02u_%02u%02u%02u', $mon, $mday, $hour, $min, $sec);
}

Usage:
Handy timestamp subroutine. Returns formatted timestamp:


   my $unique_filename = 'filename_' . get_timestamp() . '.out';


will create a file named filename_20100915_144955.out


Please NOTE that formatted means formatted for my needs; to change
displayed timestamp format, manipulate sprintf as needed.

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.