Bugzilla – Attachment 107985 Details for
Bug 26162
Prevent Selenium's StaleElementReferenceException
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26162: Wait for the table to be refreshed
Bug-26162-Wait-for-the-table-to-be-refreshed.patch (text/plain), 3.80 KB, created by
Jonathan Druart
on 2020-08-10 10:29:48 UTC
(
hide
)
Description:
Bug 26162: Wait for the table to be refreshed
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-08-10 10:29:48 UTC
Size:
3.80 KB
patch
obsolete
>From 3cb859d9136dc19b008aa7dacdcbca37b2b32aff Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 10 Aug 2020 11:59:58 +0200 >Subject: [PATCH] Bug 26162: Wait for the table to be refreshed > >The previous patch did not work as expected. We still got a >StaleElementReference exception. >But this time on >10:43:47 selenium_1 | Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id=\"branchname\"]"} >Because we found the one that existed on the page, not the one sent back >in AJAX. > >The idea of this patch is to search for the "Showing 1 to X of Y entries" info and wait for X == Y >--- > .../selenium/administration_tasks.t | 6 ++-- > t/lib/Selenium.pm | 31 ++++++++++++++++++- > 2 files changed, 33 insertions(+), 4 deletions(-) > >diff --git a/t/db_dependent/selenium/administration_tasks.t b/t/db_dependent/selenium/administration_tasks.t >index eb2ce504c9..080bb38912 100644 >--- a/t/db_dependent/selenium/administration_tasks.t >+++ b/t/db_dependent/selenium/administration_tasks.t >@@ -127,7 +127,7 @@ SKIP: { > $s->submit_form; > > # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden >- $driver->find_element('//select[@name="libraries_length"]/option[@value="-1"]')->click; >+ $s->show_all_entries('//div[@id="libraries_wrapper"]'); > $s->click( > { > href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode, >@@ -138,7 +138,7 @@ SKIP: { > $s->submit_form; > > # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden >- $driver->find_element('//select[@name="libraries_length"]/option[@value="-1"]')->click; >+ $s->show_all_entries('//div[@id="libraries_wrapper"]'); > $s->click( > { > id => 'delete_library_'.$branchcode, >@@ -193,7 +193,7 @@ SKIP: { > $s->submit_form; > > # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our category is not hidden >- $driver->find_element('//select[@name="patron_categories_length"]/option[@value="-1"]')->click; >+ $s->show_all_entries('//div[@id="patron_categories_wrapper"]'); > > $s->click( > { >diff --git a/t/lib/Selenium.pm b/t/lib/Selenium.pm >index a4a36fc68f..3e871ec1ff 100644 >--- a/t/lib/Selenium.pm >+++ b/t/lib/Selenium.pm >@@ -172,15 +172,44 @@ sub click { > $self->click_when_visible( $xpath_selector ); > } > >-sub click_when_visible { >+sub wait_for_element_visible { > my ( $self, $xpath_selector ) = @_; >+ > $self->driver->set_implicit_wait_timeout(20000); > my ($visible, $elt); >+ $self->remove_error_handler; > while ( not $visible ) { > $elt = eval {$self->driver->find_element($xpath_selector) }; > $visible = $elt && $elt->is_displayed; > $self->driver->pause(1000) unless $visible; > } >+ $self->add_error_handler; >+ return $elt; >+} >+ >+sub show_all_entries { >+ my ( $self, $xpath_selector ) = @_; >+ >+ $self->driver->find_element( $xpath_selector >+ . '//div[@class="dataTables_length"]/label/select/option[@value="-1"]' >+ )->click; >+ my ($all_displayed); >+ while ( not $all_displayed ) { >+ my $dt_infos = $self->driver->get_text( >+ $xpath_selector . '//div[@class="dataTables_info"]' ); >+ >+ if ( $dt_infos =~ m|Showing 1 to (\d+) of (\d+) entries| ) { >+ $all_displayed = 1 if $1 == $2; >+ } >+ >+ $self->driver->pause(1000) unless $all_displayed; >+ } >+} >+ >+sub click_when_visible { >+ my ( $self, $xpath_selector ) = @_; >+ >+ my $elt = $self->wait_for_element_visible( $xpath_selector ); > > my $clicked; > $self->remove_error_handler; >-- >2.20.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 26162
:
107888
|
107889
|
107940
| 107985 |
108568
|
108569