AnyEvent-WebDriver
view release on metacpan or search on metacpan
->type ("some text")
->key ("{Enter}")
->perform;
DESCRIPTION
This module aims to implement the W3C WebDriver
<https://www.w3.org/TR/webdriver1/> specification which is the
standardised equivalent to the Selenium WebDriver API, which in turn
aims at remotely controlling web browsers such as Firefox or Chromium.
One of the design goals of this module was to stay very close to the
language and words used in the WebDriver specification itself, so to
make most of this module, or, in fact, to make any reasonable use of
this module, you would need to refer to the W3C WebDriver
recommendation, which can be found here
<https://www.w3.org/TR/webdriver1/>:
https://www.w3.org/TR/webdriver1/
Mozilla's "geckodriver" has had webdriver support for a long time, while
"chromedriver" only has basic and mostly undocumented webdriver support
as of release 77.
In Debian GNU/Linux, you can install the chromedriver for chromium via
the "chromium-driver" package. Unfortunately, there is no (working)
package for geckodriver, but you can download it from github
<https://github.com/mozilla/geckodriver/releases>.
CONVENTIONS
Unless otherwise stated, all delays and time differences in this module
are represented as an integer number of milliseconds, which is perhaps
surprising to users of my other modules but is what the WebDriver spec
uses.
WEBDRIVER OBJECTS
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:
endpoint => $string
For remote connections, the endpoint to connect to (defaults to
"http://localhost:4444").
proxy => $proxyspec
The proxy to use (same as the "proxy" argument used by
AnyEvent::HTTP). The default is "undef", which disables proxies.
To use the system-provided proxy (e.g. "http_proxy" environment
variable), specify the string "default".
autodelete => $boolean
If true (the default), then automatically execute
"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,
"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 "delete_session",
if you want the session to be cleaned up.
timeout => $seconds
The HTTP timeout, in (fractional) seconds (default: 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.
persistent => 1 | "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 "localhost" :) and that the WebDriver has
a persistent timeout much higher than what AnyEvent::HTTP uses.
You can force connections to be closed for non-idempotent
requests (the safe default of AnyEvent::HTTP) by setting this to
"undef".
$al = $wd->actions
Creates an action list associated with this WebDriver. See ACTION
LISTS, below, for full details.
$sessionstring = $wd->save_session
Save the current session in a string so it can be restored load with
"load_session". Note that only the session data itself is stored
(currently the session id and capabilities), not the endpoint
information itself.
The main use of this function is in conjunction with disabled
"autodelete", to save a session to e.g., and restore it later. It
could presumably used for other applications, such as using the same
session from multiple processes and so on.
$wd->load_session ($sessionstring)
$wd->set_session ($sessionid, $capabilities)
Starts using the given session, as identified by $sessionid.
$capabilities should be the original session capabilities, although
the current version of this module does not make any use of it.
The $sessionid is stored in "$wd->{sid}" (and could be fetched form
there for later use), while the capabilities are stored in
"$wd->{capabilities}".
SIMPLIFIED API
This section documents the simplified API, which is really just a very
thin wrapper around the WebDriver protocol commands. They all block the
caller until the result is available (using AnyEvent condvars), so must
not be called from an event loop callback - see "EVENT BASED API" for an
alternative.
The method names are pretty much taken directly from the W3C WebDriver
specification, e.g. the request documented in the "Get All Cookies"
section is implemented via the "get_all_cookies" method.
The order is the same as in the WebDriver draft at the time of this
writing, and only minimal massaging is done to request parameters and
results.
( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )