AnyEvent-WebDriver
view release on metacpan or search on metacpan
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.
SESSIONS
$wd->new_session ({ key => value... })
Try to connect to the WebDriver and initialize a new session with a
"new session" command, passing the given key-value pairs as value
(e.g. "capabilities").
No session-dependent methods must be called before this function
returns successfully, and only one session can be created per
WebDriver object.
On success, "$wd->{sid}" is set to the session ID, and
"$wd->{capabilities}" is set to the returned capabilities.
Simple example of creating a WebDriver object and a new session:
my $wd = new AnyEvent::WebDriver endpoint => "http://localhost:4444";
$wd->new_session ({});
Real-world example with capability negotiation:
$wd->new_session ({
capabilities => {
alwaysMatch => {
pageLoadStrategy => "eager",
unhandledPromptBehavior => "dismiss",
# proxy => { proxyType => "manual", httpProxy => "1.2.3.4:56", sslProxy => "1.2.3.4:56" },
},
firstMatch => [
{
browserName => "firefox",
"moz:firefoxOptions" => {
binary => "firefox/firefox",
args => ["-devtools", "-headless"],
prefs => {
"dom.webnotifications.enabled" => \0,
"dom.push.enabled" => \0,
"dom.disable_beforeunload" => \1,
"browser.link.open_newwindow" => 3,
"browser.link.open_newwindow.restrictions" => 0,
"dom.popup_allowed_events" => "",
"dom.disable_open_during_load" => \1,
},
},
},
{
browserName => "chrome",
"goog:chromeOptions" => {
binary => "/bin/chromium",
args => ["--no-sandbox", "--headless"],
prefs => {
# ...
},
},
},
{
# generic fallback
},
],
},
});
Firefox-specific capability documentation can be found on MDN
<https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities
>, Chrome-specific capability documentation might be found here
<http://chromedriver.chromium.org/capabilities>, but the latest
release at the time of this writing (chromedriver 77) has
essentially no documentation about webdriver capabilities (even MDN
has better documentation about chromwedriver!)
If you have URLs for Safari/IE/Edge etc. capabilities, feel free to
tell me about them.
$wd->delete_session
Deletes the session - the WebDriver object must not be used after
this call (except for calling this method).
This method is always safe to call and will not do anything if there
is no active session.
$timeouts = $wd->get_timeouts
Get the current timeouts, e.g.:
my $timeouts = $wd->get_timeouts;
=> { implicit => 0, pageLoad => 300000, script => 30000 }
( run in 1.350 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )