Chaoui05 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks ! I appeal to your legendary wisdom. I have this following issue. I created a timer to get time elapsed between beginning of my tests and the end of them. But depending where i put my "end time" line, i have a different output in my Shell. I did this code :
use Modern::Perl; use strict; use warnings; package MyTestingSuite; use parent 'Test::Class'; use Test::Selenium::Remote::Driver; use Test::More; use POSIX qw(strftime); my $start = time(); cprint "Started at ", (strftime '%A %d %B %Y %H:%M:%S',localtime($star +t)), "\n"; sub startup : Test( startup => no_plan ) { my $self = shift; $self->{browsers} = [('firefox', 'internet explorer', 'chrome', 'pha +ntomjs')]; } # WHEN I PUT MY END TIME HERE: my $end = time(); cprint "Ended at ", (strftime '%A %d %B %Y %H:%M:%S', localtime($end +)),"\n"; cprintf "Total run time:", $end-$start, " seconds\n"; printf ("%02d:%02d:%02d\n",(gmtime($end-$start))[2,1,0]); I HAVE THIS OUTPUT IN MY SHELL: Started at 2016-05-17-16-55-00 1..0 Ended at 2016-05-17-16-57-04 Total run time:0 seconds .....ALL MY TESTS ..... sub Login_test : Tests { $driver->quit(); } } sub Logout_test : Tests { $driver->quit(); } } sub Navigation_test : Tests { $driver->quit(); } # WHEN I PUT MY END TIME HERE: my $end = time(); cprint "Ended at ", (strftime '%A %d %B %Y %H:%M:%S', localtime($end +)),"\n"; cprintf "Total run time:", $end-$start, " seconds\n"; printf ("%02d:%02d:%02d\n",(gmtime($end-$start))[2,1,0]); I HAVE THIS OUTPUT IN MY SHELL: Started at 2016-05-17-16-57-04 1..0 ....ALL MY TESTS ..... Ended at 2016-05-17-17-03-04 Total run time:360 seconds }

So in second position, inside Sub, it works fine , because i have all my tests inside my timer and so i can have elapsed time. But problem is that i can have random sub in my test . Also even if i place my end timer in the last Sub it can cut my timer inside my tests and not at the end of end.

I think about a conditionnal loop to get all my sub when they finish all to call my end time but i don't know how .

How can i do?

Many Thanks !

Replies are listed 'Best First'.
Re: Time elapsed with Selenium Test
by Corion (Patriarch) on May 17, 2016 at 15:31 UTC

    Have you considered looking at an END { ... } block?

    Also note that your output ruins the TAP format of your test programs. You should use diag or at least prefix all your non-test output with # so it gets recognized as a comment.

      As i said, i would like to get my end time AFTER my block.
      What do you mean by "ruins the TAP" ? Because my tests are running well.. Thank you