From 4c51e89f9a72427d9b8426109f1a38e23bd652ee Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 13 Nov 2024 15:45:56 +0100 Subject: [PATCH] Bug 28633: Fix patrons_search.t This does not belong here, but raised to me here, so attaching on this one. This feels like it's coming from bug 33484, but those tests were passing after it has been pushed. This patch fixes the following error: Error while executing command: stale element reference: The element reference of is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed at /usr/share/perl5/Selenium/Remote/Driver.pm line 411. Since bug 33484 the row with the filters is redrawn on table redraw. So we need to search for the input every time the table is redrawn. --- t/db_dependent/selenium/patrons_search.t | 37 ++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index 069c4983dac..aa6f74c6112 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -411,6 +411,10 @@ subtest 'Search patrons' => sub { C4::Context->set_preference( 'dateformat', 'metric' ); + sub get_dob_search_filter { + return $s->driver->find_element( '//table[@id="' . shift . '"]//th[@aria-label="Date of birth: activate to sort column ascending"]/input' ); + } + # We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 $driver->get( $base_url . "/members/members-home.pl" ); @@ -420,46 +424,43 @@ subtest 'Search patrons' => sub { sleep $DT_delay && $s->wait_for_ajax; $s->show_all_entries( '//div[@id="' . $table_id . '_wrapper"]' ); - my $dob_search_filter = - $s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); - $dob_search_filter->send_keys('1980'); + get_dob_search_filter($table_id)->send_keys('1980'); sleep $DT_delay && $s->wait_for_ajax; my $patron_27 = Koha::Patrons->search( { surname => 'test_patron_27' } )->next; is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' ); - $dob_search_filter->clear; - $dob_search_filter = $s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('1986'); + get_dob_search_filter($table_id)->send_keys('1986'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 0, 'search by incorrect year does not show the patron' ); - $dob_search_filter->clear; - $dob_search_filter = $s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('1980-06'); + get_dob_search_filter($table_id)->send_keys('1980-06'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 1, 'search by correct year-month shows the patron' ); - $dob_search_filter->clear; + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('1980-06-17'); + get_dob_search_filter($table_id)->send_keys('1980-06-17'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 1, 'search by correct full iso date shows the patron' ); - $dob_search_filter->clear; + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('1986-06-17'); + get_dob_search_filter($table_id)->send_keys('1986-06-17'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 0, 'search by incorrect full iso date does not show the patron' ); - $dob_search_filter->clear; + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('17/06/1980'); + get_dob_search_filter($table_id)->send_keys('17/06/1980'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 1, 'search by correct full formatted date shows the patron' ); - $dob_search_filter->clear; + get_dob_search_filter($table_id)->clear; - $dob_search_filter->send_keys('17/06/1986'); + get_dob_search_filter($table_id)->send_keys('17/06/1986'); sleep $DT_delay && $s->wait_for_ajax; is( is_patron_shown($patron_27), 0, 'search by incorrect full formatted date does not show the patron' ); - $dob_search_filter->clear; + get_dob_search_filter($table_id)->clear; + }; teardown(); -- 2.34.1