Koha/t/db_dependent/selenium
Jonathan Druart 5aa213e210 Bug 35598: Fix selenium/authentication_2fa.t random failure
Jenkins is failing with
koha_1       | STRACE:	/usr/share/perl5/Try/Tiny.pm:123 in Selenium::Remote::Driver::catch {...}
koha_1       | 	/usr/share/perl5/Selenium/Remote/Driver.pm:361 in Try::Tiny::try
koha_1       | 	(eval 582):1 in Selenium::Remote::Driver::__ANON__
koha_1       | 	(eval 584):2 in Selenium::Remote::Driver::__ANON__
koha_1       | 	(eval 556):17 in Selenium::Remote::Driver::_execute_command
koha_1       | 	/usr/share/perl5/Selenium/Remote/WebElement.pm:125 in Selenium::Remote::WebElement::_execute_command
koha_1       | 	t/db_dependent/selenium/authentication_2fa.t:276 in Selenium::Remote::WebElement::send_keys
koha_1       | 	/usr/share/perl/5.32/Test/Builder.pm:334 in main::__ANON__
koha_1       | 	/usr/share/perl/5.32/Test/Builder.pm:334 in (eval)
koha_1       | 	/usr/share/perl/5.32/Test/More.pm:809 in Test::Builder::subtest
koha_1       | 	t/db_dependent/selenium/authentication_2fa.t:294 in Test::More::subtest
koha_1       |
selenium_1   | 1702911648831	Marionette	INFO	Stopped listening on port 41385
selenium_1   | JavaScript error: resource:///modules/Interactions.jsm, line 230: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIUserIdleService.removeIdleObserver]
selenium_1   | 15:00:49.452 INFO [ActiveSessions$1.onStop] - Removing session c3461b22-7a80-4b56-b177-653a53cc2651 (org.openqa.selenium.firefox.GeckoDriverService)
koha_1       |     # Looks like you planned 7 tests but ran 3.
koha_1       |
koha_1       | #   Failed test 'Enforce 2FA setup on first login'
koha_1       | #   at t/db_dependent/selenium/authentication_2fa.t line 294.
koha_1       | Error while executing command: element not interactable: Element <input id="pin_code" name="pin_code" type="text"> is not reachable by keyboard at /usr/share/perl5/Selenium/Remote/Driver.pm line 411.

The error is: "Element <input id="pin_code" name="pin_code" type="text"> is not reachable by keyboard"

A guess is that the input is either 1. outside of the viewport, or 2. not
displayed yet.

1. We are hidding #registration-form then show it when we retrieved the
   info (after POST /api/v1/auth/two-factor/registration)
2. Couldn't there be a race condition?
In auth.tt
284                     success: function (data) {
292                         $("#registration-form").show();
And in the selenium test:
$s->wait_for_ajax; # There is an ajax request to populate the qr_code and the secret
Not sure this wait_for_ajax is waiting for the end of success, I don't
think so.

This patch is supposed to fix both theories.

Test plan:
0. Do not apply the patch
1. Edit auth.tt and sleep 1 second before showing the form:
290                         const sleep = ms => new Promise(r => setTimeout(r, ms));
291                         await sleep(1000);
292                         $("#registration-form").show();

You will also need to replace the following line (284):
  success: function (data) {
with
  success: async function (data) {

2. prove t/db_dependent/selenium/authentication_2fa.t
=> "is not reachable by keyboard" error!

3. Apply the patch, keep the sleep

4. prove t/db_dependent/selenium/authentication_2fa.t
=> Tests are passing

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Edit (tcohen): Tidied a bit to clear complaints
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 3270d32191)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2024-01-15 14:28:55 +01:00
..
00-onboarding.t Bug 19185: Add missing +x on new test files 2021-10-25 13:09:34 +02:00
01-installation.t Bug 19185: Add missing +x on new test files 2021-10-25 13:09:34 +02:00
administration_tasks.t Bug 35556: Fix random selenium failure if category on second page 2024-01-03 14:38:22 +01:00
authentication.t Bug 34513: (QA follow-up) Tidy 2023-09-25 18:18:37 -03:00
authentication_2fa.t Bug 35598: Fix selenium/authentication_2fa.t random failure 2024-01-15 14:28:55 +01:00
basic_workflow.t Bug 33528: Fix basic_workflow.t 2023-06-14 12:46:47 -03:00
batch_item_modification.t Bug 32242: Add selenium tests 2022-11-17 14:16:12 -03:00
ilsdi.t Bug 35008: (QA follow-up) Add selenium unit tests 2023-11-10 10:59:28 -03:00
patrons_search.t Bug 34517: (follow-up) Add test for attribute search field and make cleanup more robust 2023-11-14 08:35:23 +01:00
regressions.t Bug 35119: Add back classes used for selenium tests 2023-10-27 16:42:50 -03:00
remove_from_cart.t Bug 29779: Make selenium tests return green even if lib is missing 2022-01-31 21:55:40 -10:00
self_registration.t Bug 27634: Fix self_registration.t 2023-10-03 09:24:45 -04:00
system_preferences_search.t Bug 32926: Fix selenium tests 2023-02-24 17:52:31 -03:00
update_child_to_adult.t Bug 30595: Prevent update_child_to_adult.t to fail randomly 2022-04-22 10:02:52 -10:00