NAME
Weasel::Session - Connection to an encapsulated test driver
VERSION
0.30
SYNOPSIS
use Weasel;
use Weasel::Session;
use Weasel::Driver::Selenium2;
my $weasel = Weasel->new(
default_session => 'default',
sessions => {
default => Weasel::Session->new(
driver => Weasel::Driver::Selenium2->new(%opts),
),
});
$weasel->session->get('http://localhost/index');
DESCRIPTION
DEPENDENCIES
ATTRIBUTES
- driver
-
Holds a reference to the sessions's driver.
- widget_groups
-
Contains the list of widget groups to be used with the session, or uses all groups when undefined.
Note: this functionality allows one to load multiple groups into the running perl instance, while using different groups in various sessions.
- base_url
-
Holds the prefix that will be prepended to every URL passed to this API. The prefix can be an environment variable, e.g. ${VARIABLE}. It will be expanded and default to hppt://localhost:5000 if not defined. If it is not an environment variable, it will be used as is.
- page
-
Holds the root element of the target HTML page (the 'html' tag).
- log_hook
-
Upon instantiation can be set to log consumer; a function of 3 arguments: 1. the name of the event 2. the text to be logged (or a coderef to be called without arguments returning such)
- page_class
-
Upon instantiation can be set to an alternative class name for the
page
attribute. - retry_timeout
-
The number of seconds to poll for a condition to become true. Global setting for the
wait_for
function. - poll_delay
-
The number of seconds to wait between state polling attempts. Global setting for the
wait_for
function. - state
-
Holds one of
initial
started
stopped
Before the first page is loaded into the browser, the value of the
state
property isinitial
. After the firstget
call, the value changes tostarted
.
SUBROUTINES/METHODS
- clear($element)
-
Clears any input entered into elements supporting it. Generally applies to textarea elements and input elements of type text and password.
- click([$element])
-
Simulates a single mouse click. If an element argument is provided, that element is clicked. Otherwise, the browser window is clicked at the current mouse location.
- find($element, $locator [, scheme => $scheme] [, widget_args => \@args ] [, %locator_args])
-
Finds the first child of
$element
matching$locator
.See Weasel::Element's
find
function for more documentation. - find_all($element, $locator, [, scheme => $scheme] [, widget_args => \@args ] [, %locator_args ])
-
Finds all child elements of
$element
matching$locator
. Returns, depending on scalar or list context, an arrayref or a list with matching elements.See Weasel::Element's
find_all
function for more documentation. - get($url)
-
Loads
$url
into the active browser window of the driver connection, after prefixing withbase_url
. - get_attribute($element, $attribute)
-
Returns the value of the attribute named by
$attribute
of the element identified by$element
, orundef
if the attribute isn't defined. - get_text($element)
-
Returns the 'innerHTML' of the element identified by
$element
. - set_attribute($element_id, $attribute_name, $value)
-
DEPRECATED
Changes the value of the attribute named by
$attribute_name
to$value
for the element identified by$element_id
. - get_selected($element_id)
-
DEPRECATED
Please use
$self-
get_attribute('selected')> instead. - set_selected($element_id, $value)
-
DEPRECATED
Please use
$self-
set_attribute('selected', $value)> instead. - is_displayed($element)
-
Returns a boolean value indicating if the element identified by
$element
is visible on the page, i.e. that it can be scrolled into the viewport for interaction. - screenshot($fh)
-
Writes a screenshot of the browser's window to the filehandle
$fh
.Note: this version assumes pictures of type PNG will be written; later versions may provide a means to query the exact image type of screenshots being generated.
- start
-
Starts a new or stopped session.
Sets
state
back to the valueinitial
. - restart
-
Restarts a session by resetting it and starting.
Sets
state
back to the valueinitial
. - stop
- started
-
Returns a
true
value when the session has been started. - get_page_source($fh)
-
Writes a get_page_source of the browser's window to the filehandle
$fh
. - send_keys($element, @keys)
-
Send the characters specified in the strings in
@keys
to$element
, simulating keyboard input. - tag_name($element)
-
Returns the tag name of the element identified by
$element
. - wait_for($callback, [ retry_timeout => $number,] [poll_delay => $number,] [ on_timeout => \&cb ])
-
Polls $callback->() until it returns true, or
wait_timeout
expires -- whichever comes first.The arguments retry_timeout and poll_delay can be used to override the session-global settings.
- _logged($wrapped_fn, $event, $log_item, $log_item_pre)
-
Invokes
log_hook
when it's defined, before and after calling$wrapped_fn
with no arguments, with the 'pre_' and 'post_' prefixes to the event name.$log_item
can be a fixed string or a function of one argument returning the string to be logged. The argument passed into the function is the value returned by the$wrapped_fn
.In case there is no
$log_item_pre
to be called on the 'pre_' event,$log_item
will be used instead, with no arguments.For performance reasons, the
$log_item
and$log_item_pre
- when coderefs - aren't called; instead they are passed as-is to the$log_hook
for lazy evaluation. - _wrap_widget($_id)
-
Finds all matching widget selectors to wrap the driver element in.
In case of multiple matches, selects the most specific match (the one with the highest number of requirements).
SEE ALSO
AUTHOR
Erik Huelsmann
CONTRIBUTORS
Erik Huelsmann
Yves Lavoie
MAINTAINERS
Erik Huelsmann
BUGS AND LIMITATIONS
Bugs can be filed in the GitHub issue tracker for the Weasel project: https://github.com/perl-weasel/weasel/issues
SOURCE
The source code repository for Weasel is at https://github.com/perl-weasel/weasel
SUPPORT
Community support is available through perl-weasel@googlegroups.com.
LICENSE AND COPYRIGHT
(C) 2016-2023 Erik Huelsmann
Licensed under the same terms as Perl.