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