line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Selenium::Waiter; |
2
|
|
|
|
|
|
|
$Selenium::Waiter::VERSION = '1.48'; |
3
|
3
|
|
|
3
|
|
1044
|
use strict; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
87
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
72
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Provides a utility wait_until function |
7
|
3
|
|
|
3
|
|
532
|
use Try::Tiny; |
|
3
|
|
|
|
|
2431
|
|
|
3
|
|
|
|
|
1192
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw/Exporter/; |
10
|
|
|
|
|
|
|
our @EXPORT = qw/wait_until/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub wait_until (&%) { |
14
|
8
|
|
|
8
|
1
|
15641
|
my $assert = shift; |
15
|
8
|
|
|
|
|
65
|
my $args = { |
16
|
|
|
|
|
|
|
timeout => 30, |
17
|
|
|
|
|
|
|
interval => 1, |
18
|
|
|
|
|
|
|
debug => 0, |
19
|
|
|
|
|
|
|
die => 0, |
20
|
|
|
|
|
|
|
@_ |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
24
|
my $start = time; |
24
|
|
|
|
|
|
|
my $timeout_not_elapsed = sub { |
25
|
11
|
|
|
11
|
|
38
|
my $elapsed = time - $start; |
26
|
11
|
|
|
|
|
99
|
return $elapsed < $args->{timeout}; |
27
|
8
|
|
|
|
|
42
|
}; |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
25
|
my $exception = ''; |
30
|
8
|
|
|
|
|
25
|
while ( $timeout_not_elapsed->() ) { |
31
|
8
|
|
|
|
|
20
|
my $assert_ret; |
32
|
|
|
|
|
|
|
my $try_ret = try { |
33
|
8
|
|
|
8
|
|
805
|
$assert_ret = $assert->(); |
34
|
6
|
100
|
|
|
|
37
|
return $assert_ret if $assert_ret; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
catch { |
37
|
2
|
|
|
2
|
|
85
|
$exception = $_; |
38
|
2
|
100
|
|
|
|
22
|
die $_ if $args->{die}; |
39
|
1
|
50
|
|
|
|
4
|
warn $_ if $args->{debug}; |
40
|
1
|
|
|
|
|
9
|
return ''; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
finally { |
43
|
8
|
100
|
|
8
|
|
183
|
if ( !$assert_ret ) { |
44
|
4
|
|
|
|
|
4000993
|
sleep( $args->{interval} ); |
45
|
|
|
|
|
|
|
} |
46
|
8
|
|
|
|
|
80
|
}; |
47
|
|
|
|
|
|
|
|
48
|
7
|
100
|
|
|
|
389
|
return $try_ret if $try_ret; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
3
|
100
|
|
|
|
69
|
warn 'timeout' if $args->{debug}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# No need to repeat ourselves if we're already debugging. |
54
|
3
|
100
|
66
|
|
|
101
|
warn $exception if $exception && !$args->{debug}; |
55
|
3
|
|
|
|
|
73
|
return ''; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |