line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Selenium::Server; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33681
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
7
|
1
|
|
|
1
|
|
1030
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
48673
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
850
|
use Test::TCP; |
|
1
|
|
|
|
|
123903
|
|
|
1
|
|
|
|
|
70
|
|
9
|
1
|
|
|
1
|
|
970
|
use File::Slurp qw(write_file); |
|
1
|
|
|
|
|
6691
|
|
|
1
|
|
|
|
|
72
|
|
10
|
1
|
|
|
1
|
|
10
|
use File::Temp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
11
|
1
|
|
|
1
|
|
7
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
791
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $LATEST_VERSION; |
19
|
|
|
|
|
|
|
sub latest_version { |
20
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
unless ($LATEST_VERSION) { |
23
|
0
|
|
|
|
|
|
my $body = $ua->get('http://code.google.com/p/selenium/downloads/list')->content; |
24
|
0
|
|
|
|
|
|
my ($version) = $body =~ /selenium-server-standalone-(\d+.\d+.\d+).jar/i; |
25
|
0
|
|
|
|
|
|
$LATEST_VERSION = $version; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$LATEST_VERSION; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub download { |
32
|
0
|
|
|
0
|
1
|
|
my ($class, $version, $path) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $name = "selenium-server-standalone-${version}.jar"; |
35
|
0
|
|
|
|
|
|
my $url = "http://selenium.googlecode.com/files/${name}"; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $res = $ua->get($url); |
38
|
0
|
|
|
|
|
|
write_file($path, { binmode => ':raw' }, $res->content); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
my $jar = exists $args{jar} ? $args{jar} : do { |
45
|
0
|
0
|
|
|
|
|
my $version = exists $args{version} ? $args{version} : $class->latest_version; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $dir = File::Spec->tmpdir; |
48
|
0
|
|
|
|
|
|
my $name = "selenium-server-standalone-${version}.jar"; |
49
|
0
|
|
|
|
|
|
my $path = File::Spec->catfile($dir, $name); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
$class->download($version, $path) unless -e $path; |
52
|
0
|
|
|
|
|
|
$path; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $self = bless { jar => $jar }, $class; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($args{auto_start}) { |
58
|
0
|
|
|
|
|
|
$self->start; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub jar { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
0
|
|
0
|
|
|
|
return $self->{jar} || ''; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub host { |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
0
|
|
|
|
|
return $self->{server} ? '127.0.0.1' : ''; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub port { |
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
76
|
0
|
0
|
|
|
|
|
return $self->{server} ? $self->{server}->port : ''; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub start { |
80
|
0
|
|
|
0
|
1
|
|
my ($self, $args) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $server = Test::TCP->new( |
83
|
|
|
|
|
|
|
code => sub { |
84
|
0
|
|
|
0
|
|
|
my $port = shift; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $fh = File::Temp->new(UNLINK => 1); |
87
|
0
|
0
|
|
|
|
|
open STDOUT, '>&', $fh or croak "dup(2) failed:$!"; |
88
|
0
|
0
|
|
|
|
|
open STDERR, '>&', $fh or croak "dup(2) failed:$!"; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
0
|
|
|
|
my $cmd = sprintf 'java -jar "%s" %s -port %s', $self->jar, ($args || ''), $port; |
91
|
0
|
|
|
|
|
|
system $cmd; |
92
|
|
|
|
|
|
|
}, |
93
|
0
|
|
|
|
|
|
); |
94
|
0
|
|
|
|
|
|
$server->start; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->{server} = $server; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub stop { |
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ($self->{server}) { |
103
|
0
|
|
|
|
|
|
my ($host, $port) = ($self->host, $self->port); |
104
|
0
|
|
|
|
|
|
my $url = "http://${host}:${port}/selenium-server/driver/?cmd=shutDownSeleniumServer"; |
105
|
0
|
|
|
|
|
|
$ua->get($url); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
delete $self->{server}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub DESTROY { |
112
|
0
|
|
|
0
|
|
|
my $self = shift; |
113
|
0
|
|
|
|
|
|
$self->stop; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Selenium::Server - A wrapper of selenium-server-standalone.jar |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SYNOPSIS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use Selenium::Server; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# (default) download and use latest version jar |
127
|
|
|
|
|
|
|
my $server = Selenium::Server->new; |
128
|
|
|
|
|
|
|
# specify jar |
129
|
|
|
|
|
|
|
my $server = Selenium::Server->new(jar => '/path/to/selenium-server.jar'); |
130
|
|
|
|
|
|
|
# specify version |
131
|
|
|
|
|
|
|
my $server = Selenium::Server->new(version => '2.11.0'); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$server->start; |
134
|
|
|
|
|
|
|
# with arguments |
135
|
|
|
|
|
|
|
$server->start('-timeout 60 -trustAllSSLCertificates'); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $host = $server->host; # '127.0.0.1' |
138
|
|
|
|
|
|
|
my $port = $server->port; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$server->stop; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 DESCRIPTION |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Selenium::Server is a wrapper of Selenium RemoteWebDriver Server; |
145
|
|
|
|
|
|
|
selenium-server-standalone-{version}.jar file. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * new() |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Creates a selenium-server wrapper instance. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * start($args) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Starts selenium-server, with $args if specified. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * stop() |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Stops selenium-server. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * host() |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Returns selenium-server host. (127.0.0.1) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * port() |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns selenium-server port. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * jar() |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns selenium-server JAR file path. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * latest_version() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns selenium-server latest version string. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * download($version, $path) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Downloads selenium-server jar file specified by $version to $path. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
NAKAGAWA Masaki Emasaki@cpan.orgE |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 LICENSE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
192
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 SEE ALSO |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |