Bug 26162: Don't fall into an infinite loop
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 19 Aug 2020 05:19:09 +0000 (07:19 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 19 Aug 2020 06:19:11 +0000 (08:19 +0200)
If something went wrong we do want to stop the script!

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/lib/Selenium.pm

index 3e871ec..758470b 100644 (file)
@@ -193,7 +193,8 @@ sub show_all_entries {
     $self->driver->find_element( $xpath_selector
           . '//div[@class="dataTables_length"]/label/select/option[@value="-1"]'
     )->click;
-    my ($all_displayed);
+    my ($all_displayed, $i);
+    my $max_retries = $self->max_retries;
     while ( not $all_displayed ) {
         my $dt_infos = $self->driver->get_text(
             $xpath_selector . '//div[@class="dataTables_info"]' );
@@ -203,6 +204,9 @@ sub show_all_entries {
         }
 
         $self->driver->pause(1000) unless $all_displayed;
+
+        die "Cannot show all entries from table $xpath_selector"
+            if $max_retries <= ++$i
     }
 }
 
@@ -222,6 +226,8 @@ sub click_when_visible {
     $elt->click unless $clicked; # finally Raise the error
 }
 
+sub max_retries { 10 }
+
 =head1 NAME
 
 t::lib::Selenium - Selenium helper module