| 1 | package Test::Wait; | ||||||||||||||||||||||||||||
| 2 | # vim:syn=perl | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use vars qw( $VERSION @ISA @EXPORT ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | require Exporter; | |||||||||||||||||||||||||||
| 10 | 3 | @ISA = qw( Exporter ); | |||||||||||||||||||||||||||
| 11 | 3 | @EXPORT = qw( wait_stdin wait_x ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use constant DEFAULT_WAIT_SECONDS => 10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Test::Wait - Make tests wait for manual testing purposes. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Test::Wait is a tool for use in conjunction with test libraries such as Test::More for manual testing purposes. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | It was initially designed for use in Selenium based tests however it can be used in any test script. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Test::Wait provides a simple interface to pause test scripts at any given point, allowing you to inspect the test output or | ||||||||||||||||||||||||||||
| 28 | use the test-created data to run manual tests against the application in a browser or terminal. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | use Test::Wait; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | wait_stdin( [ 'i'm waiting for you to hit return' ] ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | wait_x( [ [ int seconds_to_wait ] [, "i'm waiting $seconds_to_wait seconds" ] ] ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 INTERFACE | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 wait_stdin( [ str message ] ) : nothing | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | wait ( for return key press ) before continuing a test. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ignored if running under prove or make test. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub wait_stdin { | ||||||||||||||||||||||||||
|
Subroutine
wait_stdin: called CC=3 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 2 | my $msg = shift; | |||||||||||||||||||||||||||
| 52 | 2 | ▶ | return if ( $ENV{HARNESS_ACTIVE} ); # don't wait if running under test harness eg; prove, make test | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | my ( $pkg, $filename, $line ) = caller(); | |||||||||||||||||||||||||||
| 54 | 0 | my $out_msg = 'I> ' . __PACKAGE__ . "::wait_stdin() - waiting at '$pkg' line '$line' ( $filename )"; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $out_msg .= ": '$msg'" if ( defined($msg) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | print STDERR "$out_msg\n"; | |||||||||||||||||||||||||||
| 57 | 0 | <STDIN>; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 wait_x( [ [ int seconds_to_wait ] [, str message ] ] ) : nothing | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | wait for $seconds_to_wait seconds before continuing a test. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | ignored if running under prove or make test. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | sub wait_x { | ||||||||||||||||||||||||||
|
Subroutine
wait_x: called CC=5 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 5 | my ( $seconds, $msg ) = @_; | |||||||||||||||||||||||||||
| 70 | 5 | ▶ | return if ( $ENV{HARNESS_ACTIVE} ); # don't wait if running under test harness eg; prove, make test | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $seconds = DEFAULT_WAIT_SECONDS() if ( !defined($seconds) || $seconds !~ /^\d+$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $seconds and $seconds =~ /^\d+$/
MC/DC0%0/2
defined $seconds and $seconds =~ /^\d+$/
defined $seconds
$seconds =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $secondsB= $seconds =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 72 | 0 | my ( $pkg, $filename, $line ) = caller(); | |||||||||||||||||||||||||||
| 73 | 0 | my $out_msg = 'I> ' . __PACKAGE__ . "::wait_x() - waiting '$seconds' seconds at '$pkg' line '$line' ( $filename )"; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | $out_msg .= ": '$msg'" if ( defined($msg) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | print STDERR "$out_msg\n"; | |||||||||||||||||||||||||||
| 76 | 0 | sleep( $seconds ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Test::More, Test::Builder, Test::Simple, Selenium::Remote::Driver, Test::Harness | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Ben Hare <ben@benhare.com> | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 CREDITS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Inspired by code written by Chris Hutchinson <chris@hutchinsonsoftware.com>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Copyright (c) Ben Hare <ben@benhare.com>, 2014. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | This program is free software. You can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | See F<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||