NAME
Weasel::Session - Connection to an encapsulated test driver
VERSION
version 0.32
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
The session represents a connection to a browser window, allowing interaction with that window. It abstracts from the protocol being used for such access; meaning that the true interactions may be achieved through Selenium, W3C Web Driver, Cypress, Playwright or any other protocol or access method as long as the driver adheres to the Weasel::DriverRole protocol of the required minimum version.
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
pageattribute. - retry_timeout
-
The number of seconds to poll for a condition to become true. Global setting for the
wait_forfunction. - poll_delay
-
The number of seconds to wait between state polling attempts. Global setting for the
wait_forfunction. - state
-
Holds one of
initial
started
stopped
Before the first page is loaded into the browser, the value of the
stateproperty isinitial. After the firstgetcall, 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
$elementmatching$locator.See Weasel::Element's
findfunction for more documentation. - find_all($element, $locator, [, scheme => $scheme] [, widget_args => \@args ] [, %locator_args ])
-
Finds all child elements of
$elementmatching$locator. Returns, depending on scalar or list context, an arrayref or a list with matching elements.See Weasel::Element's
find_allfunction for more documentation. - get($url)
-
Loads
$urlinto the active browser window of the driver connection, after prefixing withbase_url. - get_attribute($element, $attribute)
-
Returns the value of the attribute named by
$attributeof the element identified by$element, orundefif 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_nameto$valuefor 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
$elementis 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
stateback to the valueinitial. - restart
-
Restarts a session by resetting it and starting.
Sets
stateback to the valueinitial. - stop
- started
-
Returns a
truevalue 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
@keysto$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_timeoutexpires -- 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_hookwhen it's defined, before and after calling$wrapped_fnwith no arguments, with the 'pre_' and 'post_' prefixes to the event name.$log_itemcan 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_preto be called on the 'pre_' event,$log_itemwill be used instead, with no arguments.For performance reasons, the
$log_itemand$log_item_pre- when coderefs - aren't called; instead they are passed as-is to the$log_hookfor 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.