Koha/t/db_dependent/selenium/patrons_search.t
Victor Grousset/tuxayo 3c3406257e Bug 27055: Fix compatibility with newer Firefox+Selenium version
Fix "submit is not a function error"
A submit button should not be named "submit", in this case, it's id.
https://stackoverflow.com/questions/833032/submit-is-not-a-function-error-in-javascript

Fix some uses of get_attribute()

Fix a fail by setting a global implicit_wait_timeout, default value is 0
in our lib. Other libs set it higher which helps to not have to manually
deal with part of the timing issues.

Fix: remove usage of click_when_visible() because it doesn't work with
elements not in the top of the page. Because they are off screen.

Fix: use $driver->quit() in error_handler to not forget an open Firefox.
With the current version, it fills /dev/shm and fails with around 5
Firefox opened.
Also use quit() it at the end of every script.

Fix: filling item fields, to fill only the displayed one (not those
with display:none)

== Test plan ==
1. Update selenium/standalone-firefox to the latest version [1]
2. prove t/db_dependent/selenium/authentication.t
3. It fails with: arguments[0].form.submit is not a function
4. Apply patch
5. Retest
6. Success

[1] In koha-testing-docker you can do it with
docker-compose.yml:
     selenium:
-        image: selenium/standalone-firefox:2.53.1-americium
+        image: selenium/standalone-firefox

Signed-off-by: Mason James <mtj@kohaaloha.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2020-12-30 12:04:49 -03:00

143 lines
6 KiB
Perl
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/perl
# 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>.
use Modern::Perl;
use C4::Context;
use utf8;
use Test::More tests => 1;
use Test::MockModule;
use C4::Context;
use Koha::AuthUtils;
use t::lib::Mocks;
use t::lib::Selenium;
use t::lib::TestBuilder;
eval { require Selenium::Remote::Driver; };
skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
my $s = t::lib::Selenium->new;
my $driver = $s->driver;
my $opac_base_url = $s->opac_base_url;
my $base_url = $s->base_url;
my $builder = t::lib::TestBuilder->new;
our @cleanup;
subtest 'Search patrons' => sub {
plan tests => 12;
my @patrons;
my $borrowernotes = q|<strong>just 'a" note</strong> \123 ❤|;
my $borrowernotes_displayed = q|just 'a" note \123 ❤|;
my $branchname = q|<strong>just 'another" library</strong> \123 ❤|;
my $firstname = q|<strong>fir's"tname</strong> \123 ❤|;
my $address = q|<strong>add'res"s</strong> \123 ❤|;
my $email = q|a<strong>bad_email</strong>@example\123 ❤.com|;
my $patron_category = $builder->build_object(
{
class => 'Koha::Patron::Categories',
value => { category_type => 'A' }
}
);
my $library = $builder->build_object(
{ class => 'Koha::Libraries', value => { branchname => $branchname } }
);
my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields');
for my $i ( 1 .. 25 ) {
push @patrons,
$builder->build_object(
{
class => 'Koha::Patrons',
value => {
surname => "test_patron_" . $i++,
firstname => $firstname,
categorycode => $patron_category->categorycode,
branchcode => $library->branchcode,
borrowernotes => $borrowernotes,
address => $address,
email => $email,
}
}
);
}
$s->auth;
C4::Context->set_preference('DefaultPatronSearchFields',"");
$driver->get( $base_url . "/members/members-home.pl" );
my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
is( scalar @adv_options, 11, 'All standard fields are searchable if DefaultPatronSearchFields not set');
is( scalar @filter_options, 11, 'All standard fields are searchable by filter if DefaultPatronSearchFields not set');
C4::Context->set_preference('DefaultPatronSearchFields',"initials");
$driver->get( $base_url . "/members/members-home.pl" );
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
is( scalar @adv_options, 12, 'New option added when DefaultPatronSearchFields is populated with a field');
is( scalar @filter_options, 12, 'New filter option added when DefaultPatronSearchFields is populated with a field');
C4::Context->set_preference('DefaultPatronSearchFields',"initials,horses");
$driver->get( $base_url . "/members/members-home.pl" );
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
is( scalar @adv_options, 12, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field');
is( scalar @filter_options, 12, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field');
C4::Context->set_preference('DefaultPatronSearchFields',"");
$s->fill_form( { searchmember_filter => 'test_patron' } );
$s->submit_form;
my $first_patron = $patrons[0];
my @td = $driver->find_elements('//table[@id="memberresultst"]/tbody/tr/td');
like ($td[2]->get_text, qr[\Q$firstname\E],
'Column "Name" should be the 3rd and contain the firstname correctly filtered'
);
like ($td[2]->get_text, qr[\Q$address\E],
'Column "Name" should be the 3rd and contain the address correctly filtered'
);
like ($td[2]->get_text, qr[\Q$email\E],
'Column "Name" should be the 3rd and contain the email address correctly filtered'
);
is( $td[5]->get_text, $branchname,
'Column "Library" should be the 6th and contain the html tags - they have been html filtered'
);
is( $td[9]->get_text, $borrowernotes_displayed,
'Column "Circ note" should be the 10th and not contain the html tags - they have not been html filtered'
);
$driver->find_element(
'//a[@href="/cgi-bin/koha/members/memberentry.pl?op=modify&destination=circ&borrowernumber='
. $first_patron->borrowernumber
. '"]' )->click;
is(
$driver->get_title,
sprintf(
"Koha Patrons Modify patron %s %s (%s) %s (%s) (%s)",
$first_patron->title, $first_patron->firstname, $first_patron->othernames, $first_patron->surname, $first_patron->cardnumber,
$first_patron->category->description,
)
);
push @cleanup, $_ for @patrons;
push @cleanup, $library;
push @cleanup, $patron_category;
C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields);
$driver->quit();
};
END {
$_->delete for @cleanup;
}