Ver código fonte

Merge pull request #473 from jamadam/warn-timeout

make waiter timeout recognizable
George S. Baugh 4 anos atrás
pai
commit
7a8c8728b4
2 arquivos alterados com 51 adições e 0 exclusões
  1. 2 0
      lib/Selenium/Waiter.pm
  2. 49 0
      t/13-waiter.t

+ 2 - 0
lib/Selenium/Waiter.pm

@@ -118,6 +118,8 @@ sub wait_until (&%) {
         return $try_ret if $try_ret;
     }
 
+    warn 'timeout' if $args->{debug};
+    
     # No need to repeat ourselves if we're already debugging.
     warn $exception if $exception && !$args->{debug};
     return '';

+ 49 - 0
t/13-waiter.t

@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use Selenium::Waiter;
+
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use Test::More;
+
+my $res;
+
+subtest 'basic' => sub {
+    my @warning;
+    local $SIG{__WARN__} = sub { push( @warning, $_[0] ) };
+
+    $res = wait_until { 1 };
+    is $res, 1, 'right return value';
+
+    $res = wait_until { 0 } timeout => 1;
+    is $res, '', 'right return value';
+
+    is( scalar @warning, 0, 'no warnings' );
+};
+
+subtest 'exception' => sub {
+    my @warning;
+    local $SIG{__WARN__} = sub { push( @warning, $_[0] ) };
+
+    $res = wait_until { die 'case1' } debug => 0, timeout => 1;
+    is $res, '', 'right return value';
+    is( scalar @warning, 1, 'right number of warnings' );
+    like( $warning[0], qr{^case1}, 'right warning' );
+
+    @warning = ();
+    eval {
+        $res = wait_until { die 'case2' } die => 1, timeout => 1;
+    };
+    like $@, qr{case2}, 'right error';
+    is $res, '',        'right return value';
+    is( scalar @warning, 0, 'right number of warnings' );
+
+    @warning = ();
+    $res     = wait_until { 0 } debug => 1, timeout => 1;
+    is $res, '', 'right return value';
+    is( scalar @warning, 1, 'right number of warnings' );
+    like( $warning[0], qr{timeout}i, 'timeout is reported' );
+};
+
+done_testing;