AnyEvent-WebDriver
view release on metacpan or search on metacpan
WebDriver.pm view on Meta::CPAN
or Carp::croak "$AUTOLOAD: no such method";
my $func_ = \&$name_;
*$name = sub {
$func_->(@_, my $cv = AE::cv);
my ($status, $res) = $cv->recv;
if ($status ne "200") {
my $msg;
if (exists $res->{error}) {
$msg = "AyEvent::WebDriver: $res->{error}: $res->{message}";
$msg .= "\n$res->{stacktrace}caught at" if length $res->{stacktrace};
} else {
$msg = "AnyEvent::WebDriver: http status $status (wrong endpoint?), caught";
}
Carp::croak $msg;
}
$res
};
goto &$name;
}
=head2 WEBDRIVER OBJECTS
=over
=item new AnyEvent::WebDriver key => value...
Create a new WebDriver object. Example for a remote WebDriver connection
(the only type supported at the moment):
my $wd = new AnyEvent::WebDriver endpoint => "http://localhost:4444";
Supported keys are:
=over
=item endpoint => $string
For remote connections, the endpoint to connect to (defaults to C<http://localhost:4444>).
=item proxy => $proxyspec
The proxy to use (same as the C<proxy> argument used by
L<AnyEvent::HTTP>). The default is C<undef>, which disables proxies. To
use the system-provided proxy (e.g. C<http_proxy> environment variable),
specify the string C<default>.
=item autodelete => $boolean
If true (the default), then automatically execute C<delete_session> when
the WebDriver object is destroyed with an active session. If set to a
false value, then the session will continue to exist.
Note that due to bugs in perl that are unlikely to get fixed,
C<autodelete> is likely ineffective during global destruction and might
even crash your process, so you should ensure objects go out of scope
before that, or explicitly call C<delete_session>, if you want the session
to be cleaned up.
=item timeout => $seconds
The HTTP timeout, in (fractional) seconds (default: C<300>). This timeout
is reset on any activity, so it is not an overall request timeout. Also,
individual requests might extend this timeout if they are known to take
longer.
=item persistent => C<1> | C<undef>
If true (the default) then persistent connections will be used for all
requests, which assumes you have a reasonably stable connection (such as
to C<localhost> :) and that the WebDriver has a persistent timeout much
higher than what L<AnyEvent::HTTP> uses.
You can force connections to be closed for non-idempotent requests (the
safe default of L<AnyEvent::HTTP>) by setting this to C<undef>.
=back
=cut
sub new {
my ($class, %kv) = @_;
bless {
endpoint => "http://localhost:4444",
proxy => undef,
persistent => 1,
autodelete => 1,
timeout => 300,
%kv,
}, $class
}
sub DESTROY {
my ($self) = @_;
$self->delete_session
if exists $self->{sid} && $self->{autodelete};
}
=item $al = $wd->actions
Creates an action list associated with this WebDriver. See L<ACTION
LISTS>, below, for full details.
=cut
sub actions {
AnyEvent::WebDriver::Actions->new (wd => $_[0])
}
=item $sessionstring = $wd->save_session
Save the current session in a string so it can be restored load with
C<load_session>. Note that only the session data itself is stored
( run in 0.470 second using v1.01-cache-2.11-cpan-df04353d9ac )