Bug 32131 - Cypress tests are failing if ERMModule is off
Summary: Cypress tests are failing if ERMModule is off
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal (vote)
Assignee: Pedro Amorim
QA Contact: Testopia
URL:
Keywords:
Depends on: 32030 32147
Blocks:
  Show dependency treegraph
 
Reported: 2022-11-08 08:13 UTC by Jonathan Druart
Modified: 2023-06-08 22:32 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00


Attachments
Bug 32131: Cypress tests are failing if ERMModule is off (5.60 KB, patch)
2022-11-12 20:32 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 32131: Cypress tests are failing if ERMModule is off (5.69 KB, patch)
2022-11-16 08:04 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32131: Move set_ERM_sys_pref_value to before (3.16 KB, patch)
2022-11-16 08:04 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32131: Make sure we login before we restore original pref's value (926 bytes, patch)
2022-11-16 08:04 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off (1.76 KB, patch)
2022-11-16 08:04 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32131: Cypress tests are failing if ERMModule is off (5.74 KB, patch)
2022-11-17 15:30 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 32131: Move set_ERM_sys_pref_value to before (3.22 KB, patch)
2022-11-17 15:30 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 32131: Make sure we login before we restore original pref's value (989 bytes, patch)
2022-11-17 15:30 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off (1.82 KB, patch)
2022-11-17 15:30 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2022-11-08 08:13:15 UTC
The tests are failing if the syspref is off.

What would be the best approach to turn the syspref on before running the test (and making sure it's set back to its original value when the tests finished)?
Comment 1 Pedro Amorim 2022-11-11 17:19:59 UTC
Best approach imo would be to use set the syspref using before() instead of beforeEach() we're already using for cy.login.

However, this implies the following:
1) Because before() runs previous to beforeEach() this means we would also have to move login to before() - previous to setting sys pref.
2) If we're doing 1) we also need to re-implement how login is being done, using cy.session, see https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
3) That said, to use cy.session, we also need to put experimentalSessionAndOrigin: true in cypress.json since this is still an experimental thing added in Cypress 8.2, we're using cypress 9.5 last time I checked.

Lastly, before() can save the original ERMModule sys pref value in some variable and we restore its' value using after().

I tried all this, and is half-working. It works as expected for the first test in a spec, but for some reason it's not authenticating for the second test in the spec. Will keep at it.
Comment 2 Pedro Amorim 2022-11-12 20:32:59 UTC
Created attachment 143803 [details] [review]
Bug 32131: Cypress tests are failing if ERMModule is off

This patch solves this by enabling the system preference before each test, right after login. It also sets the system preference back to its original initial value after the tests finish running.

To test:
1) Disable ERMModule system preference
2) Run cypess tests: yarn cypress open / yarn cypress run
3) Verify that tests run successfully
(Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable".
4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value.
Comment 3 Pedro Amorim 2022-11-12 20:35:15 UTC
Further analysis:
login() doesn't work if called in before(), with or without cy.session, so it needs to remain in beforeEach() which means the setting of the ERM sys pref also needs to happen in beforeEach(), after logging in.

Tried to shorten the tests suite runtime duration by preventing visiting sys pref panel in case we are trying to enable the already enabled sys pref. Did this using env vars but this could cause it to fail if tests are paused and redone, leading to the real value and env var value to differ, i.e. env var value persists through subsequent test runs (this happened while using cypress open).

Finally, using cy.session for login works (and shortens tests suite duration slightly), but again, only if in beforeEach(), not in before(). I think this should also be implemented, but with its' own bug # and only if the use of experimentalSessionAndOrigin is considered reasonable by others.
Comment 4 Jonathan Druart 2022-11-14 08:47:51 UTC
Pedro, thanks for your time on this.

Yes, we need to use beforeEach, and that's not nice. But we can go with this solution for 22.11 and improve later.

You should:
1. Build the patch on top of bug 32147 (that will certainly make the tests fail)
2. Set ERMProviders as well (some tests will fail if EBSCO is selected)
Comment 5 Jonathan Druart 2022-11-15 07:50:18 UTC
(In reply to Jonathan Druart from comment #4) 
> You should:
> 1. Build the patch on top of bug 32147 (that will certainly make the tests
> fail)

Tomas, are you going to push it into 22.11?
Comment 6 Tomás Cohen Arazi 2022-11-15 11:54:51 UTC
(In reply to Jonathan Druart from comment #5)
> (In reply to Jonathan Druart from comment #4) 
> > You should:
> > 1. Build the patch on top of bug 32147 (that will certainly make the tests
> > fail)
> 
> Tomas, are you going to push it into 22.11?

Yes, was waiting for it to be PQA.
Comment 7 Jonathan Druart 2022-11-16 08:04:40 UTC
Created attachment 143938 [details] [review]
Bug 32131: Cypress tests are failing if ERMModule is off

This patch solves this by enabling the system preference before each test, right after login. It also sets the system preference back to its original initial value after the tests finish running.

To test:
1) Disable ERMModule system preference
2) Run cypess tests: yarn cypress open / yarn cypress run
3) Verify that tests run successfully
(Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable".
4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Jonathan Druart 2022-11-16 08:04:45 UTC
Created attachment 143939 [details] [review]
Bug 32131: Move set_ERM_sys_pref_value to before

We cannot (yet) move login to before, but we can set the pref before all
the tests. We need to login in before anyway to retrieve the value of
the pref.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Jonathan Druart 2022-11-16 08:04:49 UTC
Created attachment 143940 [details] [review]
Bug 32131: Make sure we login before we restore original pref's value

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 10 Jonathan Druart 2022-11-16 08:04:54 UTC
Created attachment 143941 [details] [review]
Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off

Please squash this with the first patch if 32147 is pushed before 32131.
Comment 11 Martin Renvoize 2022-11-17 15:30:21 UTC
Created attachment 144006 [details] [review]
Bug 32131: Cypress tests are failing if ERMModule is off

This patch solves this by enabling the system preference before each test,
right after login. It also sets the system preference back to its original
initial value after the tests finish running.

To test:
1) Disable ERMModule system preference
2) Run cypess tests: yarn cypress open / yarn cypress run
3) Verify that tests run successfully
(Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable".
4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 12 Martin Renvoize 2022-11-17 15:30:25 UTC
Created attachment 144007 [details] [review]
Bug 32131: Move set_ERM_sys_pref_value to before

We cannot (yet) move login to before, but we can set the pref before all
the tests. We need to login in before anyway to retrieve the value of
the pref.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 13 Martin Renvoize 2022-11-17 15:30:29 UTC
Created attachment 144008 [details] [review]
Bug 32131: Make sure we login before we restore original pref's value

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 14 Martin Renvoize 2022-11-17 15:30:34 UTC
Created attachment 144009 [details] [review]
Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off

Please squash this with the first patch if 32147 is pushed before 32131.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 15 Martin Renvoize 2022-11-17 15:32:55 UTC
All works as described and makes sense.

Passing QA
Comment 16 Tomás Cohen Arazi 2022-11-17 16:43:03 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!