t::lib::Selenium - Selenium helper module
my $s = t::lib::Selenium->new; my $driver = $s->driver; my $base_url = $s->base_url; $s->auth; $driver->get($s->base_url . 'mainpage.pl'); $s->fill_form({ input_id => 'value' });
The goal of this module is to group the different actions we need when we use automation test using Selenium
my $s = t::lib::Selenium->new; Constructor - Returns the object Selenium You can pass login, password, base_url, selenium_addr, selenium_port If not passed, the environment variables will be used KOHA_USER, KOHA_PASS, KOHA_INTRANET_URL, SELENIUM_ADDR SELENIUM_PORT Or koha, koha, syspref staffClientBaseURL, localhost, 4444
$s->auth; Will login into Koha.
$driver->get($url) $s->fill_form({ input_id => 'value', element_id => 'other_value', }); Will fill the different elements of a form. The keys must be element ids (input and select are supported so far) The values must a string.
$s->submit_form; It will submit the form using the submit button present in in the fieldset with a clas="action". It should be the default way. If it does not work you should certainly fix the Koha interface.
$s->click($xpath_selector); This is a bit dirty for now but will evolve depending on the needs 3 parameters possible but only the following 2 forms are used: $s->click({ href => '/module/script.pl?foo=bar', main => 'doc3' }); # Sometimes we have doc or doc3. To make sure we are not going to hit a link in the header $s->click({ id => 'element_id });
$s->wait_for_element_visible($xpath_selector) Wait 10s for an element to be visible
$s->wait_for_element_hidden($xpath_selector) Wait 10s for an element to be hidden
$s->wait_for_ajax; Wait 10s for all the current AJAX requests to be received.
$s->get_next_alert_text; Retrieve the next alert text.
$s->show_all_entries($xpath_selector); Select the "All" entries of the DataTables present in the selector.
$c->click_when_visible Should always be called to avoid the "An element could not be located on the page" error
Capture a screenshot and upload it using the excellent lut.im service provided by framasoft The url of the image will be printed on STDERR (it should be better to return it instead)
Add our specific error handler to the driver. It will displayed a trace as well as capture a screenshot of the current screen. So only case you should need it is after you called remove_error_handler
Do *not* call this method if you are not aware of what it will do! It will remove any kinds of error raised by the driver. It can be useful in some cases, for instance if you want to make sure something will not happen and that could make the driver exploses otherwise. You certainly should call it for only one statement then must call add_error_handler right after.
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Alex Buckley <alexbuckley@catalyst.net.nz>
Koha Development Team
Copyright 2017 - Koha Development Team
This file is part of Koha.
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Koha; if not, see <http://www.gnu.org/licenses>.