Bug 28647

Summary: administration_tasks.t is failing randomly
Product: Koha Reporter: Victor Grousset/tuxayo <victor>
Component: Test SuiteAssignee: Victor Grousset/tuxayo <victor>
Status: Patch doesn't apply --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: jonathan.druart, lucas, mtj, tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 28647: Selenium lib: make error handler fail gracefully
Bug 28647: Wait for elements to load + do twice an unreliable operation

Description Victor Grousset/tuxayo 2021-07-02 03:05:26 UTC
Koha_Master #1697

koha_1       | 	/usr/local/share/perl/5.28.1/Selenium/Remote/Driver.pm:1340 in (eval)
koha_1       | 	/kohadevbox/koha/t/lib/Selenium.pm:165 in Selenium::Remote::Driver::find_element
koha_1       | 	t/db_dependent/selenium/administration_tasks.t:188 in t::lib::Selenium::click
koha_1       | 
selenium_1   | 1624989981543	Marionette	INFO	Stopped listening on port 43585
selenium_1   | 18:06:22.136 INFO [ActiveSessions$1.onStop] - Removing session ee327494-5e3c-4809-aa8c-51d0c0df60b2 (org.openqa.selenium.firefox.GeckoDriverService)
koha_1       | Error while executing command: no such element: Unable to locate element: //div[@id="container-main"]//a[contains(@href, "/admin/admin-home.pl")] at /usr/local/share/perl/5.28.1/Selenium/Remote/Driver.pm line 411.
Comment 1 Victor Grousset/tuxayo 2021-07-02 03:10:56 UTC
I can reproduce. I'm trying stuff like adding finds before so it waits for an element to be here before continuing.
But haven't found yet something that actually works when retrying a lot of times.
Comment 2 Victor Grousset/tuxayo 2021-07-05 11:05:31 UTC
For some reason, sometimes
        $driver->get($mainpage);
doesn't do anything and we can wait as much as we want and we won't be on the mainpage
Comment 3 Victor Grousset/tuxayo 2021-07-07 00:00:28 UTC
outrageous fix:

$driver->get($mainpage);
$driver->get($mainpage);

It should still eventually fail but the probability will be: once in "a few dozen times" x "a few dozen times"

So much lower :D
Comment 4 Victor Grousset/tuxayo 2021-07-07 00:13:01 UTC
Created attachment 122624 [details] [review]
Bug 28647: Selenium lib: make error handler fail gracefully

Quitting the driver makes all the next use of Selenium in the file fail.
And go to te error handler where it fails again and goes to the error
handler.
Now it just fails the current test and continues.
I don't know how this wasn't an issue in the previous work on the test
suite.
Comment 5 Victor Grousset/tuxayo 2021-07-07 00:13:06 UTC
Created attachment 122625 [details] [review]
Bug 28647: Wait for elements to load + do twice an unreliable operation

Confirmed by 1000 passing runs. After testing: removing any of the 3
fixes almost surely causes a fail in less than 200 runs.
Comment 6 Jonathan Druart 2021-07-20 08:04:48 UTC
How to recreate the failure?
Comment 7 Victor Grousset/tuxayo 2021-07-22 02:35:44 UTC
Running 
prove t/db_dependent/selenium/administration_tasks.t
in a loop without the patches.

And hope that on your machine there isn't a too low probability of failure.
Comment 8 Lucas Gass (lukeg) 2022-04-27 15:21:15 UTC
Sadly this no longer applies to current master.