Bugzilla – Attachment 132741 Details for
Bug 30063
Make the main patron search use the /patrons REST API route
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30063: Add selenium tests
Bug-30063-Add-selenium-tests.patch (text/plain), 9.28 KB, created by
Jonathan Druart
on 2022-03-31 12:47:29 UTC
(
hide
)
Description:
Bug 30063: Add selenium tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-03-31 12:47:29 UTC
Size:
9.28 KB
patch
obsolete
>From 85861c40e5b7ad3c0ee258767d9bc6c1b1c6407d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 17 Feb 2022 12:38:29 +0100 >Subject: [PATCH] Bug 30063: Add selenium tests >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Séverine Queune <severine.queune@bulac.fr> >--- > t/db_dependent/selenium/patrons_search.t | 121 +++++++++++++++++++++-- > t/lib/Selenium.pm | 18 ++-- > 2 files changed, 120 insertions(+), 19 deletions(-) > >diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t >index dc09d70113e..8c232b2c15b 100755 >--- a/t/db_dependent/selenium/patrons_search.t >+++ b/t/db_dependent/selenium/patrons_search.t >@@ -17,6 +17,12 @@ > > use Modern::Perl; > >+our @cleanup; >+END { >+ unless ( @cleanup ) { say "WARNING: Cleanup failed!" } >+ $_->delete for @cleanup; >+}; >+ > use C4::Context; > > use utf8; >@@ -25,6 +31,7 @@ use Test::MockModule; > > use C4::Context; > use Koha::AuthUtils; >+use Koha::Patrons; > use t::lib::Mocks; > use t::lib::Selenium; > use t::lib::TestBuilder; >@@ -43,10 +50,12 @@ 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; >+ plan tests => 17; > >+ if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { >+ BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); >+ } > my @patrons; > my $borrowernotes = q|<strong>just 'a" note</strong> \123 â¤|; > my $borrowernotes_displayed = q|just 'a" note \123 â¤|; >@@ -64,6 +73,7 @@ subtest 'Search patrons' => sub { > { class => 'Koha::Libraries', value => { branchname => $branchname } } > ); > my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields'); >+ my $default_patron_per_page = C4::Context->preference('PatronsPerPage'); > for my $i ( 1 .. 25 ) { > push @patrons, > $builder->build_object( >@@ -81,9 +91,55 @@ subtest 'Search patrons' => sub { > } > ); > } >+ my $library_2 = $builder->build_object( >+ { class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } >+ ); >+ push @patrons, >+ $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ surname => "test_patron_26", >+ firstname => $firstname, >+ categorycode => $patron_category->categorycode, >+ branchcode => $library_2->branchcode, >+ borrowernotes => $borrowernotes, >+ address => $address, >+ email => $email, >+ } >+ } >+ ); >+ >+ my $attribute_type = Koha::Patron::Attribute::Type->new( >+ { >+ code => 'my code1', >+ description => 'my description1', >+ } >+ )->store; >+ my $attribute_type_searchable = Koha::Patron::Attribute::Type->new( >+ { >+ code => 'my code2', >+ description => 'my description2', >+ opac_display => 1, >+ staff_searchable => 1 >+ } >+ )->store; >+ $patrons[0]->extended_attributes([ >+ { code => $attribute_type->code, attribute => 'test_attr_1' }, >+ { code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, >+ ]); >+ $patrons[1]->extended_attributes([ >+ { code => $attribute_type->code, attribute => 'test_attr_1' }, >+ { code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, >+ ]); >+ >+ my $total_number_of_patrons = Koha::Patrons->search->count; >+ my $table_id = "memberresultst"; > > $s->auth; > C4::Context->set_preference('DefaultPatronSearchFields',""); >+ my $PatronsPerPage = 15; >+ C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); > $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'); >@@ -106,8 +162,8 @@ subtest 'Search patrons' => sub { > $s->submit_form; > my $first_patron = $patrons[0]; > >- $s->wait_for_datatable_visible('//table[@id="memberresultst"]'); >- my @td = $driver->find_elements('//table[@id="memberresultst"]/tbody/tr/td'); >+ $s->wait_for_ajax; >+ my @td = $driver->find_elements('//table[@id="'.$table_id.'"]/tbody/tr/td'); > like ($td[2]->get_text, qr[\Q$firstname\E], > 'Column "Name" should be the 3rd and contain the firstname correctly filtered' > ); >@@ -136,14 +192,63 @@ subtest 'Search patrons' => sub { > $first_patron->category->description, > ) > ); >+ >+ $driver->get( $base_url . "/members/members-home.pl" ); >+ $s->fill_form( { search_patron_filter => 'test_patron' } ); >+ $s->submit_form; >+ $s->wait_for_ajax; >+ >+ $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); >+ $s->wait_for_ajax; >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) ); >+ >+ $s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click; >+ $s->wait_for_ajax; >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 25, $total_number_of_patrons) ); >+ >+ # Reset the filters >+ $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); >+ $s->submit_form; >+ $s->wait_for_ajax; >+ >+ # And make sure all the patrons are present >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons) ); >+ >+ # Search on non-searchable attribute, we expect no result! >+ $s->fill_form( { search_patron_filter => 'test_attr_1' } ); >+ $s->submit_form; >+ $s->wait_for_ajax; >+ >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('No entries to show (filtered from %s total entries)', $total_number_of_patrons) ); >+ >+ # clear form >+ $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); >+ # Search on searchable attribute, we expect 2 patrons >+ $s->fill_form( { search_patron_filter => 'test_attr_2' } ); >+ $s->submit_form; >+ $s->wait_for_ajax; >+ >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons) ); >+ >+ # Refine search and search for test_patron in all the data using the DT global search >+ # No change in result expected, still 2 patrons >+ $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); >+ $s->wait_for_ajax; >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons) ); >+ >+ # Adding the surname of the first patron in the "Name" column >+ # We expect only 1 result >+ $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys($patrons[0]->surname); >+ $s->wait_for_ajax; >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 1, 1, $total_number_of_patrons) ); >+ > push @cleanup, $_ for @patrons; > push @cleanup, $library; >+ push @cleanup, $library_2; > push @cleanup, $patron_category; >+ push @cleanup, $attribute_type, $attribute_type_searchable; > C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields); >+ C4::Context->set_preference('PatronsPerPage',$default_patron_per_page); > > $driver->quit(); > }; >- >-END { >- $_->delete for @cleanup; >-} >diff --git a/t/lib/Selenium.pm b/t/lib/Selenium.pm >index 1b24e669759..72b55f5c822 100644 >--- a/t/lib/Selenium.pm >+++ b/t/lib/Selenium.pm >@@ -193,23 +193,19 @@ sub wait_for_element_visible { > return $elt; > } > >-sub wait_for_datatable_visible { >- my ( $self, $xpath_selector ) = @_; >+sub wait_for_ajax { >+ my ( $self ) = @_; > >- my ($visible, $elt); >- $self->remove_error_handler; >+ my $is_ready; > my $max_retries = $self->max_retries; > my $i; >- while ( not $visible ) { >- $elt = eval {$self->driver->find_element($xpath_selector . '//td[class="dataTables_empty"]')}; >- $visible = $elt && $elt->get_text ne 'No data available in table'; >- $self->driver->pause(1000) unless $visible; >+ while ( not $is_ready ) { >+ $is_ready = $self->driver->execute_script('return jQuery.active == 0'); >+ $self->driver->pause(1000) unless $is_ready; > >- die "Cannot wait more for element '$xpath_selector' to be visible" >+ die "Cannot wait more for jQuery to be active (wait_for_ajax)" > if $max_retries <= ++$i > } >- $self->add_error_handler; >- return $elt; > } > > sub show_all_entries { >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30063
:
130608
|
130609
|
130610
|
130611
|
130612
|
130613
|
130614
|
130615
|
132387
|
132552
|
132731
|
132732
|
132733
|
132734
|
132735
|
132736
|
132737
|
132738
|
132739
|
132740
|
132741
|
132742
|
132743
|
132744
|
132745
|
132746
|
132747
|
132748
|
132749
|
132759
|
132760
|
132761
|
132762
|
132763
|
132764
|
132765
|
132766
|
132767
|
132768
|
132769
|
132770
|
132771
|
132772
|
132773
|
132774
|
132775
|
132776
|
132777
|
132958