Bug 30063: Fix selenium tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 15 Feb 2022 11:28:23 +0000 (12:28 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Mon, 4 Apr 2022 07:47:01 +0000 (09:47 +0200)
Signed-off-by: Séverine Queune <severine.queune@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
t/db_dependent/selenium/patrons_search.t
t/lib/Selenium.pm

index 0d33829..dc09d70 100755 (executable)
@@ -102,10 +102,11 @@ subtest 'Search patrons' => sub {
     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->fill_form( { search_patron_filter => 'test_patron' } );
     $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');
     like ($td[2]->get_text, qr[\Q$firstname\E],
         'Column "Name" should be the 3rd and contain the firstname correctly filtered'
@@ -116,7 +117,7 @@ subtest 'Search patrons' => sub {
     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,
+    is( $td[4]->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,
index 6d9afac..1b24e66 100644 (file)
@@ -193,6 +193,25 @@ sub wait_for_element_visible {
     return $elt;
 }
 
+sub wait_for_datatable_visible {
+    my ( $self, $xpath_selector ) = @_;
+
+    my ($visible, $elt);
+    $self->remove_error_handler;
+    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;
+
+        die "Cannot wait more for element '$xpath_selector' to be visible"
+            if $max_retries <= ++$i
+    }
+    $self->add_error_handler;
+    return $elt;
+}
+
 sub show_all_entries {
     my ( $self, $xpath_selector ) = @_;